Search in sources :

Example 1 with ContainerInfo

use of net.mcft.copy.betterstorage.api.crafting.ContainerInfo in project BetterStorage by copygirl.

the class InventoryCraftingStation method craftSlot.

private ItemStack craftSlot(ItemStack stack, IRecipeInput requiredInput, EntityPlayer player, boolean simulate) {
    if (simulate)
        stack = stack.copy();
    ContainerInfo containerInfo = new ContainerInfo();
    requiredInput.craft(stack, containerInfo);
    ItemStack containerItem = ItemStack.copyItemStack(containerInfo.getContainerItem());
    boolean removeStack = false;
    if (stack.stackSize <= 0) {
        // Item stack is depleted.
        removeStack = true;
    } else if (stack.getItem().isDamageable() && (stack.getItemDamage() > stack.getMaxDamage())) {
        // Item stack is destroyed.
        removeStack = true;
        if (player != null)
            MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, stack));
    }
    // to either null, or the container item.
    if (removeStack) {
        if (!containerInfo.doesLeaveCrafting()) {
            stack = containerItem;
            containerItem = null;
        } else
            stack = null;
    }
    if ((containerItem != null) && !simulate) {
        // Try to add the container item to the internal storage, or spawn the item in the world.
        if (!InventoryUtils.tryAddItemToInventory(containerItem, new InventoryStacks(contents), true) && (entity != null))
            WorldUtils.spawnItem(entity.getWorldObj(), entity.xCoord + 0.5, entity.yCoord + 0.5, entity.zCoord + 0.5, containerItem);
    }
    return stack;
}
Also used : ContainerInfo(net.mcft.copy.betterstorage.api.crafting.ContainerInfo) ItemStack(net.minecraft.item.ItemStack) PlayerDestroyItemEvent(net.minecraftforge.event.entity.player.PlayerDestroyItemEvent)

Aggregations

ContainerInfo (net.mcft.copy.betterstorage.api.crafting.ContainerInfo)1 ItemStack (net.minecraft.item.ItemStack)1 PlayerDestroyItemEvent (net.minecraftforge.event.entity.player.PlayerDestroyItemEvent)1