public boolean onBlockActivated( World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) { ItemStack itemstack = par5EntityPlayer.inventory.getCurrentItem(); int currentMeta = par1World.getBlockMetadata(par2, par3, par4); int bottomBlockID = par1World.getBlockId(par2, par3 - 1, par4); Block block = Block.blocksList[bottomBlockID]; if (itemstack == null) { if (!par5EntityPlayer.inventory.addItemStackToInventory( new ItemStack(DCsAppleMilk.emptyPan, 1, 0))) { par5EntityPlayer.entityDropItem(new ItemStack(DCsAppleMilk.emptyPan, 1, 0), 1); } par1World.setBlockToAir(par2, par3, par4); par1World.playSoundAtEntity(par5EntityPlayer, "random.pop", 0.4F, 1.8F); return true; } else if (itemstack.itemID == DCsAppleMilk.emptyPan.blockID) { if (!par5EntityPlayer.inventory.addItemStackToInventory( new ItemStack(DCsAppleMilk.emptyPan, 1))) { par5EntityPlayer.entityDropItem(new ItemStack(DCsAppleMilk.emptyPan, 1), 1); } par1World.setBlockToAir(par2, par3, par4); par1World.playSoundAtEntity(par5EntityPlayer, "random.pop", 0.4F, 1.8F); return true; } else if (itemstack.itemID == Item.bowlEmpty.itemID) { return true; } else { int ID = itemstack.itemID; int IDm = itemstack.getItemDamage(); int setMeta = this.getMakerMeta(ID, IDm); if ((setMeta > 0) && (bottomBlockID == Block.furnaceBurning.blockID || block instanceof BlockFurnace)) { this.setPanMeta(par1World, par2, par3, par4, par5EntityPlayer, itemstack, setMeta); par5EntityPlayer.triggerAchievement(AchievementRegister.makeRice); return true; } else { return false; } } }
/** 空容器の返却を行うメソッド。 */ protected boolean returnItemStack(EntityPlayer player, int meta) { ItemStack ret = this.getReturnContainer(meta); if (ret != null) { if (!player.inventory.addItemStackToInventory(ret)) { player.entityDropItem(ret, 1); return true; } } return false; }
private void stealItems(Entity EntityAvaritia) { AxisAlignedBB box = EntityAvaritia.boundingBox.expand(RANGE, RANGE, RANGE); Class<EntityPlayer> players = EntityPlayer.class; List<EntityPlayer> inbox = EntityAvaritia.worldObj.getEntitiesWithinAABB(players, box); for (EntityPlayer entityPlayer : inbox) { Random rand1 = new Random(); int random1 = rand1.nextInt(32) + 1; Random rand2 = new Random(); int random2 = rand2.nextInt(5) + 1; if (random1 == 1 && counter >= 20 && !worldObj.isRemote) { if (random2 == 1 && entityPlayer.getCurrentArmor(0) != null) { ItemStack helm = entityPlayer.getCurrentArmor(0).copy(); entityPlayer.setCurrentItemOrArmor(1, null); entityPlayer.entityDropItem(helm, 1); } if (random2 == 2 && entityPlayer.getCurrentArmor(1) != null) { ItemStack torso = entityPlayer.getCurrentArmor(1).copy(); entityPlayer.setCurrentItemOrArmor(2, null); entityPlayer.entityDropItem(torso, 1); } if (random2 == 3 && entityPlayer.getCurrentArmor(2) != null) { ItemStack leggings = entityPlayer.getCurrentArmor(2).copy(); entityPlayer.setCurrentItemOrArmor(3, null); entityPlayer.entityDropItem(leggings, 1); } if (random2 == 4 && entityPlayer.getCurrentArmor(3) != null) { ItemStack boots = entityPlayer.getCurrentArmor(3).copy(); entityPlayer.setCurrentItemOrArmor(4, null); entityPlayer.entityDropItem(boots, 1); } if (random2 == 5 && entityPlayer.getHeldItem() != null) { ItemStack hand = entityPlayer.getHeldItem().copy(); entityPlayer.setCurrentItemOrArmor(0, null); entityPlayer.entityDropItem(hand, 1); } counter = 0; } } }
@Override public void onContainerClosed(EntityPlayer par1EntityPlayer) { super.onContainerClosed(par1EntityPlayer); if (!this.worldObj.isRemote) { for (int var2 = 1; var2 < this.craftMatrix.getSizeInventory(); ++var2) { final ItemStack var3 = this.craftMatrix.getStackInSlotOnClosing(var2); if (var3 != null) { par1EntityPlayer.entityDropItem(var3, 0.0F); } } } }
/** * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, * world, entityPlayer */ @Override public ItemStack onItemRightClick(ItemStack ist, World world, EntityPlayer player) { PotionEssence essence = new PotionEssence(ist.getTagCompound()); if (!getSplash(ist)) { if (essence.getEffects().size() > 0) { player.setItemInUse(ist, this.getMaxItemUseDuration(ist)); return ist; } else { MovingObjectPosition mop = this.getMovingObjectPositionFromPlayer(world, player, true); if (mop == null) return ist; else { if (mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { int blockX = mop.blockX; int blockY = mop.blockY; int blockZ = mop.blockZ; if (world.getBlock(blockX, blockY, blockZ) instanceof BlockApothecaryCauldron) { TileEntityCauldron cauldronTile = (TileEntityCauldron) world.getTileEntity(blockX, blockY, blockZ); NBTTagCompound potionTag = cauldronTile.removeContainedPotion(); ItemStack newPotion = new ItemStack(this, 1, 0); newPotion.setTagCompound(potionTag); if (--ist.stackSize <= 0) { return newPotion; } if (!player.inventory.addItemStackToInventory(newPotion)) { player.entityDropItem(newPotion, 0.1F); } } } } } } else { if (world.isRemote) return ist; Entity e = new EntityThrownXRPotion(world, player, ist); if (e == null) return ist; if (!player.capabilities.isCreativeMode) { --ist.stackSize; } world.playSoundAtEntity( player, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F)); world.spawnEntityInWorld(e); } return ist; }
@Override public ItemStack onEaten( ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { if (par1ItemStack.getItemDamage() > 14 && par1ItemStack.getItemDamage() < 19) { --par1ItemStack.stackSize; par3EntityPlayer .getFoodStats() .addStats(this.getHealAmount(par1ItemStack), this.getSaturationModifier(par1ItemStack)); par2World.playSoundAtEntity( par3EntityPlayer, "random.burp", 0.5F, par2World.rand.nextFloat() * 0.1F + 0.9F); if (!par2World.isRemote) { par3EntityPlayer.entityDropItem(new ItemStack(GCItems.canister, 1, 0), 0.0F); } return par1ItemStack; } return super.onEaten(par1ItemStack, par2World, par3EntityPlayer); }
private void getFoodPlate( World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer) { int meta = par1World.getBlockMetadata(par2, par3, par4); TileTeppann tile = (TileTeppann) par1World.getTileEntity(par2, par3, par4); ItemStack getItem = new ItemStack(DCsAppleMilk.clam, 1, 2); if (tile != null) { getItem = this.getEjectFoods(meta); tile.getItemstack((ItemStack) null); if (!par5EntityPlayer.inventory.addItemStackToInventory(getItem)) { if (!par1World.isRemote) par5EntityPlayer.entityDropItem(getItem, 1.0F); } // 実績用処理 if (getItem.getItem() == Item.getItemFromBlock(DCsAppleMilk.foodPlate) && getItem.getItemDamage() == 3) { par5EntityPlayer.triggerAchievement(AchievementRegister.getHamaguri); } tile.getItemstack((ItemStack) null); par1World.playSoundAtEntity(par5EntityPlayer, "random.pop", 0.4F, 1.8F); } }
@Override public void onPickupFromSlot(EntityPlayer player, ItemStack itemstack) { itemstack.onCrafting(thePlayer.worldObj, thePlayer, slotNumber); TerraFirmaCraft.proxy.takenFromCrafting(thePlayer, itemstack, craftMatrix); for (int i = 0; i < craftMatrix.getSizeInventory(); i++) { ItemStack itemstack1 = craftMatrix.getStackInSlot(i); if (itemstack1 != null) { craftMatrix.decrStackSize(i, 1); if (player.worldObj.isRemote && player.openContainer instanceof ContainerSpecialCrafting) ((GuiKnapping) Minecraft.getMinecraft().currentScreen).resetButton(i); if (itemstack1.getItem().getContainerItem() != null) { ItemStack itemstack2 = new ItemStack(itemstack1.getItem().getContainerItem()); if (!itemstack1.getItem().doesContainerItemLeaveCraftingGrid(itemstack1) || !thePlayer.inventory.addItemStackToInventory(itemstack2)) { if (craftMatrix.getStackInSlot(i) == null) craftMatrix.setInventorySlotContents(i, itemstack2); else thePlayer.entityDropItem(itemstack2, 0); } } } } }
private void spawnCasing(EntityPlayer player) { if (!player.inventory.addItemStackToInventory(new ItemStack(ModItems.bullet, 1, 0))) { player.entityDropItem(new ItemStack(ModItems.bullet, 1, 0), 0.1F); } }
private void spawnEmptyMagazine(EntityPlayer player) { if (!player.inventory.addItemStackToInventory(new ItemStack(ModItems.magazine, 1, 0))) { player.entityDropItem(new ItemStack(ModItems.magazine, 1, 0), 0.1F); } }
// 右クリック処理 @Override public boolean onBlockActivated( World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) { ItemStack itemstack = par5EntityPlayer.inventory.getCurrentItem(); int meta = par1World.getBlockMetadata(par2, par3, par4); TileIncenseBase tile = (TileIncenseBase) par1World.getTileEntity(par2, par3, par4); AMTBlockRightClickEvent event = new AMTBlockRightClickEvent(par1World, par5EntityPlayer, itemstack, par2, par3, par4); MinecraftForge.EVENT_BUS.post(event); if (event.isCanceled()) { return true; } if (itemstack == null) // 回収動作 { if (!par5EntityPlayer.inventory.addItemStackToInventory(new ItemStack(this, 1))) { if (!par1World.isRemote) par5EntityPlayer.entityDropItem(new ItemStack(this, 1), 1); } par1World.setBlockToAir(par2, par3, par4); par1World.playSoundAtEntity(par5EntityPlayer, "random.pop", 0.4F, 1.8F); return true; } else if (itemstack.getItem() == Item.getItemFromBlock(this)) { if (!par1World.isRemote) { EntityItem entity = new EntityItem( par1World, par5EntityPlayer.posX, par5EntityPlayer.posY, par5EntityPlayer.posZ, new ItemStack(this, 1)); par1World.spawnEntityInWorld(entity); } par1World.setBlockToAir(par2, par3, par4); par1World.playSoundAtEntity(par5EntityPlayer, "random.pop", 0.4F, 1.8F); return true; } else if (itemstack.getItem() instanceof IIncenseEffect) // お香アイテムの場合 { if (tile != null && !tile.hasItem()) { ItemStack put = itemstack.copy(); tile.setItemstack(put); if (!par5EntityPlayer.capabilities.isCreativeMode && (itemstack.stackSize - put.stackSize) <= 0) { par5EntityPlayer.inventory.setInventorySlotContents( par5EntityPlayer.inventory.currentItem, (ItemStack) null); } tile.markDirty(); par5EntityPlayer.inventory.markDirty(); par1World.markBlockForUpdate(par2, par3, par4); par1World.playSoundAtEntity(par5EntityPlayer, "random.pop", 0.4F, 1.8F); return true; } return false; } else if (itemstack.getItem() == Items.flint_and_steel || itemstack.getItem() == DCsAppleMilk.firestarter) { if (tile != null && tile.hasItem() && !tile.getActive()) { par5EntityPlayer.triggerAchievement(AchievementRegister.useIncense); itemstack.attemptDamageItem(1, par1World.rand); tile.setActive(); tile.markDirty(); par1World.setBlockMetadataWithNotify(par2, par3, par4, 1, 3); par1World.playSoundAtEntity(par5EntityPlayer, "random.pop", 0.4F, 1.8F); par1World.scheduleBlockUpdate(par2, par3, par4, this, this.tickRate(par1World)); return true; } return false; } else { return false; } }