@Override public void giveItem(BaseItemStack itemStack) { this.player.inventory.addItemStackToInventory( new ItemStack(Item.getByNameOrId(itemStack.getType().getId()), itemStack.getAmount(), 0)); }
@Nonnull @Override public ItemStack onItemUseFinish(@Nonnull ItemStack stack, World world, EntityLivingBase living) { if(!world.isRemote) { for(PotionEffect effect : getBrew(stack).getPotionEffects(stack)) { PotionEffect newEffect = new PotionEffect(effect.getPotion(), effect.getDuration(), effect.getAmplifier(), true, true); if(effect.getPotion().isInstant()) effect.getPotion().affectEntity(living, living, living, newEffect.getAmplifier(), 1F); else living.addPotionEffect(newEffect); } if(world.rand.nextBoolean()) world.playSound(null, living.posX, living.posY, living.posZ, SoundEvents.ENTITY_PLAYER_BURP, SoundCategory.PLAYERS, 1F, 1F); int swigs = getSwigsLeft(stack); if(living instanceof EntityPlayer && !((EntityPlayer) living).capabilities.isCreativeMode) { if(swigs == 1) { if(!((EntityPlayer) living).inventory.addItemStackToInventory(baseItem.copy())) return baseItem.copy(); else { return ItemStack.EMPTY; } } setSwigsLeft(stack, swigs - 1); } } return stack; }
@SubscribeEvent public static void onPlayerRespawn(PlayerRespawnEvent event) { NBTTagCompound data = event.player.getEntityData(); if(data.hasKey(EntityPlayer.PERSISTED_NBT_TAG)) { NBTTagCompound cmp = data.getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG); NBTTagCompound cmp1 = cmp.getCompoundTag(TAG_PLAYER_KEPT_DROPS); int count = cmp1.getInteger(TAG_DROP_COUNT); for(int i = 0; i < count; i++) { NBTTagCompound cmp2 = cmp1.getCompoundTag(TAG_DROP_PREFIX + i); ItemStack stack = new ItemStack(cmp2); if(!stack.isEmpty()) { ItemStack copy = stack.copy(); ItemNBTHelper.setBoolean(copy, TAG_KEEP, false); event.player.inventory.addItemStackToInventory(copy); } } cmp.setTag(TAG_PLAYER_KEPT_DROPS, new NBTTagCompound()); } }
public void addItem(EntityPlayer player, Item item) { player.inventory.addItemStackToInventory(new ItemStack(item)); }
@Override public void onCollideWithPlayer(EntityPlayer player) { if (inGround && !worldObj.isRemote) { TutorialMain.logger.info("Picked up a rock."); player.inventory.addItemStackToInventory(new ItemStack(TutorialMain.throwingRock)); setDead(); } } }
public static void spawnPlayer(EntityPlayer player, BlockPos pos, boolean fabricated) { NBTTagCompound data = player.getEntityData(); if(!data.hasKey(EntityPlayer.PERSISTED_NBT_TAG)) data.setTag(EntityPlayer.PERSISTED_NBT_TAG, new NBTTagCompound()); NBTTagCompound persist = data.getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG); final boolean test = false; if(test || !persist.getBoolean(TAG_HAS_OWN_ISLAND)) { createSkyblock(player.world, pos); if(player instanceof EntityPlayerMP) { EntityPlayerMP pmp = (EntityPlayerMP) player; pmp.setPositionAndUpdate(pos.getX() + 0.5, pos.getY() + 1.6, pos.getZ() + 0.5); pmp.setSpawnChunk(pos, true, player.world.provider.getDimension()); player.inventory.addItemStackToInventory(new ItemStack(ModItems.lexicon)); } if(fabricated) { persist.setBoolean(TAG_HAS_OWN_ISLAND, true); persist.setDouble(TAG_ISLAND_X, player.posX); persist.setDouble(TAG_ISLAND_Y, player.posY); persist.setDouble(TAG_ISLAND_Z, player.posZ); } } else { double posX = persist.getDouble(TAG_ISLAND_X); double posY = persist.getDouble(TAG_ISLAND_Y); double posZ = persist.getDouble(TAG_ISLAND_Z); if(player instanceof EntityPlayerMP) { EntityPlayerMP pmp = (EntityPlayerMP) player; pmp.setPositionAndUpdate(posX, posY, posZ); } } }
@Override public void giveToPlayer(@Nonnull EntityPlayer player){ if(!player.inventory.addItemStackToInventory(this.getStack())){ // eg a full inventory player.entityDropItem(this.getStack(), 0.0F); } }
@Override protected void onFoodEaten(ItemStack stack, World world, EntityPlayer player) { super.onFoodEaten(stack, world, player); if (!world.isRemote && player.getRNG().nextDouble() < 0.5) { player.inventory.addItemStackToInventory(new ItemStack(this.seed)); } }
else if( !this.thePlayer.inventory.addItemStackToInventory( itemstack2 ) )
@Override public void runCommand(MinecraftServer server, CommandBase command, ICommandSender sender, String[] args) throws CommandException { if(sender instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer)sender; if(!player.inventory.addItemStackToInventory(new ItemStack(BetterQuesting.guideBook))) { player.dropItem(new ItemStack(BetterQuesting.guideBook), true, false); } } } }
private void doInventoryPickup(EntityItem itemToGet, EntityPlayer player, ItemStack itemStackToGet, World world, int stackSize) { if (itemToGet.getDistance(player) <= distanceFromPlayer) { if (player.inventory.addItemStackToInventory(itemStackToGet)) { player.onItemPickup(itemToGet, stackSize); world.playSound(player, player.getPosition(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.1F, 0.5F * ((player.getEntityWorld().rand.nextFloat() - player.getEntityWorld().rand.nextFloat()) * 0.7F + 2F)); } } }
@Override public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { EntityPlayer player = getCommandSenderAsPlayer(sender); player.inventory.addItemStackToInventory(VampireBookManager.getInstance().getRandomBook(player.getRNG())); }
@Override public void onCollideWithPlayer(EntityPlayer entityIn) { if (!this.world.isRemote) { if (delayBeforePickup == 0) { if (Helper.isHunter(entityIn)) { if (entityIn.inventory.addItemStackToInventory(getSoulItemStack())) { entityIn.onItemPickup(this, 1); this.setDead(); } } } } }
@Override public ItemStack onItemUseFinish(ItemStack itemStack, World world, EntityLivingBase entity) { ItemStack itemStackRemaining = super.onItemUseFinish(itemStack, world, entity); if (getContainerItem() != null) { ItemStack container = getContainerItem(itemStack); if (itemStackRemaining == null || itemStackRemaining.stackSize <= 0) return container; else if (!(entity instanceof EntityPlayer) || !((EntityPlayer) entity).inventory.addItemStackToInventory(container)) entity.entityDropItem(container, 0); } return itemStackRemaining; }
@Override public void giveReward(QuestStack questStack, EntityPlayer entityPlayer) { if (!entityPlayer.inventory.addItemStackToInventory(itemStack.copy())) { entityPlayer.world.spawnEntity(new EntityItem(entityPlayer.world, entityPlayer.posX, entityPlayer.posY + entityPlayer.getEyeHeight(), entityPlayer.posZ, itemStack.copy())); } }
@Override public ItemStack onItemUseFinish(ItemStack stack, World world, EntityLivingBase entityLiving) { super.onItemUseFinish(stack, world, entityLiving); if (entityLiving instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) entityLiving; if (stack.getCount() >= 0) if (!player.inventory.addItemStackToInventory(getContainerItem(stack))) player.dropItem(getContainerItem(stack), false); } return stack; }
@SubscribeEvent public void onPlayerLoggedIn(net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent event) { if (Config.spawnNote) { PlayerGotNote note = PlayerProperties.getPlayerGotNote(event.player); if (!note.isPlayerGotNote()) { boolean success = event.player.inventory.addItemStackToInventory(new ItemStack(ModItems.probeNote)); if (success) { note.setPlayerGotNote(true); } } } } }
@Override public void handleCommand(ICommandSender sender, String[] arguments) { if (sender instanceof EntityPlayer && isPlayerOp(sender)) { EntityPlayer player = (EntityPlayer) sender; if (arguments.length == 1) player = sender.getEntityWorld().getPlayerEntityByName(arguments[0]); if (QuestingData.hasData(player)) { player.inventory.addItemStackToInventory(ItemQuestBook.getOPBook(player)); } else { sendChat(player, "hqm.message.noPlayer"); } } } }
@Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { int age = getAge(state); if (age == 3) { world.playSound(player, pos, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.5F, 2.0F); if (!player.inventory.addItemStackToInventory(getBerry())) Utils.dropStack(world, pos, getBerry()); world.setBlockState(pos, this.withAge(2), 2); return true; } return false; }
public static void spawnBook(EntityPlayer player) { if (!Quest.canQuestsBeEdited() && !player.world.isRemote && ModConfig.spawnBook && !QuestingData.getQuestingData(player).receivedBook && QuestingData.isQuestActive()) { QuestingData.getQuestingData(player).receivedBook = true; NBTTagCompound hqmTag = new NBTTagCompound(); if (player.getEntityData().hasKey(PlayerTracker.HQ_TAG)) hqmTag = player.getEntityData().getCompoundTag(PlayerTracker.HQ_TAG); hqmTag.setBoolean(PlayerTracker.RECEIVED_BOOK, true); player.getEntityData().setTag(PlayerTracker.HQ_TAG, hqmTag); ItemStack stack = new ItemStack(ModItems.book); if (!player.inventory.addItemStackToInventory(stack)) { spawnItemAtPlayer(player, stack); } } }