Search in sources :

Example 6 with ItemPart

use of com.bluepowermod.item.ItemPart in project BluePower by Qmunity.

the class RecipeNullCell method getCraftingResult.

private ItemStack getCraftingResult(IInventory inv, EntityPlayer player, boolean isCrafting) {
    if (inv.getSizeInventory() < 9)
        return null;
    int centerX = 0;
    int centerY = 0;
    GateNullCell gnc = null;
    // Find the null cell
    for (int x = 0; x < 3; x++) {
        for (int y = 0; y < 3; y++) {
            ItemStack item = getItemAt(inv, x, y);
            if (item == null)
                continue;
            if (!(item.getItem() instanceof ItemPart))
                continue;
            IPart p = ((ItemPart) item.getItem()).createPart(item, BluePower.proxy.getPlayer(), null, null);
            if (p != null && p instanceof GateNullCell) {
                gnc = (GateNullCell) p;
                centerX = x;
                centerY = y;
                break;
            }
        }
        if (gnc != null)
            break;
    }
    // If there's no null cell, return null
    if (gnc == null)
        return null;
    // Make this recipe invalid if there's items where there shouldn't be
    {
        // To the right
        if (centerX < 2)
            for (int x = centerX + 1; x < 3; x++) for (int y = 0; y < 3; y++) if (getItemAt(inv, x, y) != null)
                return null;
        // To the left - 1
        for (int x = 0; x < centerX - 1; x++) for (int y = 0; y < 3; y++) if (getItemAt(inv, x, y) != null)
            return null;
        // To the left
        if (centerX > 0) {
            if (getItemAt(inv, centerX - 1, 0) != null)
                return null;
            if (getItemAt(inv, centerX - 1, 2) != null)
                return null;
        }
    }
    // Determine what kind of crafting operation this is
    // Removing > adding
    {
        // Removing
        {
            // Screwdriver on top
            if (centerY > 0) {
                ItemStack sd = getItemAt(inv, centerX, centerY - 1);
                if (sd != null && sd.getItem() instanceof ItemScrewdriver) {
                    RedwireType t = gnc.getTypeB();
                    boolean bundled = gnc.isBundledB();
                    if (t != null) {
                        boolean can = true;
                        if (centerY < 2)
                            if (getItemAt(inv, centerX, centerY + 1) != null)
                                can = false;
                        if (centerX > 0)
                            if (getItemAt(inv, centerX - 1, centerY) != null)
                                can = false;
                        if (!((IScrewdriver) sd.getItem()).damage(sd, getItemAt(inv, centerX, centerY).stackSize, null, true))
                            can = false;
                        if (can) {
                            ItemStack wire = PartManager.getPartInfo("wire." + t.getName() + (bundled ? ".bundled" : "")).getStack(getItemAt(inv, centerX, centerY).stackSize);
                            if (isCrafting) {
                                gnc = new GateNullCell(gnc.getTypeA(), gnc.isBundledA(), null, false);
                                ItemStack nullCellStack = GateNullCell.getStackWithData(gnc);
                                nullCellStack.stackSize = getItemAt(inv, centerX, centerY).stackSize + 1;
                                setItemAt(inv, centerX, centerY, nullCellStack);
                                sd.stackSize++;
                                ((IScrewdriver) sd.getItem()).damage(sd, nullCellStack.stackSize - 1, null, false);
                            }
                            return wire;
                        }
                    }
                }
            }
            // Screwdriver below
            if (centerY < 2) {
                ItemStack sd = getItemAt(inv, centerX, centerY + 1);
                if (sd != null && sd.getItem() instanceof ItemScrewdriver) {
                    RedwireType t = gnc.getTypeA();
                    boolean bundled = gnc.isBundledA();
                    if (t != null) {
                        boolean can = true;
                        if (centerY > 0)
                            if (getItemAt(inv, centerX, centerY - 1) != null)
                                can = false;
                        if (centerX > 0)
                            if (getItemAt(inv, centerX - 1, centerY) != null)
                                can = false;
                        if (!((IScrewdriver) sd.getItem()).damage(sd, getItemAt(inv, centerX, centerY).stackSize, null, true))
                            can = false;
                        if (can) {
                            ItemStack wire = PartManager.getPartInfo("wire." + t.getName() + (bundled ? ".bundled" : "")).getStack(getItemAt(inv, centerX, centerY).stackSize);
                            if (isCrafting) {
                                gnc = new GateNullCell(null, false, gnc.getTypeB(), gnc.isBundledB());
                                ItemStack nullCellStack = GateNullCell.getStackWithData(gnc);
                                nullCellStack.stackSize = getItemAt(inv, centerX, centerY).stackSize + 1;
                                setItemAt(inv, centerX, centerY, nullCellStack);
                                sd.stackSize++;
                                ((IScrewdriver) sd.getItem()).damage(sd, nullCellStack.stackSize - 1, null, false);
                            }
                            return wire;
                        }
                    }
                }
            }
            // Screwdriver on the left
            if (centerX > 0) {
                ItemStack sd = getItemAt(inv, centerX - 1, centerY);
                if (sd != null && sd.getItem() instanceof ItemScrewdriver) {
                    RedwireType tA = gnc.getTypeA();
                    boolean bundledA = gnc.isBundledA();
                    RedwireType tB = gnc.getTypeB();
                    boolean bundledB = gnc.isBundledB();
                    if (tA != null || tB != null) {
                        boolean can = true;
                        if (centerY > 0)
                            if (getItemAt(inv, centerX, centerY - 1) != null)
                                can = false;
                        if (centerY < 2)
                            if (getItemAt(inv, centerX, centerY + 1) != null)
                                can = false;
                        int amt = 0;
                        if (tA != null && (tB == null || tB == tA))
                            amt += getItemAt(inv, centerX, centerY).stackSize;
                        if (tB != null)
                            amt += getItemAt(inv, centerX, centerY).stackSize;
                        if (amt > 64)
                            can = false;
                        if (!((IScrewdriver) sd.getItem()).damage(sd, amt, null, true))
                            can = false;
                        if (can) {
                            ItemStack wire = null;
                            if (tB != null) {
                                wire = PartManager.getPartInfo("wire." + tB.getName() + (bundledB ? ".bundled" : "")).getStack(amt);
                            } else {
                                wire = PartManager.getPartInfo("wire." + tA.getName() + (bundledA ? ".bundled" : "")).getStack(amt);
                            }
                            if (isCrafting) {
                                if (tA != null && tB != null && tA == tB) {
                                    gnc = new GateNullCell(null, false, null, false);
                                } else if (tB != null) {
                                    gnc = new GateNullCell(gnc.getTypeA(), gnc.isBundledA(), null, false);
                                } else if (tA != null) {
                                    gnc = new GateNullCell(null, false, gnc.getTypeB(), gnc.isBundledB());
                                }
                                ItemStack nullCellStack = GateNullCell.getStackWithData(gnc);
                                nullCellStack.stackSize = getItemAt(inv, centerX, centerY).stackSize + 1;
                                setItemAt(inv, centerX, centerY, nullCellStack);
                                sd.stackSize++;
                                System.out.println(((IScrewdriver) sd.getItem()).damage(sd, amt, null, false) + " " + player);
                            }
                            return wire;
                        }
                    }
                }
            }
        }
        // Adding
        {
            // Wire on top
            if (centerY > 0 && gnc.getTypeB() == null) {
                ItemStack wire = getItemAt(inv, centerX, centerY - 1);
                if (wire != null && wire.getItem() instanceof ItemPart) {
                    IPart p = ((ItemPart) wire.getItem()).createPart(wire, BluePower.proxy.getPlayer(), null, null);
                    if (p != null && p instanceof PartRedwireFaceUninsulated) {
                        RedwireType t = ((PartRedwireFace) p).getRedwireType(ForgeDirection.UNKNOWN);
                        boolean bundled = false;
                        boolean can = true;
                        if (centerY < 2)
                            if (getItemAt(inv, centerX, centerY + 1) != null)
                                can = false;
                        if (centerX > 0)
                            if (getItemAt(inv, centerX - 1, centerY) != null)
                                can = false;
                        if (can)
                            return GateNullCell.getStackWithData(new GateNullCell(gnc.getTypeA(), gnc.isBundledA(), t, bundled));
                    }
                }
            }
            // Wire below
            if (centerY < 2 && gnc.getTypeA() == null) {
                ItemStack wire = getItemAt(inv, centerX, centerY + 1);
                if (wire != null && wire.getItem() instanceof ItemPart) {
                    IPart p = ((ItemPart) wire.getItem()).createPart(wire, BluePower.proxy.getPlayer(), null, null);
                    if (p != null && p instanceof PartRedwireFaceUninsulated) {
                        RedwireType t = ((PartRedwireFace) p).getRedwireType(ForgeDirection.UNKNOWN);
                        boolean bundled = false;
                        boolean can = true;
                        if (centerY > 0)
                            if (getItemAt(inv, centerX, centerY - 1) != null)
                                can = false;
                        if (centerX > 0)
                            if (getItemAt(inv, centerX - 1, centerY) != null)
                                can = false;
                        if (can)
                            return GateNullCell.getStackWithData(new GateNullCell(t, bundled, gnc.getTypeB(), gnc.isBundledB()));
                    }
                }
            }
            // Wire below
            if (centerY == 1 && gnc.getTypeA() == null && gnc.getTypeB() == null) {
                ItemStack wireA = getItemAt(inv, centerX, centerY + 1);
                ItemStack wireB = getItemAt(inv, centerX, centerY - 1);
                if (wireA != null && wireA.getItem() instanceof ItemPart && wireB != null && wireB.getItem() instanceof ItemPart) {
                    IPart pA = ((ItemPart) wireA.getItem()).createPart(wireA, BluePower.proxy.getPlayer(), null, null);
                    IPart pB = ((ItemPart) wireB.getItem()).createPart(wireB, BluePower.proxy.getPlayer(), null, null);
                    if (pA != null && pA instanceof PartRedwireFaceUninsulated && pB != null && pB instanceof PartRedwireFaceUninsulated) {
                        RedwireType tA = ((PartRedwireFace) pA).getRedwireType(ForgeDirection.UNKNOWN);
                        boolean bundledA = false;
                        RedwireType tB = ((PartRedwireFace) pB).getRedwireType(ForgeDirection.UNKNOWN);
                        boolean bundledB = false;
                        boolean can = true;
                        if (centerX > 0)
                            if (getItemAt(inv, centerX - 1, centerY) != null)
                                can = false;
                        if (can)
                            return GateNullCell.getStackWithData(new GateNullCell(tA, bundledA, tB, bundledB));
                    }
                }
            }
        }
    }
    return null;
}
Also used : RedwireType(com.bluepowermod.api.wire.redstone.RedwireType) GateNullCell(com.bluepowermod.part.gate.supported.GateNullCell) ItemPart(com.bluepowermod.item.ItemPart) IScrewdriver(com.bluepowermod.api.misc.IScrewdriver) IPart(uk.co.qmunity.lib.part.IPart) PartRedwireFace(com.bluepowermod.part.wire.redstone.PartRedwireFace) ItemStack(net.minecraft.item.ItemStack) ItemScrewdriver(com.bluepowermod.item.ItemScrewdriver) PartRedwireFaceUninsulated(com.bluepowermod.part.wire.redstone.PartRedwireFace.PartRedwireFaceUninsulated)

Aggregations

ItemPart (com.bluepowermod.item.ItemPart)6 IScrewdriver (com.bluepowermod.api.misc.IScrewdriver)4 PartRedwireFaceUninsulated (com.bluepowermod.part.wire.redstone.PartRedwireFace.PartRedwireFaceUninsulated)4 IPart (uk.co.qmunity.lib.part.IPart)4 PartRedwireFace (com.bluepowermod.part.wire.redstone.PartRedwireFace)3 RedwireType (com.bluepowermod.api.wire.redstone.RedwireType)2 GateNullCell (com.bluepowermod.part.gate.supported.GateNullCell)2 ItemStack (net.minecraft.item.ItemStack)2 Vec3d (uk.co.qmunity.lib.vec.Vec3d)2 Vec3dCube (uk.co.qmunity.lib.vec.Vec3dCube)2 IIntegratedCircuitPart (com.bluepowermod.api.gate.IIntegratedCircuitPart)1 TubeColor (com.bluepowermod.api.tube.IPneumaticTube.TubeColor)1 ItemScrewdriver (com.bluepowermod.item.ItemScrewdriver)1 BPPart (com.bluepowermod.part.BPPart)1 IIcon (net.minecraft.util.IIcon)1 Vec3 (net.minecraft.util.Vec3)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1 RenderHelper (uk.co.qmunity.lib.client.render.RenderHelper)1 Rotation (uk.co.qmunity.lib.transform.Rotation)1 Vec2d (uk.co.qmunity.lib.vec.Vec2d)1