Search in sources :

Example 1 with CraftingSourceTileEntity

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

the class InventoryCraftingStation method craft.

/** Called when an item is removed from the output slot while it doesn't
	 *  store any real items. Returns if the recipe can be crafted again.*/
private boolean craft(EntityPlayer player, boolean simulate) {
    ItemStack[] contents = (simulate ? this.contents.clone() : this.contents);
    ItemStack[] crafting = (simulate ? this.crafting.clone() : this.crafting);
    if (simulate)
        for (int i = 0; i < crafting.length; i++) crafting[i] = ItemStack.copyItemStack(crafting[i]);
    if (currentCrafting instanceof VanillaStationCrafting) {
        boolean unset = false;
        if (player == null) {
            player = FakePlayer.get(entity);
            unset = true;
        }
        ItemStack craftOutput = (simulate ? output[4].copy() : output[4]);
        IInventory craftMatrix = new InventoryStacks(crafting);
        FMLCommonHandler.instance().firePlayerCraftingEvent(player, craftOutput, craftMatrix);
        new CustomSlotCrafting(player, craftOutput);
        if (unset) {
            FakePlayer.unset();
            player = null;
        }
    }
    ICraftingSource source = new CraftingSourceTileEntity(entity, player);
    currentCrafting.craft(source);
    IRecipeInput[] requiredInput = currentCrafting.getCraftRequirements();
    for (int i = 0; i < crafting.length; i++) if (crafting[i] != null)
        crafting[i] = craftSlot(crafting[i], requiredInput[i], player, simulate);
    boolean pulled = pullRequired(contents, crafting, requiredInput);
    if (!simulate) {
        int requiredExperience = currentCrafting.getRequiredExperience();
        if ((requiredExperience != 0) && (player != null) && !player.capabilities.isCreativeMode)
            player.experienceLevel -= requiredExperience;
        outputIsReal = !outputEmpty();
        progress = 0;
        inputChanged();
        checkHasRequirements = true;
    }
    return pulled;
}
Also used : VanillaStationCrafting(net.mcft.copy.betterstorage.item.recipe.VanillaStationCrafting) IInventory(net.minecraft.inventory.IInventory) ICraftingSource(net.mcft.copy.betterstorage.api.crafting.ICraftingSource) CraftingSourceTileEntity(net.mcft.copy.betterstorage.api.crafting.CraftingSourceTileEntity) IRecipeInput(net.mcft.copy.betterstorage.api.crafting.IRecipeInput) ItemStack(net.minecraft.item.ItemStack)

Aggregations

CraftingSourceTileEntity (net.mcft.copy.betterstorage.api.crafting.CraftingSourceTileEntity)1 ICraftingSource (net.mcft.copy.betterstorage.api.crafting.ICraftingSource)1 IRecipeInput (net.mcft.copy.betterstorage.api.crafting.IRecipeInput)1 VanillaStationCrafting (net.mcft.copy.betterstorage.item.recipe.VanillaStationCrafting)1 IInventory (net.minecraft.inventory.IInventory)1 ItemStack (net.minecraft.item.ItemStack)1