public static void load() { for (int i = 0; i < c.size(); i++) { ItemStack mat = c.get(i); if (mat != null) { mat = mat.copy(); mat.stackSize = 1; String mod = Base.modid.toLowerCase() + ":"; Base.cobaltReed = new BlockOreReed("oreGrowableCobalt") .setBlockName(mod + "oreGrowableCobalt") .setCreativeTab(Base.tabGrowableOre); AReedMakerClass.addReed(Base.cobaltReed, 4, 1, "oreGrowableCobalt", mat, mat); if (Base.cobaltReed != null) { break; } } } for (int i = 0; i < a.size(); i++) { ItemStack mat = a.get(i); if (mat != null) { mat = mat.copy(); mat.stackSize = 1; String mod = Base.modid.toLowerCase() + ":"; Base.arditeReed = new BlockOreReed("oreGrowableArdite") .setBlockName(mod + "oreGrowableArdite") .setCreativeTab(Base.tabGrowableOre); AReedMakerClass.addReed(Base.arditeReed, 4, 1, "oreGrowableArdite", mat, mat); if (Base.arditeReed != null) { break; } } } for (int i = 0; i < al.size(); i++) { ItemStack mat = al.get(i); if (mat != null) { mat = mat.copy(); mat.stackSize = 1; String mod = Base.modid.toLowerCase() + ":"; Base.aluminiumReed = new BlockOreReed("oreGrowableAluminium") .setBlockName(mod + "oreGrowableAluminium") .setCreativeTab(Base.tabGrowableOre); AReedMakerClass.addReed( Base.aluminiumReed, 2, 1, "oreGrowableAluminium", mat, "ingotAluminum"); if (Base.aluminiumReed != null) { break; } } } }
protected ItemStack fillOrEmptyContainer( ITankContainer tank, ItemStack itemstack, EnumFacing facing) { for (LiquidContainerData data : LiquidContainerRegistry.getRegisteredLiquidContainerData()) { if (data.container.isItemEqual(itemstack)) { int amount = data.stillLiquid.amount; LiquidStack liquid = tank.drain( ForgeDirection.getOrientation(facing.ordinal()).getOpposite(), amount, false); if (liquid != null && liquid.isLiquidEqual(data.stillLiquid) && liquid.amount == amount) { tank.drain(ForgeDirection.getOrientation(facing.ordinal()).getOpposite(), amount, true); itemstack.stackSize--; ItemStack result = data.filled.copy(); result.stackSize = 1; return result; } } else if (data.filled.isItemEqual(itemstack)) { LiquidStack liquid = data.stillLiquid; int amount = tank.fill(ForgeDirection.getOrientation(facing.ordinal()).getOpposite(), liquid, false); if (liquid.amount == amount) { tank.fill(ForgeDirection.getOrientation(facing.ordinal()).getOpposite(), liquid, true); ItemStack result = itemstack.getItem().getContainerItemStack(itemstack); itemstack.stackSize--; if (result == null) { result = data.container.copy(); result.stackSize = 0; } return result; } else { return null; } } } return null; }
// Rebalance the recipes stacks as best we can. public static int balanceStacks( List<ItemStack> stacks, int existing, int allowable, int available) { int added = allowable - existing; if (added > available) added = available; existing += added; // Split int share = existing / stacks.size(); int remainder = existing - (share * stacks.size()); for (ItemStack stack : stacks) { if (share < existing) { if (remainder > 0) { stack.stackSize = share + 1; existing -= share + 1; remainder--; } else { stack.stackSize = share; existing -= share; } } else { // This should be last one stack.stackSize = existing; existing = 0; } } return existing; }
public StampingRecipe(LiquidCasting tableCasting, CastingRecipe recipe) { this.output = recipe.output.copy(); this.cast = recipe.cast.copy(); this.coolTime = recipe.coolTime; float value = 0; try { this.metal = tableCasting .getCastingRecipe( recipe.castingMetal, new ItemStack(TinkerSmeltery.metalPattern, 1, 0)) .getResult(); value = (float) tableCasting.getCastingAmount(recipe.castingMetal, recipe.cast) / tableCasting.getCastingAmount( recipe.castingMetal, new ItemStack(TinkerSmeltery.metalPattern, 1, 0)); metal.stackSize = (int) Math.max(Math.floor(value), 1); if (value > 1) { value -= metal.stackSize; } } catch (NullPointerException e) { this.metal = null; // Ender Pearls -> Frying Pan? } if (value > 0.1) { secondaryResult = output.copy(); secondaryResult.stackSize /= value; secondaryResult.stackSize -= output.stackSize; if (secondaryResult.stackSize <= 0) { secondaryResult = null; } } }
public static ItemStack insertItem( IInventory inventory, ItemStack itemStack, boolean test, boolean force) { if (test) { itemStack = itemStack.copy(); } int size = inventory.getSizeInventory(); for (int i = 0; i < size; i++) { if (inventory.isItemValidForSlot(i, itemStack) || force) { ItemStack storedItem = inventory.getStackInSlot(i); if (storedItem != null) { if (equalItemAndNBT(storedItem, itemStack)) { int maxStackSize = Math.min(itemStack.getMaxStackSize(), inventory.getInventoryStackLimit()); int add = Math.min(itemStack.stackSize, maxStackSize - storedItem.stackSize); if (!test) { storedItem.stackSize += add; } itemStack.stackSize -= add; inventory.setInventorySlotContents(i, storedItem); } } else { storedItem = itemStack.copy(); storedItem.stackSize = Math.min(itemStack.stackSize, itemStack.getMaxStackSize()); if (!test) { inventory.setInventorySlotContents(i, storedItem); } itemStack.stackSize -= storedItem.stackSize; } if (itemStack.stackSize <= 0) { return null; } } } return itemStack; }
public ItemStack func_174894_a(ItemStack p_174894_1_) { ItemStack itemstack1 = p_174894_1_.copy(); for (int i = 0; i < this.slotsCount; ++i) { ItemStack itemstack2 = this.getStackInSlot(i); if (itemstack2 == null) { this.setInventorySlotContents(i, itemstack1); this.markDirty(); return null; } if (ItemStack.areItemsEqual(itemstack2, itemstack1)) { int j = Math.min(this.getInventoryStackLimit(), itemstack2.getMaxStackSize()); int k = Math.min(itemstack1.stackSize, j - itemstack2.stackSize); if (k > 0) { itemstack2.stackSize += k; itemstack1.stackSize -= k; if (itemstack1.stackSize <= 0) { this.markDirty(); return null; } } } } if (itemstack1.stackSize != p_174894_1_.stackSize) { this.markDirty(); } return itemstack1; }
/** * Adds an ItemStack to the first available slot in the provided IInventory, continuing to * distribute the stack as necessary until the stacksize reaches 0, if possible * * @return the number of items remaining in the stack, zero if all were added */ public static int addItemToInventory(ItemStack stack, IInventory inv) { int remaining = stack.stackSize; for (int i = 0; i < inv.getSizeInventory() && remaining > 0; ++i) { ItemStack slotstack = inv.getStackInSlot(i); if (slotstack == null && inv.isItemValidForSlot(i, stack)) { remaining -= inv.getInventoryStackLimit(); stack.stackSize = (remaining > 0 ? inv.getInventoryStackLimit() : stack.stackSize); inv.setInventorySlotContents(i, stack); inv.markDirty(); } else if (slotstack != null && stack.isStackable() && inv.isItemValidForSlot(i, stack)) { if (slotstack.getItem() == stack.getItem() && (!stack.getHasSubtypes() || stack.getItemDamage() == slotstack.getItemDamage()) && ItemStack.areItemStackTagsEqual(stack, slotstack)) { int l = slotstack.stackSize + remaining; if (l <= stack.getMaxStackSize() && l <= inv.getInventoryStackLimit()) { remaining = 0; slotstack.stackSize = l; inv.markDirty(); } else if (slotstack.stackSize < stack.getMaxStackSize() && stack.getMaxStackSize() <= inv.getInventoryStackLimit()) { remaining -= stack.getMaxStackSize() - slotstack.stackSize; slotstack.stackSize = stack.getMaxStackSize(); inv.markDirty(); } } } } return remaining; }
public void combineStackWithRemainder(ItemStack var1, ItemStack var2, int var3) { if (this.canCombineStackWithRemainder(var1, var2, var3)) { int var4 = this.getRemainingStackSize(var1, var2, var3); var1.stackSize = var4; var2.stackSize = this.getInventoryStackLimit(); } }
public ItemStack func_174894_a(ItemStack p_174894_1_) { ItemStack var2 = p_174894_1_.copy(); for (int var3 = 0; var3 < this.slotsCount; ++var3) { ItemStack var4 = this.getStackInSlot(var3); if (var4 == null) { this.setInventorySlotContents(var3, var2); this.markDirty(); return null; } if (ItemStack.areItemsEqual(var4, var2)) { int var5 = Math.min(this.getInventoryStackLimit(), var4.getMaxStackSize()); int var6 = Math.min(var2.stackSize, var5 - var4.stackSize); if (var6 > 0) { var4.stackSize += var6; var2.stackSize -= var6; if (var2.stackSize <= 0) { this.markDirty(); return null; } } } } if (var2.stackSize != p_174894_1_.stackSize) { this.markDirty(); } return var2; }
@Override public ItemStack removeItem(int maxRemove) { if (maxRemove <= 0) { return null; } int[] slots = getSlots(); if (slots == null) { return null; } for (int i : slots) { ItemStack s = getSlotContents(i); if (s != null && canRemoveItem(s, i)) { int toRemove = Math.min(s.stackSize, maxRemove); s.stackSize -= toRemove; ItemStack removed = s.copy(); removed.stackSize = toRemove; if (s.stackSize > 0) { _inv.setInventorySlotContents(i, s); } else { _inv.setInventorySlotContents(i, null); } _inv.markDirty(); return removed; } } return null; }
private void craftItem() { ItemStack recipeOutput = getRecipeOutput(); craftSlot.onPickupFromSlot(internalPlayer, recipeOutput); ItemStack[] tempStorage = internalInventoryCrafting.tempStacks; for (int i = 0; i < tempStorage.length; i++) { if (tempStorage[i] != null && tempStorage[i].stackSize <= 0) { tempStorage[i] = null; } inv.getItemStacks()[i] = tempStorage[i]; } subtractEnergy(getRequiredEnergy()); List<ItemStack> outputs = Lists.newArrayList(recipeOutput.copy()); for (int i = 0; i < internalPlayer.inventory.mainInventory.length; i++) { if (internalPlayer.inventory.mainInventory[i] != null) { outputs.add(internalPlayer.inventory.mainInventory[i]); internalPlayer.inventory.mainInventory[i] = null; } } for (ItemStack output : outputs) { output.stackSize -= Transactor.getTransactorFor(invOutput).add(output, ForgeDirection.UP, true).stackSize; if (output.stackSize > 0) { output.stackSize -= Utils.addToRandomInventoryAround(worldObj, xCoord, yCoord, zCoord, output); } if (output.stackSize > 0) { InvUtils.dropItems(worldObj, output, xCoord, yCoord + 1, zCoord); } } }
@Override public ItemStack removeItem(int maxRemove, ItemStack type) { if (maxRemove <= 0) { return null; } int[] slots = getSlots(); if (slots == null) { return null; } for (int i : slots) { ItemStack s = getSlotContents(i); if (ItemHelper.itemsEqualWithMetadata(s, type) && canRemoveItem(s, i)) { int toRemove = Math.min(s.stackSize, maxRemove); s.stackSize -= toRemove; ItemStack removed = s.copy(); removed.stackSize = toRemove; if (s.stackSize > 0) { _inv.setInventorySlotContents(i, s); } else { _inv.setInventorySlotContents(i, null); } return removed; } } return null; }
@Override public void renderTileEntityAt( TileEntityDryingTable tile, double xPos, double yPos, double zPos) { EntityItem customitem = new EntityItem(getWorldObj()); customitem.hoverStart = 0f; float blockScale = 1.0F; if (((TileEntityDryingTable) tile).getStackInSlot(0) != null) { GL11.glPushMatrix(); // start GL11.glTranslatef((float) xPos + 0.5F, (float) yPos + 0.5F, (float) zPos + 0.5F); if (RenderManager.instance.options.fancyGraphics) { GL11.glRotatef(180F, 0.0F, 1.0F, 0.0F); } GL11.glScalef(blockScale, blockScale, blockScale); ItemStack target = ((TileEntityDryingTable) tile).getStackInSlot(0).copy(); target.stackSize = 1; customitem.setEntityItemStack(target); itemRenderer.doRender(customitem, 0, 0, 0, 0, 0); GL11.glPopMatrix(); // end } if (((TileEntityDryingTable) tile).getStackInSlot(1) != null) { GL11.glPushMatrix(); // start GL11.glTranslatef((float) xPos + 0.5F, (float) yPos + 0.2F, (float) zPos + 0.5F); if (RenderManager.instance.options.fancyGraphics) { GL11.glRotatef(180F, 0.0F, 1.0F, 0.0F); } GL11.glScalef(blockScale, blockScale, blockScale); ItemStack target = ((TileEntityDryingTable) tile).getStackInSlot(1).copy(); target.stackSize = 1; customitem.setEntityItemStack(target); itemRenderer.doRender(customitem, 0, 0, 0, 0, 0); GL11.glPopMatrix(); // end } }
public InfuserRecipe(ItemStack first, ItemStack second, ItemStack result) { first.stackSize = Math.max(first.stackSize, 1); second.stackSize = Math.max(second.stackSize, 1); result.stackSize = Math.max(result.stackSize, 1); this.first = first; this.second = second; this.result = result; }
public static ArrayList<ItemStack> dumpToIInventory( ArrayList<ItemStack> stacks, IInventory inventory) { boolean debug = false; ArrayList<ItemStack> remaining = new ArrayList<ItemStack>(); // returns the remainder ItemStack chestStack; for (ItemStack current : stacks) { if (current == null) { continue; } for (int i = 0; i < inventory.getSizeInventory(); i++) { if (current == null) { continue; } chestStack = inventory.getStackInSlot(i); if (chestStack == null) { if (debug) System.out.println("DUMP " + i); inventory.setInventorySlotContents(i, current); // and dont add current ot remainder at all ! sweet! current = null; } else if (chestStack.isItemEqual(current)) { int space = chestStack.getMaxStackSize() - chestStack.stackSize; int toDeposit = Math.min(space, current.stackSize); if (toDeposit > 0) { if (debug) System.out.println("merge " + i + " ; toDeposit = " + toDeposit); current.stackSize -= toDeposit; chestStack.stackSize += toDeposit; if (current.stackSize == 0) { current = null; } } } } // finished current pass over inventory if (current != null) { if (debug) System.out.println("remaining.add : stackSize = " + current.stackSize); remaining.add(current); } } if (debug) System.out.println("remaining" + remaining.size()); return remaining; }
public FurnaceRecipeInfo(ItemStack input, ItemStack output) { ItemStack recipeInput = input.copy(); ArrayList<ItemStack> inputs = new ArrayList<>(); inputs.add(recipeInput); inputs.add(new ItemStack(Items.coal)); recipeItems = inputs; recipeOutput = output.copy(); recipeInput.stackSize *= 8; recipeOutput.stackSize *= 8; }
public static ItemStack addToOccupiedSlot( IInventory inventory, int slot, ItemStack stack, ItemStack existingStack) { int stackLimit = Math.min(inventory.getInventoryStackLimit(), stack.getMaxStackSize()); if (stack.stackSize + existingStack.stackSize > stackLimit) { int stackDiff = stackLimit - existingStack.stackSize; existingStack.stackSize = stackLimit; stack.stackSize -= stackDiff; inventory.setInventorySlotContents(slot, existingStack); return stack; } existingStack.stackSize += Math.min(stack.stackSize, stackLimit); inventory.setInventorySlotContents(slot, existingStack); return stackLimit >= stack.stackSize ? null : stack.splitStack(stack.stackSize - stackLimit); }
public static boolean fillFluidHandlerWithPlayerItem( World world, IFluidHandler handler, EntityPlayer player, ItemStack equipped) { if (equipped == null) return false; FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(equipped); if (fluid != null) { if (handler.fill(null, fluid, false) == fluid.amount || player.capabilities.isCreativeMode) { if (world.isRemote) return true; ItemStack filledStack = FluidContainerRegistry.drainFluidContainer(equipped); if (!player.capabilities.isCreativeMode) { if (equipped.stackSize == 1) { player.inventory.setInventorySlotContents(player.inventory.currentItem, null); player.inventory.addItemStackToInventory(filledStack); } else { equipped.stackSize -= 1; if (filledStack != null && !player.inventory.addItemStackToInventory(filledStack)) player.dropItem(filledStack, false, true); } player.openContainer.detectAndSendChanges(); if (player instanceof EntityPlayerMP) ((EntityPlayerMP) player) .updateCraftingInventory(player.openContainer, player.openContainer.getInventory()); } handler.fill(null, fluid, true); return true; } } else if (equipped.getItem() instanceof IFluidContainerItem) { IFluidContainerItem container = (IFluidContainerItem) equipped.getItem(); fluid = container.getFluid(equipped); if (handler.fill(null, fluid, false) > 0) { if (world.isRemote) return true; int fill = handler.fill(null, fluid, true); if (equipped.stackSize > 1) { ItemStack emptied = ItemStackUtils.copyStackWithAmount(equipped, 1); equipped.stackSize -= 1; container.drain(emptied, fill, true); if (!player.inventory.addItemStackToInventory(emptied)) player.dropItem(emptied, false, true); } else container.drain(equipped, fill, true); player.openContainer.detectAndSendChanges(); if (player instanceof EntityPlayerMP) ((EntityPlayerMP) player) .updateCraftingInventory(player.openContainer, player.openContainer.getInventory()); return true; } } return false; }
@Override public ItemStack addItem(ItemStack stack) { if (stack == null) { return null; } int quantitytoadd = stack.stackSize; ItemStack remaining = stack.copy(); int[] slots = getSlots(); if (slots == null) { return remaining; } for (int i : slots) { int maxStackSize = Math.min(_inv.getInventoryStackLimit(), stack.getMaxStackSize()); ItemStack s = getSlotContents(i); if (s == null) { ItemStack add = stack.copy(); add.stackSize = Math.min(quantitytoadd, maxStackSize); if (canAddItem(add, i)) { quantitytoadd -= add.stackSize; _inv.setInventorySlotContents(i, add); _inv.markDirty(); } } else if (ItemHelper.itemsEqualWithMetadata(s, stack)) { ItemStack add = stack.copy(); add.stackSize = Math.min(quantitytoadd, maxStackSize - s.stackSize); if (add.stackSize > 0 && canAddItem(add, i)) { s.stackSize += add.stackSize; quantitytoadd -= add.stackSize; _inv.setInventorySlotContents(i, s); _inv.markDirty(); } } if (quantitytoadd == 0) { break; } } remaining.stackSize = quantitytoadd; if (remaining.stackSize == 0) { return null; } else { return remaining; } }
@Override public ItemStack applyEffectByID(ItemStack artifact, int id, String trigger) { if (artifact.stackTagCompound == null) { artifact.stackTagCompound = this.createDefault(); } int[] a = artifact.stackTagCompound.getIntArray("allComponents"); Vector effectsOnItem = new Vector(); for (int i = 0; i < 5; ++i) { if (a[i] != 0) { effectsOnItem.add(a[i]); } } int numEff = 0; IArtifactComponent c = getComponent(id); if (!effectsOnItem.contains(c)) { if (trigger == null || trigger.equals("")) trigger = c.getRandomTrigger(rand); if (!artifact.stackTagCompound.hasKey(trigger)) { effectsOnItem.add(c); if (id == 9) { int bonus = a.length * 5; if (numEff == a.length) { numEff = 1; bonus = 0; artifact.stackSize = 10; } artifact.stackTagCompound.setInteger("cashBonus", bonus); } if (id == 7) { if (numEff == a.length) { if (trigger == "onDropped") { numEff = 1; artifact.stackSize = 10; } } } artifact.stackTagCompound.setInteger(trigger, id); for (int i = 0; i < 5; ++i) { if (a[i] == 0) { a[i] = id; i = 99; } } artifact.stackTagCompound.setIntArray("allComponents", a); } } return artifact; }
@Override public void setInventorySlotContents(int slot, ItemStack stack) { inv[slot] = stack; if (stack != null && stack.stackSize > getInventoryStackLimit()) { stack.stackSize = getInventoryStackLimit(); } }
public static ItemStack setLiquid(ItemStack bucket, FluidStack liquid) { if (LiquidRegistry.getName(liquid) != null) { bucket.stackSize = 1; bucket.setItemDamage(LiquidRegistry.getID(liquid)); } return bucket; }
/* Straight from InventoryHelper in vanilla code */ public static void spawnInWorld(World world, BlockPos pos, ItemStack itemStack) { float f = RANDOM.nextFloat() * 0.8F + 0.1F; float f1 = RANDOM.nextFloat() * 0.8F + 0.1F; float f2 = RANDOM.nextFloat() * 0.8F + 0.1F; while (itemStack.stackSize > 0) { int i = RANDOM.nextInt(21) + 10; if (i > itemStack.stackSize) i = itemStack.stackSize; itemStack.stackSize -= i; EntityItem entityitem = new EntityItem( world, pos.getX() + (double) f, pos.getY() + (double) f1, pos.getZ() + (double) f2, new ItemStack(itemStack.getItem(), i, itemStack.getMetadata())); if (itemStack.hasTagCompound()) entityitem .getEntityItem() .setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy()); float f3 = 0.05F; entityitem.motionX = RANDOM.nextGaussian() * (double) f3; entityitem.motionY = RANDOM.nextGaussian() * (double) f3 + 0.20000000298023224D; entityitem.motionZ = RANDOM.nextGaussian() * (double) f3; world.spawnEntityInWorld(entityitem); } }
@Override public void setInventorySlotContents(int i, ItemStack itemstack) { metalItemStacks[i] = itemstack; if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) { itemstack.stackSize = getInventoryStackLimit(); } }
public void sellProperty() { ArrayList<ItemStack> addedStacks = new ArrayList<ItemStack>(); for (ItemStack stack : price) { if (owner.inventory.addItemStackToInventory(stack)) addedStacks.add(stack); else { for (ItemStack addedStack : addedStacks) for (int i = 0; i < addedStack.stackSize; i++) owner.inventory.consumeInventoryItem( addedStack.itemID); // Abrar's PR: ,addedStack.getItemDamage()); break; } } ArrayList<ItemStack> takenStacks = new ArrayList<ItemStack>(); for (ItemStack stack : price) { ItemStack copyStack = stack.copy(); copyStack.stackSize = 0; do { if (!buyer.inventory.consumeInventoryItem(stack.itemID)) for (ItemStack takenStack : takenStacks) owner.inventory.addItemStackToInventory(copyStack); copyStack.stackSize++; } while (copyStack.stackSize < stack.stackSize); if (copyStack.stackSize == stack.stackSize) takenStacks.add(copyStack); } }
/** * 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.slots[par1] = par2ItemStack; if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit()) { par2ItemStack.stackSize = this.getInventoryStackLimit(); } }
public static void spawnEntityItem(World world, ItemStack stack, double x, double y, double z) { float f = world.rand.nextFloat() * 0.8F + 0.1F; float f1 = world.rand.nextFloat() * 0.8F + 0.1F; EntityItem entityitem; for (float f2 = world.rand.nextFloat() * 0.8F + 0.1F; stack.stackSize > 0; world.spawnEntityInWorld(entityitem)) { int j1 = world.rand.nextInt(21) + 10; if (j1 > stack.stackSize) j1 = stack.stackSize; stack.stackSize -= j1; entityitem = new EntityItem( world, (double) ((float) x + f), (double) ((float) y + f1), (double) ((float) z + f2), new ItemStack(stack.getItem(), j1, stack.getItemDamage())); float f3 = 0.05F; entityitem.motionX = (double) ((float) world.rand.nextGaussian() * f3); entityitem.motionY = (double) ((float) world.rand.nextGaussian() * f3 + 0.2F); entityitem.motionZ = (double) ((float) world.rand.nextGaussian() * f3); if (stack.hasTagCompound()) { entityitem.getEntityItem().setTagCompound((NBTTagCompound) stack.getTagCompound().copy()); } } }
private void dropItems(World world, int x, int y, int z) { Random rand = new Random(); TileEntity tileEntity = world.getBlockTileEntity(x, y, z); if (!(tileEntity instanceof IInventory)) { return; } IInventory inventory = (IInventory) tileEntity; for (int i = 0; i < inventory.getSizeInventory(); i++) { ItemStack item = inventory.getStackInSlot(i); if (item != null && item.stackSize > 0) { float rx = rand.nextFloat() * 0.8F + 0.1F; float ry = rand.nextFloat() * 0.8F + 0.1F; float rz = rand.nextFloat() * 0.8F + 0.1F; EntityItem entityItem = new EntityItem( world, x + rx, y + ry, z + rz, new ItemStack(item.itemID, item.stackSize, item.getItemDamage())); if (item.hasTagCompound()) { entityItem.getEntityItem().setTagCompound((NBTTagCompound) item.getTagCompound().copy()); } float factor = 0.05F; entityItem.motionX = rand.nextGaussian() * factor; entityItem.motionY = rand.nextGaussian() * factor + 0.2F; entityItem.motionZ = rand.nextGaussian() * factor; world.spawnEntityInWorld(entityItem); item.stackSize = 0; } } }
@Override public void setInventorySlotContents(int i, ItemStack itemstack) { this.inventory[i] = itemstack; if ((itemstack != null) && (itemstack.stackSize > getInventoryStackLimit())) { itemstack.stackSize = getInventoryStackLimit(); } }
public boolean onItemUse( ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, BlockPos pos, EnumFacing par5EnumFacing, float hitX, float hitY, float hitZ) { if (!par3World.isRemote) { if (BlockUtils.getBlock(par3World, pos) == mod_SecurityCraft.frame) { String owner = ((IOwnable) par3World.getTileEntity(pos)).getOwnerName(); String uuid = ((IOwnable) par3World.getTileEntity(pos)).getOwnerUUID(); EnumFacing enumfacing = (EnumFacing) par3World.getBlockState(pos).getValue(BlockKeypad.FACING); par3World.setBlockState( pos, mod_SecurityCraft .Keypad .getDefaultState() .withProperty(BlockKeypad.FACING, enumfacing) .withProperty(BlockKeypad.POWERED, false)); ((IOwnable) par3World.getTileEntity(pos)).setOwner(uuid, owner); par1ItemStack.stackSize -= 1; } return true; } return false; }