Search in sources :

Example 1 with TubeColor

use of com.bluepowermod.api.tube.IPneumaticTube.TubeColor 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 2 with TubeColor

use of com.bluepowermod.api.tube.IPneumaticTube.TubeColor in project BluePower by Qmunity.

the class PneumaticTube method renderStatic.

@Override
@SideOnly(Side.CLIENT)
public boolean renderStatic(Vec3i loc, RenderHelper renderer, RenderBlocks renderBlocks, int pass) {
    boolean down = shouldRenderConnection(ForgeDirection.DOWN);
    boolean up = shouldRenderConnection(ForgeDirection.UP);
    boolean north = shouldRenderConnection(ForgeDirection.NORTH);
    boolean south = shouldRenderConnection(ForgeDirection.SOUTH);
    boolean west = shouldRenderConnection(ForgeDirection.WEST);
    boolean east = shouldRenderConnection(ForgeDirection.EAST);
    boolean renderFully = shouldRenderFully();
    if (this instanceof RestrictionTube) {
        IIcon icon = IconSupplier.restrictionTubeSide;
        renderer.renderBox(new Vec3dCube(0.25, 0.25, 0.25, 0.75, 0.75, 0.75), icon);
    }
    double addedThickness = getAddedThickness();
    double wireSize = getSize() / 16D;
    double frameSeparation = 6 / 16D - addedThickness - addedThickness - 0.001;
    double frameThickness = 1 / 16D + addedThickness;
    if (pass == 0) {
        if (this instanceof RestrictionTube) {
            IIcon icon = IconSupplier.restrictionTubeSide;
            renderer.renderBox(new Vec3dCube(0.25, 0.25, 0.25, 0.75, 0.75, 0.75), icon);
        }
        if (renderFully) {
            renderer.setColor(getColorMultiplier());
            renderFrame(renderer, wireSize, frameSeparation, frameThickness, true, true, true, true, true, true, down, up, west, east, north, south, true, getFrameIcon(), getFrameColorMultiplier());
            renderer.setColor(0xFFFFFF);
        } else {
            boolean isInWorld = getParent() != null;
            renderer.setColor(getFrameColorMultiplier());
            // Frame
            renderFrame(renderer, wireSize, frameSeparation, frameThickness, down, up, west, east, north, south, isInWorld, getFrameIcon(), getFrameColorMultiplier());
        }
        // Tube coloring
        {
            Vec3dCube side = new Vec3dCube(0.25 + 5 / 128D, 0, 0.25 - addedThickness, 0.25 + 9 / 128D + addedThickness, 0.25, 0.25 + 2 / 128D);
            Vec3dCube side2 = new Vec3dCube(0.25 - addedThickness, 0, 0.25 + 5 / 128D, 0.25 + 2 / 128D, 0.25, 0.25 + 9 / 128D + addedThickness);
            Vec3dCube side3 = new Vec3dCube(0.25 - addedThickness, 0.25 - addedThickness, 0.25 + 5 / 128D, 0.25 + 2 / 128D, 0.25 + 4 / 128D, 0.25 + 59 / 128D);
            Vec3dCube side4 = new Vec3dCube(0.25 + 5 / 128D, 0.25 - addedThickness, 0.25 + 5 / 128D, 0.25 + 9 / 128D + addedThickness, 0.25 + 2 / 128D, 0.25 + 56 / 128D);
            Vec3dCube side5 = new Vec3dCube(0.25 + 5 / 128D, 0.25 - addedThickness, 0.25 - 1 / 128D, 0.25 + 9 / 128D + addedThickness, 0.25 + 2 / 128D, 0.25 + 65 / 128D);
            for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                TubeColor c = color[d.ordinal()];
                if (c != TubeColor.NONE) {
                    try {
                        renderer.setColor(MinecraftColor.values()[15 - c.ordinal()].getHex());
                        if (connections[d.ordinal()]) {
                            for (int i = 0; i < 4; i++) {
                                renderer.renderBox(side.clone().rotate(0, i * 90, 0, Vec3d.center).rotate(d, Vec3d.center), IconSupplier.pneumaticTubeColoring);
                                renderer.renderBox(side2.clone().rotate(0, i * 90, 0, Vec3d.center).rotate(d, Vec3d.center), IconSupplier.pneumaticTubeColoring);
                                if (renderFully)
                                    renderer.renderBox(side3.clone().rotate(0, i * 90, 0, Vec3d.center).rotate(d, Vec3d.center), IconSupplier.pneumaticTubeColoring);
                            }
                        } else if (renderFully) {
                            for (int i = 0; i < 4; i++) renderer.renderBox(side4.clone().rotate(0, i * 90, 0, Vec3d.center).rotate(d, Vec3d.center), IconSupplier.pneumaticTubeColoring);
                        } else {
                            for (int i = 1; i < 4; i += 2) renderer.renderBox(side5.clone().rotate(0, (i + ((shouldRenderConnection(ForgeDirection.NORTH) || (shouldRenderConnection(ForgeDirection.UP) && (d == ForgeDirection.NORTH || d == ForgeDirection.SOUTH))) ? 1 : 0)) * 90, 0, Vec3d.center).rotate(d, Vec3d.center), IconSupplier.pneumaticTubeColoring);
                        }
                        renderer.setColor(0xFFFFFF);
                    } catch (Exception ex) {
                        System.out.println("Err on side " + d + ". Color: " + c);
                    }
                }
            }
        }
        if (redwireType != null) {
            frameThickness /= 1.5;
            frameSeparation -= 1 / 32D;
            renderFrame(renderer, wireSize, frameSeparation, frameThickness, renderFully || shouldRenderConnection(ForgeDirection.DOWN), renderFully || shouldRenderConnection(ForgeDirection.UP), renderFully || shouldRenderConnection(ForgeDirection.WEST), renderFully || shouldRenderConnection(ForgeDirection.EAST), renderFully || shouldRenderConnection(ForgeDirection.NORTH), renderFully || shouldRenderConnection(ForgeDirection.SOUTH), redstoneConnections[ForgeDirection.DOWN.ordinal()], redstoneConnections[ForgeDirection.UP.ordinal()], redstoneConnections[ForgeDirection.WEST.ordinal()], redstoneConnections[ForgeDirection.EAST.ordinal()], redstoneConnections[ForgeDirection.NORTH.ordinal()], redstoneConnections[ForgeDirection.SOUTH.ordinal()], getParent() != null && getWorld() != null, IconSupplier.wire, WireHelper.getColorForPowerLevel(redwireType, getPower()));
            Vec3dCube c = new Vec3dCube(0.5 - 1 / 56D, 0, 0.2, 0.5 + 1 / 56D, 1 / 32D, 0.8);
            renderer.setColor(WireHelper.getColorForPowerLevel(redwireType, getPower()));
            for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                if (redstoneConnections[d.ordinal()] && !connections[d.ordinal()]) {
                    renderer.addTransformation(new Rotation(d));
                    for (int i = 0; i < 2; i++) {
                        renderer.addTransformation(new Rotation(0, 45 + 90 * i, 0));
                        renderer.renderBox(c.clone(), IconSupplier.wire);
                        renderer.removeTransformation();
                    }
                    renderer.removeTransformation();
                }
            }
            renderer.setColor(0xFFFFFF);
        }
    } else {
        IIcon glass = this instanceof MagTube ? IconSupplier.magTubeGlass : IconSupplier.pneumaticTubeGlass;
        IIcon glass2 = this instanceof MagTube ? IconSupplier.magTubeGlass2 : IconSupplier.pneumaticTubeGlass2;
        if (!(this instanceof RestrictionTube)) {
            renderer.setRenderSides(!down, !up, !west, !east, !north, !south);
            if (renderFully) {
                renderer.renderBox(new Vec3dCube(4.5 / 16D, 4.5 / 16D, 4.5 / 16D, 11.5 / 16D, 11.5 / 16D, 11.5 / 16D), glass);
            } else {
                boolean ud = west || east;
                boolean we = north || south;
                boolean ns = west || east;
                renderer.setTextureRotations(ud ? 1 : 0, ud ? 1 : 0, we ? 1 : 0, we ? 1 : 0, ns ? 1 : 0, ns ? 1 : 0);
                renderer.renderBox(new Vec3dCube(4.5 / 16D, 4.5 / 16D, 4.5 / 16D, 11.5 / 16D, 11.5 / 16D, 11.5 / 16D), glass2);
            }
            renderer.resetRenderedSides();
            renderer.resetTextureRotations();
        }
        Vec3dCube c = new Vec3dCube(4.5 / 16D, 0, 4.5 / 16D, 11.5 / 16D, 4.5 / 16D, 11.5 / 16D);
        if (renderFully) {
            boolean ud = west || east;
            boolean we = north || south;
            boolean ns = west || east;
            renderer.setTextureRotations(ud ? 1 : 0, ud ? 1 : 0, we ? 1 : 0, we ? 1 : 0, ns ? 1 : 0, ns ? 1 : 0);
            for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                if (shouldRenderConnection(d)) {
                    renderer.setRenderSide(d, false);
                    renderer.setRenderSide(d.getOpposite(), false);
                    renderer.renderBox(c.clone().rotate(d, Vec3d.center), glass);
                    renderer.resetRenderedSides();
                }
            }
        } else {
            boolean ud = west || east;
            boolean we = north || south;
            boolean ns = west || east;
            renderer.setTextureRotations(ud ? 1 : 0, ud ? 1 : 0, we ? 1 : 0, we ? 1 : 0, ns ? 1 : 0, ns ? 1 : 0);
            for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                if (shouldRenderConnection(d)) {
                    renderer.setRenderSide(d, false);
                    renderer.setRenderSide(d.getOpposite(), false);
                    renderer.renderBox(c.clone().rotate(d, Vec3d.center), glass2);
                    renderer.resetRenderedSides();
                }
            }
        }
    }
    return true;
}
Also used : TubeColor(com.bluepowermod.api.tube.IPneumaticTube.TubeColor) IIcon(net.minecraft.util.IIcon) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Rotation(uk.co.qmunity.lib.transform.Rotation) IOException(java.io.IOException) Vec3dCube(uk.co.qmunity.lib.vec.Vec3dCube) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Example 3 with TubeColor

use of com.bluepowermod.api.tube.IPneumaticTube.TubeColor in project BluePower by Qmunity.

the class PneumaticTubeOpaque method renderStatic.

@Override
@SideOnly(Side.CLIENT)
public boolean renderStatic(Vec3i loc, RenderHelper renderer, RenderBlocks renderBlocks, int pass) {
    if (pass == 0) {
        boolean renderFully = false;
        int count = 0;
        for (int i = 0; i < 6; i++) {
            if (connections[i] || redstoneConnections[i])
                count++;
            if (i % 2 == 0 && connections[i] != connections[i + 1])
                renderFully = true;
        }
        renderFully |= count > 2 || count == 0;
        IIcon icon = this instanceof RestrictionTubeOpaque ? (renderFully ? IconSupplier.restrictionTubeNodeOpaque : IconSupplier.restrictionTubeSideOpaque) : renderFully ? IconSupplier.pneumaticTubeOpaqueNode : IconSupplier.pneumaticTubeOpaqueSide;
        if (shouldRenderConnection(ForgeDirection.EAST) || shouldRenderConnection(ForgeDirection.WEST))
            renderer.setTextureRotations(1, 1, 0, 0, 1, 1);
        if (shouldRenderConnection(ForgeDirection.NORTH) || shouldRenderConnection(ForgeDirection.SOUTH))
            renderer.setTextureRotations(0, 0, 1, 1, 0, 0);
        renderer.renderBox(new Vec3dCube(0.25, 0.25, 0.25, 0.75, 0.75, 0.75), icon);
        renderer.resetTextureRotations();
        for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
            if (shouldRenderConnection(d)) {
                renderer.addTransformation(new Rotation(d));
                renderer.renderBox(new Vec3dCube(0.25, 0, 0.25, 0.75, 0.25, 0.75), IconSupplier.pneumaticTubeOpaqueNode, null, icon, icon, icon, icon);
                renderer.removeTransformation();
            }
        }
        if (getRedwireType() != null) {
            double wireSize = getSize() / 16D;
            double frameSeparation = 6 / 16D - (wireSize - 2 / 16D);
            double frameThickness = 1 / 16D;
            frameThickness /= 1.5;
            frameSeparation -= 1 / 32D;
            renderFrame(renderer, wireSize, frameSeparation, frameThickness, renderFully || shouldRenderConnection(ForgeDirection.DOWN), renderFully || shouldRenderConnection(ForgeDirection.UP), renderFully || shouldRenderConnection(ForgeDirection.WEST), renderFully || shouldRenderConnection(ForgeDirection.EAST), renderFully || shouldRenderConnection(ForgeDirection.NORTH), renderFully || shouldRenderConnection(ForgeDirection.SOUTH), redstoneConnections[ForgeDirection.DOWN.ordinal()], redstoneConnections[ForgeDirection.UP.ordinal()], redstoneConnections[ForgeDirection.WEST.ordinal()], redstoneConnections[ForgeDirection.EAST.ordinal()], redstoneConnections[ForgeDirection.NORTH.ordinal()], redstoneConnections[ForgeDirection.SOUTH.ordinal()], getParent() != null && getWorld() != null, IconSupplier.wire, WireHelper.getColorForPowerLevel(getRedwireType(), getPower()));
        }
        // Tube coloring
        {
            Vec3dCube side = new Vec3dCube(0.25 + 5 / 128D, 0, 0.25 - 1 / 128D, 0.25 + 9 / 128D, 0.25, 0.25 + 2 / 128D);
            Vec3dCube side2 = new Vec3dCube(0.25 - 1 / 128D, 0, 0.25 + 5 / 128D, 0.25 + 2 / 128D, 0.25, 0.25 + 9 / 128D);
            Vec3dCube side3 = new Vec3dCube(0.25 - 1 / 128D, 0.25 - 1 / 128D, 0.25 + 5 / 128D, 0.25 + 2 / 128D, 0.25 + 2 / 128D, 0.25 + 59 / 128D);
            Vec3dCube side4 = new Vec3dCube(0.25 + 5 / 128D, 0.25 - 1 / 128D, 0.25 + 5 / 128D, 0.25 + 9 / 128D, 0.25 + 2 / 128D, 0.25 + 56 / 128D);
            Vec3dCube side5 = new Vec3dCube(0.25 + 5 / 128D, 0.25 - 1 / 128D, 0.25 - 1 / 128D, 0.25 + 9 / 128D, 0.25 + 2 / 128D, 0.25 + 65 / 128D);
            for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                TubeColor c = color[d.ordinal()];
                if (c != TubeColor.NONE) {
                    try {
                        renderer.setColor(MinecraftColor.values()[15 - c.ordinal()].getHex());
                        if (connections[d.ordinal()]) {
                            for (int i = 0; i < 4; i++) {
                                renderer.renderBox(side.clone().rotate(0, i * 90, 0, Vec3d.center).rotate(d, Vec3d.center), IconSupplier.pneumaticTubeColoring);
                                renderer.renderBox(side2.clone().rotate(0, i * 90, 0, Vec3d.center).rotate(d, Vec3d.center), IconSupplier.pneumaticTubeColoring);
                                if (renderFully)
                                    renderer.renderBox(side3.clone().rotate(0, i * 90, 0, Vec3d.center).rotate(d, Vec3d.center), IconSupplier.pneumaticTubeColoring);
                            }
                        } else if (renderFully) {
                            for (int i = 0; i < 4; i++) renderer.renderBox(side4.clone().rotate(0, i * 90, 0, Vec3d.center).rotate(d, Vec3d.center), IconSupplier.pneumaticTubeColoring);
                        } else {
                            for (int i = 1; i < 4; i += 2) renderer.renderBox(side5.clone().rotate(0, (i + ((shouldRenderConnection(ForgeDirection.NORTH) || (shouldRenderConnection(ForgeDirection.UP) && (d == ForgeDirection.NORTH || d == ForgeDirection.SOUTH))) ? 1 : 0)) * 90, 0, Vec3d.center).rotate(d, Vec3d.center), IconSupplier.pneumaticTubeColoring);
                        }
                        renderer.setColor(0xFFFFFF);
                    } catch (Exception ex) {
                        System.out.println("Err on side " + d + ". Color: " + c);
                    }
                }
            }
        }
    }
    return true;
}
Also used : TubeColor(com.bluepowermod.api.tube.IPneumaticTube.TubeColor) IIcon(net.minecraft.util.IIcon) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Rotation(uk.co.qmunity.lib.transform.Rotation) Vec3dCube(uk.co.qmunity.lib.vec.Vec3dCube) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Aggregations

TubeColor (com.bluepowermod.api.tube.IPneumaticTube.TubeColor)3 Vec3dCube (uk.co.qmunity.lib.vec.Vec3dCube)3 SideOnly (cpw.mods.fml.relauncher.SideOnly)2 IIcon (net.minecraft.util.IIcon)2 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)2 Rotation (uk.co.qmunity.lib.transform.Rotation)2 IScrewdriver (com.bluepowermod.api.misc.IScrewdriver)1 ItemPart (com.bluepowermod.item.ItemPart)1 BPPart (com.bluepowermod.part.BPPart)1 PartRedwireFaceUninsulated (com.bluepowermod.part.wire.redstone.PartRedwireFace.PartRedwireFaceUninsulated)1 IOException (java.io.IOException)1