Search in sources :

Example 1 with TileEntitySecondaryInputBase

use of com.codetaylor.mc.artisanworktables.modules.worktables.tile.spi.TileEntitySecondaryInputBase in project artisan-worktables by codetaylor.

the class CSPacketWorktableClear method clear.

public static void clear(TileEntityBase table, int clearFlags) {
    if ((clearFlags & CLEAR_FLUID) == CLEAR_FLUID) {
        FluidTank tank = table.getTank();
        tank.drain(tank.getCapacity(), true);
        ModuleWorktables.PACKET_SERVICE.sendToAllAround(new SCPacketWorktableFluidUpdate(table.getPos(), tank), table);
    }
    if ((clearFlags & CLEAR_GRID) == CLEAR_GRID) {
        ICraftingMatrixStackHandler craftingMatrixHandler = table.getCraftingMatrixHandler();
        for (int i = 0; i < craftingMatrixHandler.getSlots(); i++) {
            craftingMatrixHandler.setStackInSlot(i, ItemStack.EMPTY);
        }
    }
    if ((clearFlags & CLEAR_OUTPUT) == CLEAR_OUTPUT) {
        ItemStackHandler resultHandler = table.getResultHandler();
        resultHandler.setStackInSlot(0, ItemStack.EMPTY);
    }
    if ((clearFlags & CLEAR_TOOLS) == CLEAR_TOOLS) {
        ItemStackHandler toolHandler = table.getToolHandler();
        for (int i = 0; i < toolHandler.getSlots(); i++) {
            toolHandler.setStackInSlot(i, ItemStack.EMPTY);
        }
    }
    if ((clearFlags & CLEAR_EXTRA_OUTPUT) == CLEAR_EXTRA_OUTPUT) {
        ItemStackHandler secondaryOutputHandler = table.getSecondaryOutputHandler();
        for (int i = 0; i < secondaryOutputHandler.getSlots(); i++) {
            secondaryOutputHandler.setStackInSlot(i, ItemStack.EMPTY);
        }
    }
    if (table instanceof TileEntitySecondaryInputBase && (clearFlags & CLEAR_SECONDARY_INPUT) == CLEAR_SECONDARY_INPUT) {
        IItemHandlerModifiable secondaryIngredientHandler = ((TileEntitySecondaryInputBase) table).getSecondaryIngredientHandler();
        for (int i = 0; i < secondaryIngredientHandler.getSlots(); i++) {
            secondaryIngredientHandler.setStackInSlot(i, ItemStack.EMPTY);
        }
    }
}
Also used : FluidTank(net.minecraftforge.fluids.FluidTank) ItemStackHandler(net.minecraftforge.items.ItemStackHandler) ICraftingMatrixStackHandler(com.codetaylor.mc.artisanworktables.api.internal.recipe.ICraftingMatrixStackHandler) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) TileEntitySecondaryInputBase(com.codetaylor.mc.artisanworktables.modules.worktables.tile.spi.TileEntitySecondaryInputBase)

Example 2 with TileEntitySecondaryInputBase

use of com.codetaylor.mc.artisanworktables.modules.worktables.tile.spi.TileEntitySecondaryInputBase in project artisan-worktables by codetaylor.

the class ZSRecipeExport method getExportString.

public static String getExportString(AWContainer container, TileEntityBase tileEntity, boolean shaped) {
    ICraftingMatrixStackHandler craftingMatrixHandler = tileEntity.getCraftingMatrixHandler();
    int width = craftingMatrixHandler.getWidth();
    int height = craftingMatrixHandler.getHeight();
    ItemStackHandler resultHandler = tileEntity.getResultHandler();
    ItemStackHandler secondaryOutputHandler = tileEntity.getSecondaryOutputHandler();
    FluidTank tank = tileEntity.getTank();
    // - start
    StringBuilder out = new StringBuilder();
    out.append("RecipeBuilder.get(\"").append(tileEntity.getType().getName()).append("\")\n");
    // -------------------------------------------------------------------------
    if (shaped) {
        out.append("  .setShaped([\n");
        int xMin = width, xMax = 0;
        int yMin = height, yMax = 0;
        for (int i = container.slotIndexCraftingMatrixStart; i <= container.slotIndexCraftingMatrixEnd; i++) {
            int x = (i - container.slotIndexCraftingMatrixStart) % width;
            int y = (i - container.slotIndexCraftingMatrixStart) / width;
            if (container.getSlot(i).getHasStack()) {
                if (x < xMin) {
                    xMin = x;
                }
                if (x > xMax) {
                    xMax = x;
                }
                if (y < yMin) {
                    yMin = y;
                }
                if (y > yMax) {
                    yMax = y;
                }
            }
        }
        int actualWidth = xMax - xMin + 1;
        int actualHeight = yMax - yMin + 1;
        ItemStack[] remappedGrid = new ItemStack[actualWidth * actualHeight];
        for (int i = container.slotIndexCraftingMatrixStart; i <= container.slotIndexCraftingMatrixEnd; i++) {
            int x = (i - container.slotIndexCraftingMatrixStart) % width;
            int y = (i - container.slotIndexCraftingMatrixStart) / height;
            if (x < xMin || x > xMax) {
                continue;
            }
            if (y < yMin || y > yMax) {
                continue;
            }
            Slot slot = container.getSlot(i);
            ItemStack stack = slot.getStack();
            int xMapped = x - xMin;
            int yMapped = y - yMin;
            remappedGrid[xMapped + yMapped * actualWidth] = stack;
        }
        for (int i = 0; i < remappedGrid.length; i++) {
            int x = i % actualWidth;
            int y = i / actualWidth;
            if (x == 0) {
                out.append("    [");
            }
            int containerIndex = container.slotIndexCraftingMatrixStart + (x + xMin) + (y + yMin) * width;
            String oreDict = tileEntity.oreDictMap.lookup(containerIndex);
            ItemStack stackInSlot = remappedGrid[i];
            if (oreDict == null) {
                ZSRecipeExport.getItemString(stackInSlot, out, true, false, false);
            } else {
                ZSRecipeExport.getItemStringOredict(oreDict, stackInSlot, out, true);
            }
            if (i == remappedGrid.length - 1) {
                // finished with the whole thing
                out.append("]])\n");
            } else if (x == actualWidth - 1) {
                // finished with the row
                out.append("],\n");
            } else {
                out.append(", ");
            }
        }
    } else {
        List<String> list = new ArrayList<>();
        for (int i = container.slotIndexCraftingMatrixStart; i <= container.slotIndexCraftingMatrixEnd; i++) {
            String oreDict = tileEntity.oreDictMap.lookup(i);
            ItemStack stackInSlot = container.getSlot(i).getStack();
            if (!stackInSlot.isEmpty()) {
                StringBuilder builder = new StringBuilder();
                if (oreDict == null) {
                    ZSRecipeExport.getItemString(stackInSlot, builder, true, false, false);
                } else {
                    ZSRecipeExport.getItemStringOredict(oreDict, stackInSlot, builder, true);
                }
                list.add(builder.toString());
            }
        }
        out.append("  .setShapeless([").append(String.join(", ", list)).append("])\n");
    }
    // -------------------------------------------------------------------------
    if (tank.getFluidAmount() > 0 && tank.getFluid() != null) {
        FluidStack fluid = tank.getFluid();
        String name = fluid.getFluid().getName();
        out.append("  .setFluid(<").append("liquid:").append(name).append("> * ").append(fluid.amount).append(")\n");
    }
    // -------------------------------------------------------------------------
    if (tileEntity instanceof TileEntitySecondaryInputBase) {
        IItemHandlerModifiable secondaryIngredientHandler = ((TileEntitySecondaryInputBase) tileEntity).getSecondaryIngredientHandler();
        int total = 0;
        int count = 0;
        for (int i = 0; i < secondaryIngredientHandler.getSlots(); i++) {
            if (!secondaryIngredientHandler.getStackInSlot(i).isEmpty()) {
                total += 1;
            }
        }
        if (total > 0) {
            out.append("  .setSecondaryIngredients([");
            for (int i = container.slotIndexSecondaryInputStart; i <= container.slotIndexSecondaryInputEnd; i++) {
                String oreDict = tileEntity.oreDictMap.lookup(i);
                ItemStack stackInSlot = container.getSlot(i).getStack();
                if (stackInSlot.isEmpty()) {
                    continue;
                }
                StringBuilder builder = new StringBuilder();
                if (oreDict == null) {
                    ZSRecipeExport.getItemString(stackInSlot, builder, false, false, false);
                } else {
                    ZSRecipeExport.getItemStringOredict(oreDict, stackInSlot, builder, false);
                }
                count += 1;
                out.append(builder.toString());
                out.append((count == total) ? "" : ", ");
            }
            out.append("])\n");
        }
    }
    // - addTool
    // -------------------------------------------------------------------------
    {
        for (int i = container.slotIndexToolsStart; i <= container.slotIndexToolsEnd; i++) {
            String oreDict = tileEntity.oreDictMap.lookup(i);
            ItemStack stackInSlot = container.getSlot(i).getStack();
            if (!stackInSlot.isEmpty()) {
                out.append("  .addTool(");
                StringBuilder builder = new StringBuilder();
                if (oreDict == null) {
                    ZSRecipeExport.getItemString(stackInSlot, builder, true, false, false);
                } else {
                    ZSRecipeExport.getItemStringOredict(oreDict, stackInSlot, builder, true);
                }
                out.append(builder.toString());
                out.append(", 1)\n");
            }
        }
    }
    // - setOutput
    // -------------------------------------------------------------------------
    {
        ItemStack stackInSlot = resultHandler.getStackInSlot(0);
        out.append("  .addOutput(");
        ZSRecipeExport.getItemString(stackInSlot, out, false, false, false);
        out.append(")\n");
    }
    // - setSecondaryOutput
    // -------------------------------------------------------------------------
    {
        int slot = 0;
        for (int i = 0; i < secondaryOutputHandler.getSlots(); i++) {
            ItemStack stackInSlot = secondaryOutputHandler.getStackInSlot(i);
            if (stackInSlot.isEmpty()) {
                continue;
            }
            if (slot == 0) {
                slot += 1;
                out.append("  .setExtraOutputOne(");
                ZSRecipeExport.getItemString(stackInSlot, out, false, false, false);
                out.append(", 1.0)\n");
            } else if (slot == 1) {
                slot += 1;
                out.append("  .setExtraOutputTwo(");
                ZSRecipeExport.getItemString(stackInSlot, out, false, false, false);
                out.append(", 1.0)\n");
            } else if (slot == 2) {
                slot += 1;
                out.append("  .setExtraOutputThree(");
                ZSRecipeExport.getItemString(stackInSlot, out, false, false, false);
                out.append(", 1.0)\n");
            }
        }
    }
    // - create
    // -------------------------------------------------------------------------
    out.append("  .create();");
    return out.toString();
}
Also used : ItemStackHandler(net.minecraftforge.items.ItemStackHandler) FluidStack(net.minecraftforge.fluids.FluidStack) TileEntitySecondaryInputBase(com.codetaylor.mc.artisanworktables.modules.worktables.tile.spi.TileEntitySecondaryInputBase) ArrayList(java.util.ArrayList) FluidTank(net.minecraftforge.fluids.FluidTank) ICraftingMatrixStackHandler(com.codetaylor.mc.artisanworktables.api.internal.recipe.ICraftingMatrixStackHandler) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ICraftingMatrixStackHandler (com.codetaylor.mc.artisanworktables.api.internal.recipe.ICraftingMatrixStackHandler)2 TileEntitySecondaryInputBase (com.codetaylor.mc.artisanworktables.modules.worktables.tile.spi.TileEntitySecondaryInputBase)2 FluidTank (net.minecraftforge.fluids.FluidTank)2 IItemHandlerModifiable (net.minecraftforge.items.IItemHandlerModifiable)2 ItemStackHandler (net.minecraftforge.items.ItemStackHandler)2 ArrayList (java.util.ArrayList)1 Slot (net.minecraft.inventory.Slot)1 ItemStack (net.minecraft.item.ItemStack)1 FluidStack (net.minecraftforge.fluids.FluidStack)1