List of usage examples for net.minecraftforge.items ItemHandlerHelper insertItemStacked
@Nonnull public static ItemStack insertItemStacked(IItemHandler inventory, @Nonnull ItemStack stack, boolean simulate)
From source file:daxum.temporalconvergence.tileentity.TileTimeChest.java
License:Open Source License
private void convertItemInSlot(int slot) { ItemStack stack = inventory.getStackInSlot(slot); ItemStack output = TimeChestRecipes.getOutput(stack); int amount = 0; if (!output.isEmpty()) { amount = stack.getCount() * output.getCount(); } else if (stack.getItem() instanceof ItemFood) { final int foodValue = Math.max(((ItemFood) stack.getItem()).getHealAmount(stack), 1); final double dustAmount = stack.getCount() * foodValue / 4.0; if (dustAmount < 1.0) { amount = dustAmount > world.rand.nextDouble() ? 1 : 0; } else {/*from w w w . j a v a2s. c om*/ final int intDust = MathHelper.floor(dustAmount); amount = intDust + (dustAmount - intDust > world.rand.nextDouble() ? 1 : 0); } output = new ItemStack(ModItems.ANCIENT_DUST); } if (!output.isEmpty()) { output.setCount(Math.min(Math.min(amount, inventory.getSlotLimit(slot)), output.getMaxStackSize())); final int extra = amount - output.getCount(); inventory.setStackInSlot(slot, output); //If can't fit in slot, add to other slots. If it still can't fit, just get rid of it if (extra > 0) { ItemHandlerHelper.insertItemStacked(inventory, new ItemStack(output.getItem(), extra, output.getMetadata()), false); } } }