/** * Sets the given item stack to the specified slot in the inventory (can be crafting or armor * sections). */ public void setContents(ItemStack par2ItemStack) { for (int x = 0; x < 27; x++) { if (this.poubelleContents[x] != null && this.poubelleContents[x].getItem().shiftedIndex == par2ItemStack.getItem().shiftedIndex) { int max = this.poubelleContents[x].stackSize + par2ItemStack.stackSize; if (par2ItemStack.getItem().getHasSubtypes()) { } else if (max > 64) { this.poubelleContents[x].stackSize = 64; par2ItemStack.stackSize = max - 64; this.onInventoryChanged(); } else { this.poubelleContents[x].stackSize += par2ItemStack.stackSize; this.onInventoryChanged(); break; } } else if (this.poubelleContents[x] == null) { this.poubelleContents[x] = par2ItemStack; if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit()) { par2ItemStack.stackSize = this.getInventoryStackLimit(); } this.onInventoryChanged(); break; } } }
public boolean hitEntity(ItemStack itemstack, EntityLiving mob, EntityLiving entityliving1) { World world = entityliving1.worldObj; if (type1 == type2) { attacks(itemstack, world, entityliving1, mob, type1); } else { if (random.nextInt(100) + 1 <= 80) { attacks(itemstack, world, entityliving1, mob, type1); } if (random.nextInt(100) + 1 <= 20) { attacks(itemstack, world, entityliving1, mob, type2); } } int i = itemstack.getItemDamage(); if (i >= dur) { itemstack.stackSize = 0; } if (type1 == 3 || type2 == 3 || type1 == 4 || type2 == 4 || type1 == 8 || type2 == 8) { if (random.nextInt(100) + 1 <= 90) { itemstack.damageItem(1, entityliving1); } } else { itemstack.damageItem(1, entityliving1); } return true; }
/** * Sets the given item stack to the specified slot in the inventory (can be crafting or armor * sections). */ public void setInventorySlotContents(int par1, ItemStack par2ItemStack) { this.freezerItemStacks[par1] = par2ItemStack; if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit()) { par2ItemStack.stackSize = this.getInventoryStackLimit(); } }
@Override public void setInventorySlotContents(int pos, ItemStack stack) { this.inv[pos] = stack; if ((stack != null) && (stack.stackSize > this.getInventoryStackLimit())) { stack.stackSize = this.getInventoryStackLimit(); } }
@Override public void setInventorySlotContents(int slot, ItemStack stack) { if (isLocked()) return; contents[slot] = stack; if (stack != null && stack.stackSize > getInventoryStackLimit()) stack.stackSize = getInventoryStackLimit(); onInventoryChanged(); }
@Override public void setInventorySlotContents(int i, ItemStack itemstack) { contents[i] = itemstack; if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) { itemstack.stackSize = getInventoryStackLimit(); } onInventoryChanged(); }
/** * Sets the given item stack to the specified slot in the inventory (can be crafting or armor * sections). */ public void setInventorySlotContents(int par1, ItemStack par2ItemStack) { this.poubelleContents[par1] = par2ItemStack; if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit()) { par2ItemStack.stackSize = this.getInventoryStackLimit(); } this.onInventoryChanged(); }
public boolean onBlockDestroyed( ItemStack itemstack, int i, int j, int k, int l, EntityLiving entityliving) { int i1 = itemstack.getItemDamage(); if (i1 >= dur) { itemstack.stackSize = 0; } itemstack.damageItem(2, entityliving); return true; }
@Override public void breakBlock(World world, int x, int y, int z, int i1, int i2) { TileEntityBasicMachine tileEntity = (TileEntityBasicMachine) world.getBlockTileEntity(x, y, z); if (tileEntity != null) { for (int i = 0; i < tileEntity.getSizeInventory(); ++i) { ItemStack slotStack = tileEntity.getStackInSlot(i); if (slotStack != null) { float xRandom = machineRand.nextFloat() * 0.8F + 0.1F; float yRandom = machineRand.nextFloat() * 0.8F + 0.1F; float zRandom = machineRand.nextFloat() * 0.8F + 0.1F; while (slotStack.stackSize > 0) { int j = machineRand.nextInt(21) + 10; if (j > slotStack.stackSize) { j = slotStack.stackSize; } slotStack.stackSize -= j; EntityItem item = new EntityItem( world, (double) ((float) x + xRandom), (double) ((float) y + yRandom), (double) ((float) z + zRandom), new ItemStack(slotStack.itemID, j, slotStack.getItemDamage())); if (slotStack.hasTagCompound()) { item.item.setTagCompound((NBTTagCompound) slotStack.getTagCompound().copy()); } float k = 0.05F; item.motionX = (double) ((float) machineRand.nextGaussian() * k); item.motionY = (double) ((float) machineRand.nextGaussian() * k + 0.2F); item.motionZ = (double) ((float) machineRand.nextGaussian() * k); world.spawnEntityInWorld(item); } } } tileEntity.invalidate(); } super.breakBlock(world, x, y, z, i1, i2); }
/** ejects contained items into the world, and notifies neighbours of an update, as appropriate */ public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6) { TileEntityChest var7 = (TileEntityChest) par1World.getBlockTileEntity(par2, par3, par4); if (var7 != null) { for (int var8 = 0; var8 < var7.getSizeInventory(); ++var8) { ItemStack var9 = var7.getStackInSlot(var8); if (var9 != null) { float var10 = this.random.nextFloat() * 0.8F + 0.1F; float var11 = this.random.nextFloat() * 0.8F + 0.1F; EntityItem var14; for (float var12 = this.random.nextFloat() * 0.8F + 0.1F; var9.stackSize > 0; par1World.spawnEntityInWorld(var14)) { int var13 = this.random.nextInt(21) + 10; if (var13 > var9.stackSize) { var13 = var9.stackSize; } var9.stackSize -= var13; var14 = new EntityItem( par1World, (double) ((float) par2 + var10), (double) ((float) par3 + var11), (double) ((float) par4 + var12), new ItemStack(var9.itemID, var13, var9.getItemDamage())); float var15 = 0.05F; var14.motionX = (double) ((float) this.random.nextGaussian() * var15); var14.motionY = (double) ((float) this.random.nextGaussian() * var15 + 0.2F); var14.motionZ = (double) ((float) this.random.nextGaussian() * var15); if (var9.hasTagCompound()) { var14.item.setTagCompound((NBTTagCompound) var9.getTagCompound().copy()); } } } } } super.breakBlock(par1World, par2, par3, par4, par5, par6); }
@Override public boolean onItemUseFirst( ItemStack stack, EntityPlayer player, World world, int X, int Y, int Z, int side) { TileEntity te = world.getBlockTileEntity(X, Y, Z); if (te != null && te instanceof TileEntityIronChest) { TileEntityIronChest ironchest = (TileEntityIronChest) te; TileEntityIronChest newchest = ironchest.applyUpgradeItem(this); if (newchest == null) { return false; } world.setBlockTileEntity(X, Y, Z, newchest); world.setBlockMetadataWithNotify(X, Y, Z, newchest.getType().ordinal()); world.notifyBlocksOfNeighborChange(X, Y, Z, world.getBlockId(X, Y, Z)); world.markBlockNeedsUpdate(X, Y, Z); stack.stackSize = 0; return true; } else { return false; } }
private void dropItems(World world, int x, int y, int z) { Random rand = new Random(); TileEntity tile_entity = world.getBlockTileEntity(x, y, z); if (!(tile_entity instanceof IInventory)) { return; } IInventory inventory = (IInventory) tile_entity; for (int i = 0; i < inventory.getSizeInventory(); i++) { ItemStack item = inventory.getStackInSlot(i); if (item != null && item.stackSize > 0) { float rx = rand.nextFloat() * 0.6F + 0.1F; float ry = rand.nextFloat() * 0.6F + 0.1F; float rz = rand.nextFloat() * 0.6F + 0.1F; EntityItem entity_item = new EntityItem( world, x + rx, y + ry, z + rz, new ItemStack(item.itemID, item.stackSize, item.getItemDamage())); if (item.hasTagCompound()) { entity_item.item.setTagCompound((NBTTagCompound) item.getTagCompound().copy()); } float factor = 0.5F; entity_item.motionX = rand.nextGaussian() * factor; entity_item.motionY = rand.nextGaussian() * factor + 0.2F; entity_item.motionZ = rand.nextGaussian() * factor; world.spawnEntityInWorld(entity_item); item.stackSize = 0; } } }
public void setInventorySlotContents(int i, ItemStack itemstack) { ItemStacks[i] = itemstack; if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) { itemstack.stackSize = getInventoryStackLimit(); } }