Search in sources :

Example 1 with CraftingRecipe

use of mcjty.rftools.craftinggrid.CraftingRecipe in project RFTools by McJty.

the class CrafterBaseTE method writeRecipesToNBT.

private void writeRecipesToNBT(NBTTagCompound tagCompound) {
    NBTTagList recipeTagList = new NBTTagList();
    for (CraftingRecipe recipe : recipes) {
        NBTTagCompound nbtTagCompound = new NBTTagCompound();
        recipe.writeToNBT(nbtTagCompound);
        recipeTagList.appendTag(nbtTagCompound);
    }
    tagCompound.setTag("Recipes", recipeTagList);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) CraftingRecipe(mcjty.rftools.craftinggrid.CraftingRecipe)

Example 2 with CraftingRecipe

use of mcjty.rftools.craftinggrid.CraftingRecipe in project RFTools by McJty.

the class GuiCrafter method applyRecipe.

private void applyRecipe() {
    int selected = recipeList.getSelected();
    if (selected == -1) {
        return;
    }
    if (selected >= tileEntity.getSupportedRecipes()) {
        recipeList.setSelected(-1);
        return;
    }
    CraftingRecipe craftingRecipe = tileEntity.getRecipe(selected);
    InventoryCrafting inv = craftingRecipe.getInventory();
    for (int i = 0; i < 9; i++) {
        ItemStack oldStack = inv.getStackInSlot(i);
        ItemStack newStack = inventorySlots.getSlot(i).getStack();
        if (!itemStacksEqual(oldStack, newStack)) {
            inv.setInventorySlotContents(i, newStack);
        }
    }
    // Compare current contents to avoid unneeded slot update.
    IRecipe recipe = CraftingRecipe.findRecipe(mc.world, inv);
    ItemStack newResult;
    if (recipe == null) {
        newResult = ItemStack.EMPTY;
    } else {
        newResult = recipe.getCraftingResult(inv);
    }
    ItemStack oldResult = inventorySlots.getSlot(9).getStack();
    if (!itemStacksEqual(oldResult, newResult)) {
        inventorySlots.getSlot(9).putStack(newResult);
    }
    craftingRecipe.setResult(newResult);
    updateRecipe();
    populateList();
}
Also used : IRecipe(net.minecraft.item.crafting.IRecipe) CraftingRecipe(mcjty.rftools.craftinggrid.CraftingRecipe) InventoryCrafting(net.minecraft.inventory.InventoryCrafting) ItemStack(net.minecraft.item.ItemStack)

Example 3 with CraftingRecipe

use of mcjty.rftools.craftinggrid.CraftingRecipe in project RFTools by McJty.

the class GuiCrafter method populateList.

private void populateList() {
    recipeList.removeChildren();
    for (int i = 0; i < tileEntity.getSupportedRecipes(); i++) {
        CraftingRecipe recipe = tileEntity.getRecipe(i);
        addRecipeLine(recipe.getResult());
    }
}
Also used : CraftingRecipe(mcjty.rftools.craftinggrid.CraftingRecipe)

Example 4 with CraftingRecipe

use of mcjty.rftools.craftinggrid.CraftingRecipe in project RFTools by McJty.

the class CrafterBaseTE method selectRecipe.

public void selectRecipe(int index) {
    CraftingRecipe recipe = recipes[index];
    setInventorySlotContents(CrafterContainer.SLOT_CRAFTOUTPUT, recipe.getResult());
    InventoryCrafting inv = recipe.getInventory();
    int size = inv.getSizeInventory();
    for (int i = 0; i < size; ++i) {
        setInventorySlotContents(CrafterContainer.SLOT_CRAFTINPUT + i, inv.getStackInSlot(i));
    }
}
Also used : CraftingRecipe(mcjty.rftools.craftinggrid.CraftingRecipe) InventoryCrafting(net.minecraft.inventory.InventoryCrafting)

Example 5 with CraftingRecipe

use of mcjty.rftools.craftinggrid.CraftingRecipe in project RFTools by McJty.

the class CrafterBaseTE method craftOneItemNew.

private boolean craftOneItemNew(CraftingRecipe craftingRecipe) {
    IRecipe recipe = craftingRecipe.getCachedRecipe(getWorld());
    if (recipe == null) {
        return false;
    }
    Map<Integer, ItemStack> undo = new HashMap<>();
    if (!testAndConsumeCraftingItems(craftingRecipe, undo, true)) {
        undo(undo);
        if (!testAndConsumeCraftingItems(craftingRecipe, undo, false)) {
            undo(undo);
            return false;
        }
    }
    // ItemStack result = recipe.getCraftingResult(craftingRecipe.getInventory());
    ItemStack result = ItemStack.EMPTY;
    try {
        result = recipe.getCraftingResult(workInventory);
    } catch (RuntimeException e) {
        // Ignore this error for now to make sure we don't crash on bad recipes.
        Logging.logError("Problem with recipe!", e);
    }
    // Try to merge the output. If there is something that doesn't fit we undo everything.
    CraftingRecipe.CraftMode mode = craftingRecipe.getCraftMode();
    if (!result.isEmpty() && placeResult(mode, result, undo)) {
        List<ItemStack> remaining = recipe.getRemainingItems(workInventory);
        if (remaining != null) {
            CraftingRecipe.CraftMode remainingMode = mode == EXTC ? INT : mode;
            for (ItemStack s : remaining) {
                if (!s.isEmpty()) {
                    if (!placeResult(remainingMode, s, undo)) {
                        // Not enough room.
                        undo(undo);
                        return false;
                    }
                }
            }
        }
        return true;
    } else {
        // We don't have place. Undo the operation.
        undo(undo);
        return false;
    }
}
Also used : IRecipe(net.minecraft.item.crafting.IRecipe) HashMap(java.util.HashMap) CraftingRecipe(mcjty.rftools.craftinggrid.CraftingRecipe) ItemStack(net.minecraft.item.ItemStack)

Aggregations

CraftingRecipe (mcjty.rftools.craftinggrid.CraftingRecipe)7 InventoryCrafting (net.minecraft.inventory.InventoryCrafting)3 ItemStack (net.minecraft.item.ItemStack)2 IRecipe (net.minecraft.item.crafting.IRecipe)2 HashMap (java.util.HashMap)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1