Search in sources :

Example 1 with ItemPart

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

the class NullCellHandler method loadCraftingRecipes.

@Override
public void loadCraftingRecipes(ItemStack result) {
    if (result == null || !(result.getItem() instanceof ItemPart))
        return;
    try {
        for (int i = 0; i < 4; i++) {
            GateNullCell base = new GateNullCell(null, false, null, false);
            for (int j = 0; j < (i == 0 || i == 3 ? 1 : RedwireType.values().length); j++) {
                if (i == 1 || i == 2)
                    base = new GateNullCell(i == 1 ? RedwireType.values()[j] : null, false, i == 2 ? RedwireType.values()[j] : null, false);
                if (i < 3) {
                    for (RedwireType t1 : RedwireType.values()) {
                        for (RedwireType t2 : RedwireType.values()) {
                            NullCellRecipe r = new NullCellRecipe(base, t1, false, t2, false);
                            if (r.getResult() != null && ((ItemPart) r.getResult().item.getItem()).createPart(r.getResult().item, BluePower.proxy.getPlayer(), null, null).equals(((ItemPart) result.getItem()).createPart(result, BluePower.proxy.getPlayer(), null, null)))
                                arecipes.add(r);
                        }
                        NullCellRecipe r = new NullCellRecipe(base, t1, false, null, false);
                        if (r.getResult() != null && ((ItemPart) r.getResult().item.getItem()).createPart(r.getResult().item, BluePower.proxy.getPlayer(), null, null).equals(((ItemPart) result.getItem()).createPart(result, BluePower.proxy.getPlayer(), null, null)))
                            arecipes.add(r);
                        r = new NullCellRecipe(base, null, false, t1, false);
                        if (r.getResult() != null && ((ItemPart) r.getResult().item.getItem()).createPart(r.getResult().item, BluePower.proxy.getPlayer(), null, null).equals(((ItemPart) result.getItem()).createPart(result, BluePower.proxy.getPlayer(), null, null)))
                            arecipes.add(r);
                    }
                } else {
                    for (RedwireType t1 : RedwireType.values()) {
                        for (RedwireType t2 : RedwireType.values()) {
                            base = new GateNullCell(t1, false, t2, false);
                            NullCellRecipe r = new NullCellRecipe(base, true, false);
                            if (r.getResult() != null && new GateNullCell(null, false, base.getTypeB(), base.isBundledB()).equals(((ItemPart) result.getItem()).createPart(result, BluePower.proxy.getPlayer(), null, null)))
                                arecipes.add(r);
                            r = new NullCellRecipe(base, true, true);
                            if (r.getResult() != null && new GateNullCell(null, false, null, false).equals(((ItemPart) result.getItem()).createPart(result, BluePower.proxy.getPlayer(), null, null)))
                                arecipes.add(r);
                            r = new NullCellRecipe(base, false, true);
                            if (r.getResult() != null && new GateNullCell(base.getTypeB(), base.isBundledB(), null, false).equals(((ItemPart) result.getItem()).createPart(result, BluePower.proxy.getPlayer(), null, null)))
                                arecipes.add(r);
                        }
                        base = new GateNullCell(t1, false, null, false);
                        NullCellRecipe r = new NullCellRecipe(base, true, false);
                        if (r.getResult() != null && new GateNullCell(null, false, base.getTypeB(), base.isBundledB()).equals(((ItemPart) result.getItem()).createPart(result, BluePower.proxy.getPlayer(), null, null)))
                            arecipes.add(r);
                        r = new NullCellRecipe(base, true, true);
                        if (r.getResult() != null && new GateNullCell(null, false, null, false).equals(((ItemPart) result.getItem()).createPart(result, BluePower.proxy.getPlayer(), null, null)))
                            arecipes.add(r);
                        r = new NullCellRecipe(base, false, true);
                        if (r.getResult() != null && new GateNullCell(base.getTypeB(), base.isBundledB(), null, false).equals(((ItemPart) result.getItem()).createPart(result, BluePower.proxy.getPlayer(), null, null)))
                            arecipes.add(r);
                        base = new GateNullCell(null, false, t1, false);
                        r = new NullCellRecipe(base, true, false);
                        if (r.getResult() != null && new GateNullCell(null, false, base.getTypeB(), base.isBundledB()).equals(((ItemPart) result.getItem()).createPart(result, BluePower.proxy.getPlayer(), null, null)))
                            arecipes.add(r);
                        r = new NullCellRecipe(base, true, true);
                        if (r.getResult() != null && new GateNullCell(null, false, null, false).equals(((ItemPart) result.getItem()).createPart(result, BluePower.proxy.getPlayer(), null, null)))
                            arecipes.add(r);
                        r = new NullCellRecipe(base, false, true);
                        if (r.getResult() != null && new GateNullCell(base.getTypeB(), base.isBundledB(), null, false).equals(((ItemPart) result.getItem()).createPart(result, BluePower.proxy.getPlayer(), null, null)))
                            arecipes.add(r);
                    }
                    NullCellRecipe r = new NullCellRecipe(base, true, false);
                    if (r.getResult() != null && new GateNullCell(null, false, base.getTypeB(), base.isBundledB()).equals(((ItemPart) result.getItem()).createPart(result, BluePower.proxy.getPlayer(), null, null)))
                        arecipes.add(r);
                    r = new NullCellRecipe(base, true, true);
                    if (r.getResult() != null && new GateNullCell(null, false, null, false).equals(((ItemPart) result.getItem()).createPart(result, BluePower.proxy.getPlayer(), null, null)))
                        arecipes.add(r);
                    r = new NullCellRecipe(base, false, true);
                    if (r.getResult() != null && new GateNullCell(base.getTypeB(), base.isBundledB(), null, false).equals(((ItemPart) result.getItem()).createPart(result, BluePower.proxy.getPlayer(), null, null)))
                        arecipes.add(r);
                }
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : RedwireType(com.bluepowermod.api.wire.redstone.RedwireType) ItemPart(com.bluepowermod.item.ItemPart) GateNullCell(com.bluepowermod.part.gate.supported.GateNullCell)

Example 2 with ItemPart

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

the class GateNullCell method drawHighlight.

@Override
public boolean drawHighlight(QMovingObjectPosition mop, EntityPlayer player, float frame) {
    Vec3d hit = new Vec3d(mop.hitVec).sub(mop.blockX, mop.blockY, mop.blockZ).rotateUndo(getFace(), Vec3d.center);
    Vec3 pos = player.getPosition(frame);
    ItemStack held = player.getCurrentEquippedItem();
    if (held == null)
        return false;
    if (held.getItem() instanceof ItemPart) {
        IPart part = ((ItemPart) held.getItem()).createPart(held, player, null, null);
        if (part == null)
            return false;
        if (!(part instanceof PartRedwireFaceUninsulated))
            return false;
        PartRedwireFace wire = (PartRedwireFace) part;
        RenderHelper renderer = RenderHelper.instance;
        renderer.fullReset();
        renderer.setRenderCoords(getWorld(), getX(), getY(), getZ());
        double height = 2 / 16D;
        IIcon wireIcon = IconSupplier.wire;
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture);
        Tessellator.instance.startDrawingQuads();
        Tessellator.instance.addTranslation((float) -pos.xCoord, (float) -pos.yCoord, (float) -pos.zCoord);
        {
            switch(getFace()) {
                case DOWN:
                    break;
                case UP:
                    renderer.addTransformation(new Rotation(180, 180, 0, Vec3d.center));
                    break;
                case NORTH:
                    renderer.addTransformation(new Rotation(90, 0, 0, Vec3d.center));
                    break;
                case SOUTH:
                    renderer.addTransformation(new Rotation(-90, 0, 0, Vec3d.center));
                    break;
                case WEST:
                    renderer.addTransformation(new Rotation(0, 0, -90, Vec3d.center));
                    break;
                case EAST:
                    renderer.addTransformation(new Rotation(0, 0, 90, Vec3d.center));
                    break;
                default:
                    break;
            }
            int rotation = getRotation();
            if (rotation != -1)
                renderer.addTransformation(new Rotation(0, 90 * -rotation, 0));
            renderer.setOpacity(0.5);
            renderer.setColor(WireHelper.getColorForPowerLevel(wire.getRedwireType(ForgeDirection.UNKNOWN), (byte) (255 / 2)));
            ForgeDirection dir = ForgeDirection.NORTH;
            if (getRotation() % 2 == 1)
                dir = dir.getRotation(getFace());
            if (hit.getY() > 2 / 16D) {
                if (typeB == null) {
                    renderer.renderBox(new Vec3dCube(0 / 16D, 2 / 16D, 7 / 16D, 2 / 16D, 10 / 16D, 9 / 16D), wireIcon);
                    renderer.renderBox(new Vec3dCube(14 / 16D, 2 / 16D, 7 / 16D, 16 / 16D, 10 / 16D, 9 / 16D), wireIcon);
                    renderer.renderBox(new Vec3dCube(0 / 16D, 10 / 16D, 7 / 16D, 16 / 16D, 12 / 16D, 9 / 16D), wireIcon);
                }
            } else {
                if (typeA == null)
                    renderer.renderBox(new Vec3dCube(7 / 16D, 2 / 16D, 0 / 16D, 9 / 16D, 2 / 16D + height, 16 / 16D), wireIcon);
            }
            renderer.fullReset();
        }
        Tessellator.instance.addTranslation((float) pos.xCoord, (float) pos.yCoord, (float) pos.zCoord);
        Tessellator.instance.draw();
        GL11.glDisable(GL11.GL_BLEND);
        return true;
    } else if (held.getItem() instanceof IScrewdriver) {
    // List<Vec3dCube> l = new ArrayList<Vec3dCube>();
    // super.addBoxes(l);
    // boolean def = false;
    // for (Vec3dCube c : l)
    // if (mop.getCube().equals(c.clone().rotate(getFace(), Vec3d.center).rotate(0, 90 * -getRotation(), 0, Vec3d.center)))
    // def = true;
    // if (def || hit.getY() <= 2 / 16D) {
    // Vec3dCube c = Vec3dCube.merge(getSelectionBoxes()).expand(0.001);
    //
    // GL11.glEnable(GL11.GL_BLEND);
    // GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    // GL11.glDisable(GL11.GL_TEXTURE_2D);
    // GL11.glColor4f(0, 0, 0, 0.4F);
    // GL11.glLineWidth(2);
    // GL11.glDepthMask(true);
    // GL11.glPushMatrix();
    //
    // Tessellator var2 = Tessellator.instance;
    // var2.startDrawing(3);
    // Tessellator.instance.addTranslation((float) -pos.xCoord + getX(), (float) -pos.yCoord + getY(), (float) -pos.zCoord
    // + getZ());
    // var2.addVertex(c.getMinX(), c.getMinY(), c.getMinZ());
    // var2.addVertex(c.getMaxX(), c.getMinY(), c.getMinZ());
    // var2.addVertex(c.getMaxX(), c.getMinY(), c.getMaxZ());
    // var2.addVertex(c.getMinX(), c.getMinY(), c.getMaxZ());
    // var2.addVertex(c.getMinX(), c.getMinY(), c.getMinZ());
    // var2.draw();
    // var2.startDrawing(3);
    // var2.addVertex(c.getMinX(), c.getMaxY(), c.getMinZ());
    // var2.addVertex(c.getMaxX(), c.getMaxY(), c.getMinZ());
    // var2.addVertex(c.getMaxX(), c.getMaxY(), c.getMaxZ());
    // var2.addVertex(c.getMinX(), c.getMaxY(), c.getMaxZ());
    // var2.addVertex(c.getMinX(), c.getMaxY(), c.getMinZ());
    // var2.draw();
    // var2.startDrawing(1);
    // var2.addVertex(c.getMinX(), c.getMinY(), c.getMinZ());
    // var2.addVertex(c.getMinX(), c.getMaxY(), c.getMinZ());
    // var2.addVertex(c.getMaxX(), c.getMinY(), c.getMinZ());
    // var2.addVertex(c.getMaxX(), c.getMaxY(), c.getMinZ());
    // var2.addVertex(c.getMaxX(), c.getMinY(), c.getMaxZ());
    // var2.addVertex(c.getMaxX(), c.getMaxY(), c.getMaxZ());
    // var2.addVertex(c.getMinX(), c.getMinY(), c.getMaxZ());
    // var2.addVertex(c.getMinX(), c.getMaxY(), c.getMaxZ());
    // Tessellator.instance.addTranslation((float) pos.xCoord - getX(), (float) pos.yCoord - getY(), (float) pos.zCoord - getZ());
    // var2.draw();
    //
    // GL11.glPopMatrix();
    // GL11.glDepthMask(false);
    // GL11.glEnable(GL11.GL_TEXTURE_2D);
    // GL11.glDisable(GL11.GL_BLEND);
    //
    // return true;
    // }
    //
    // return true;
    }
    return false;
}
Also used : ItemPart(com.bluepowermod.item.ItemPart) RenderHelper(uk.co.qmunity.lib.client.render.RenderHelper) IIcon(net.minecraft.util.IIcon) Rotation(uk.co.qmunity.lib.transform.Rotation) Vec3d(uk.co.qmunity.lib.vec.Vec3d) PartRedwireFaceUninsulated(com.bluepowermod.part.wire.redstone.PartRedwireFace.PartRedwireFaceUninsulated) IScrewdriver(com.bluepowermod.api.misc.IScrewdriver) IPart(uk.co.qmunity.lib.part.IPart) Vec3(net.minecraft.util.Vec3) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) PartRedwireFace(com.bluepowermod.part.wire.redstone.PartRedwireFace) ItemStack(net.minecraft.item.ItemStack) Vec3dCube(uk.co.qmunity.lib.vec.Vec3dCube)

Example 3 with ItemPart

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

the class PneumaticTube method onActivated.

/**
     * Event called when the part is activated (right clicked)
     *
     * @param player
     *            Player that right clicked the part
     * @param item
     *            Item that was used to click it
     * @return Whether or not an action occurred
     */
@Override
public boolean onActivated(EntityPlayer player, QMovingObjectPosition mop, ItemStack item) {
    if (getWorld() == null)
        return false;
    if (item != null) {
        TubeColor newColor = null;
        if (item.getItem() == BPItems.paint_brush && ((ItemDamageableColorableOverlay) BPItems.paint_brush).tryUseItem(item)) {
            newColor = TubeColor.values()[item.getItemDamage()];
        } else if (item.getItem() == Items.water_bucket || (item.getItem() == BPItems.paint_brush && item.getItemDamage() == 16)) {
            newColor = TubeColor.NONE;
        }
        if (newColor != null) {
            if (!getWorld().isRemote) {
                List<Vec3dCube> boxes = getTubeBoxes();
                Vec3dCube box = mop.getCube();
                int face = -1;
                if (box.equals(boxes.get(0))) {
                    face = mop.sideHit;
                } else {
                    face = getSideFromAABBIndex(boxes.indexOf(box));
                }
                color[face] = newColor;
                updateConnections();
                getLogic().clearNodeCaches();
                notifyUpdate();
            }
            return true;
        }
        if (item.getItem() instanceof ItemPart) {
            BPPart part = PartManager.getExample(item);
            if (redwireType == null && part instanceof PartRedwireFaceUninsulated) {
                if (!getWorld().isRemote) {
                    redwireType = ((IRedwire) part).getRedwireType(ForgeDirection.UNKNOWN);
                    if (!player.capabilities.isCreativeMode)
                        item.stackSize--;
                    // Redstone update
                    getRedstoneConnectionCache().recalculateConnections();
                    RedstoneApi.getInstance().getRedstonePropagator(this, ForgeDirection.DOWN).propagate();
                    updateConnections();
                    getLogic().clearNodeCaches();
                    notifyUpdate();
                    sendUpdatePacket();
                }
                return true;
            }
        }
        // Removing redwire
        if (redwireType != null && item.getItem() instanceof IScrewdriver && player.isSneaking()) {
            if (!getWorld().isRemote) {
                IOHelper.spawnItemInWorld(getWorld(), PartManager.getPartInfo("wire." + redwireType.getName()).getStack(), getX() + 0.5, getY() + 0.5, getZ() + 0.5);
                redwireType = null;
                // Redstone update
                getRedstoneConnectionCache().recalculateConnections();
                RedstoneApi.getInstance().getRedstonePropagator(this, ForgeDirection.DOWN).propagate();
                ((IScrewdriver) item.getItem()).damage(item, 1, player, false);
                updateConnections();
                getLogic().clearNodeCaches();
                notifyUpdate();
                sendUpdatePacket();
            }
            return true;
        }
    }
    return false;
}
Also used : TubeColor(com.bluepowermod.api.tube.IPneumaticTube.TubeColor) ItemPart(com.bluepowermod.item.ItemPart) IScrewdriver(com.bluepowermod.api.misc.IScrewdriver) BPPart(com.bluepowermod.part.BPPart) Vec3dCube(uk.co.qmunity.lib.vec.Vec3dCube) PartRedwireFaceUninsulated(com.bluepowermod.part.wire.redstone.PartRedwireFace.PartRedwireFaceUninsulated)

Example 4 with ItemPart

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

the class GateIntegratedCircuit method onActivated.

@Override
public boolean onActivated(final EntityPlayer player, QMovingObjectPosition hit, ItemStack item) {
    Vec2d v = new Vec2d(hit.hitVec.xCoord - hit.blockX, hit.hitVec.zCoord - hit.blockZ).sub(0.5, 0.5).rotate(90 * -getRotation()).add(0.5, 0.5);
    int x = (int) (v.getX() * getSize());
    int z = (int) (v.getY() * getSize());
    if (getPart(x, z) == null && item != null && item.getItem() instanceof ItemPart) {
        IPart part = ((ItemPart) item.getItem()).createPart(item, player, getWorld(), hit);
        if (part instanceof IIntegratedCircuitPart) {
            if (!getWorld().isRemote) {
                setPart(x, z, (IIntegratedCircuitPart) part);
                sendUpdatePacket(part, -1);
            }
            return true;
        }
    }
    return super.onActivated(player, hit, item);
}
Also used : ItemPart(com.bluepowermod.item.ItemPart) IPart(uk.co.qmunity.lib.part.IPart) IIntegratedCircuitPart(com.bluepowermod.api.gate.IIntegratedCircuitPart) Vec2d(uk.co.qmunity.lib.vec.Vec2d)

Example 5 with ItemPart

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

the class GateNullCell method onActivated.

// In-world customization
@Override
public boolean onActivated(EntityPlayer player, QMovingObjectPosition mop, ItemStack item) {
    Vec3d hit = new Vec3d(mop.hitVec).sub(mop.blockX, mop.blockY, mop.blockZ).rotateUndo(getFace(), Vec3d.center);
    if (item != null) {
        if (item.getItem() instanceof ItemPart) {
            IPart part = ((ItemPart) item.getItem()).createPart(item, player, null, null);
            if (part != null && part instanceof PartRedwireFaceUninsulated) {
                PartRedwireFace wire = (PartRedwireFace) part;
                if (hit.getY() > 2 / 16D) {
                    if (typeB == null) {
                        if (getWorld().isRemote)
                            return true;
                        typeB = wire.getRedwireType(ForgeDirection.UNKNOWN);
                        bundledB = false;
                        inWorldB = true;
                        getRedstoneConnectionCache().recalculateConnections();
                        sendUpdatePacket();
                        if (!player.capabilities.isCreativeMode)
                            item.stackSize--;
                        return true;
                    }
                } else {
                    if (typeA == null) {
                        if (getWorld().isRemote)
                            return true;
                        typeA = wire.getRedwireType(ForgeDirection.UNKNOWN);
                        bundledA = false;
                        inWorldA = true;
                        getRedstoneConnectionCache().recalculateConnections();
                        sendUpdatePacket();
                        if (!player.capabilities.isCreativeMode)
                            item.stackSize--;
                        return true;
                    }
                }
            }
        } else if (item.getItem() instanceof IScrewdriver && player.isSneaking()) {
            if (hit.getY() > 2 / 16D && ((hit.getY() <= 4 / 16D && hit.getX() > 0.5 - 1 / 16D && hit.getX() > 0.5 + 1 / 16D) || hit.getY() > 4 / 16D)) {
                if (typeB != null) {
                    if (getWorld().isRemote)
                        return true;
                    IOHelper.spawnItemInWorld(getWorld(), typeB.getPartInfo(MinecraftColor.NONE, bundledB).getStack(), getX() + 0.5, getY() + 0.5, getZ() + 0.5);
                    typeB = null;
                    bundledB = false;
                    inWorldB = false;
                    ((IScrewdriver) item.getItem()).damage(item, 1, player, false);
                    getRedstoneConnectionCache().recalculateConnections();
                    sendUpdatePacket();
                    return true;
                }
            } else if (hit.getY() > 2 / 16D) {
                if (typeA != null) {
                    if (getWorld().isRemote)
                        return true;
                    IOHelper.spawnItemInWorld(getWorld(), typeA.getPartInfo(MinecraftColor.NONE, bundledA).getStack(), getX() + 0.5, getY() + 0.5, getZ() + 0.5);
                    typeA = null;
                    bundledA = false;
                    inWorldA = false;
                    ((IScrewdriver) item.getItem()).damage(item, 1, player, false);
                    getRedstoneConnectionCache().recalculateConnections();
                    sendUpdatePacket();
                    return true;
                }
            }
        }
    }
    return super.onActivated(player, mop, item);
}
Also used : 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) Vec3d(uk.co.qmunity.lib.vec.Vec3d) 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