Search in sources :

Example 6 with EnumWirePart

use of buildcraft.api.transport.EnumWirePart in project BuildCraft by BuildCraft.

the class PipeWireRenderer method renderWires.

public static void renderWires(TilePipeHolder pipe, double x, double y, double z, BufferBuilder bb) {
    int combinedLight = pipe.getWorld().getCombinedLight(pipe.getPipePos(), 0);
    int skyLight = combinedLight >> 16 & 0xFFFF;
    int blockLight = combinedLight & 0xFFFF;
    RenderHelper.disableStandardItemLighting();
    GlStateManager.pushMatrix();
    GlStateManager.translate(x, y, z);
    for (Map.Entry<EnumWirePart, EnumDyeColor> partColor : pipe.getWireManager().parts.entrySet()) {
        EnumWirePart part = partColor.getKey();
        EnumDyeColor color = partColor.getValue();
        boolean isOn = pipe.wireManager.isPowered(part);
        int idx = getIndex(part, color, isOn);
        if (wireRenderingCache[idx] == -1) {
            wireRenderingCache[idx] = compileWire(part, color, isOn);
        }
        OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, isOn ? 240 : blockLight, skyLight);
        GlStateManager.callList(wireRenderingCache[idx]);
    }
    for (Map.Entry<EnumWireBetween, EnumDyeColor> betweenColor : pipe.getWireManager().betweens.entrySet()) {
        EnumWireBetween between = betweenColor.getKey();
        EnumDyeColor color = betweenColor.getValue();
        boolean isOn = pipe.wireManager.isPowered(between.parts[0]);
        int idx = getIndex(between, color, isOn);
        if (wireRenderingCache[idx] == -1) {
            wireRenderingCache[idx] = compileWire(between, color, isOn);
        }
        OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, isOn ? 240 : blockLight, skyLight);
        GlStateManager.callList(wireRenderingCache[idx]);
    }
    GlStateManager.popMatrix();
    GlStateManager.enableLighting();
    /*
         * Directly rendering (like with a gllist) changes the colour directly, so we need to change the opengl state
         * directly
         */
    GL11.glColor3f(1, 1, 1);
    GlStateManager.color(1, 1, 1, 1);
}
Also used : EnumWirePart(buildcraft.api.transport.EnumWirePart) Map(java.util.Map) EnumMap(java.util.EnumMap) EnumDyeColor(net.minecraft.item.EnumDyeColor) EnumWireBetween(buildcraft.transport.wire.EnumWireBetween)

Example 7 with EnumWirePart

use of buildcraft.api.transport.EnumWirePart in project BuildCraft by BuildCraft.

the class BlockPipeHolder method getPickBlock.

@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
    TilePipeHolder tile = getPipe(world, pos, false);
    if (tile == null || target == null) {
        return ItemStack.EMPTY;
    }
    if (target.subHit <= 6) {
        Pipe pipe = tile.getPipe();
        if (pipe != null) {
            PipeDefinition def = pipe.getDefinition();
            Item item = (Item) PipeApi.pipeRegistry.getItemForPipe(def);
            if (item != null) {
                int meta = pipe.getColour() == null ? 0 : pipe.getColour().getMetadata() + 1;
                return new ItemStack(item, 1, meta);
            }
        }
    } else if (target.subHit <= 12) {
        int pluggableHit = target.subHit - 7;
        EnumFacing face = EnumFacing.VALUES[pluggableHit];
        PipePluggable plug = tile.getPluggable(face);
        if (plug != null) {
            return plug.getPickStack();
        }
    } else {
        EnumWirePart part = null;
        EnumWireBetween between = null;
        if (target.subHit > 6) {
            part = getWirePartHit(target);
            between = getWireBetweenHit(target);
        }
        if (part != null && tile.wireManager.getColorOfPart(part) != null) {
            return new ItemStack(BCTransportItems.wire, 1, tile.wireManager.getColorOfPart(part).getMetadata());
        } else if (between != null && tile.wireManager.getColorOfPart(between.parts[0]) != null) {
            return new ItemStack(BCTransportItems.wire, 1, tile.wireManager.getColorOfPart(between.parts[0]).getMetadata());
        }
    }
    return ItemStack.EMPTY;
}
Also used : TilePipeHolder(buildcraft.transport.tile.TilePipeHolder) Item(net.minecraft.item.Item) EnumWirePart(buildcraft.api.transport.EnumWirePart) EnumFacing(net.minecraft.util.EnumFacing) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) Pipe(buildcraft.transport.pipe.Pipe) PipeDefinition(buildcraft.api.transport.pipe.PipeDefinition) ItemStack(net.minecraft.item.ItemStack) EnumWireBetween(buildcraft.transport.wire.EnumWireBetween)

Example 8 with EnumWirePart

use of buildcraft.api.transport.EnumWirePart in project BuildCraft by BuildCraft.

the class BlockPipeHolder method getSelectedBoundingBox.

@Override
@SideOnly(Side.CLIENT)
public AxisAlignedBB getSelectedBoundingBox(IBlockState state, World world, BlockPos pos) {
    TilePipeHolder tile = getPipe(world, pos, false);
    if (tile == null) {
        return FULL_BLOCK_AABB;
    }
    RayTraceResult trace = Minecraft.getMinecraft().objectMouseOver;
    if (trace == null || trace.subHit < 0 || !pos.equals(trace.getBlockPos())) {
        // Perhaps we aren't the object the mouse is over
        return FULL_BLOCK_AABB;
    }
    int part = trace.subHit;
    AxisAlignedBB aabb = FULL_BLOCK_AABB;
    if (part == 0) {
        aabb = BOX_CENTER;
    } else if (part < 1 + 6) {
        aabb = BOX_FACES[part - 1];
        Pipe pipe = tile.getPipe();
        if (pipe != null) {
            EnumFacing face = EnumFacing.VALUES[part - 1];
            float conSize = pipe.getConnectedDist(face);
            if (conSize > 0 && conSize != 0.25f) {
                Vec3d center = VecUtil.offset(new Vec3d(0.5, 0.5, 0.5), face, 0.25 + (conSize / 2));
                Vec3d radius = new Vec3d(0.25, 0.25, 0.25);
                radius = VecUtil.replaceValue(radius, face.getAxis(), conSize / 2);
                Vec3d min = center.subtract(radius);
                Vec3d max = center.add(radius);
                aabb = BoundingBoxUtil.makeFrom(min, max);
            }
        }
    } else if (part < 1 + 6 + 6) {
        EnumFacing side = EnumFacing.VALUES[part - 1 - 6];
        PipePluggable pluggable = tile.getPluggable(side);
        if (pluggable != null) {
            aabb = pluggable.getBoundingBox();
        }
    } else if (part < 1 + 6 + 6 + 8) {
        EnumWirePart wirePart = EnumWirePart.VALUES[part - 1 - 6 - 6];
        aabb = wirePart.boundingBox;
    } else if (part < 1 + 6 + 6 + 6 + 8 + 36) {
        EnumWireBetween wireBetween = EnumWireBetween.VALUES[part - 1 - 6 - 6 - 8];
        aabb = wireBetween.boundingBox;
    }
    if (part >= 1 + 6 + 6) {
        return aabb.offset(pos);
    } else {
        return (aabb == FULL_BLOCK_AABB ? aabb : aabb.grow(1 / 32.0)).offset(pos);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) TilePipeHolder(buildcraft.transport.tile.TilePipeHolder) EnumWirePart(buildcraft.api.transport.EnumWirePart) EnumFacing(net.minecraft.util.EnumFacing) RayTraceResult(net.minecraft.util.math.RayTraceResult) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) Pipe(buildcraft.transport.pipe.Pipe) Vec3d(net.minecraft.util.math.Vec3d) EnumWireBetween(buildcraft.transport.wire.EnumWireBetween) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 9 with EnumWirePart

use of buildcraft.api.transport.EnumWirePart in project BuildCraft by BuildCraft.

the class WireManager method updateBetweens.

@Override
public void updateBetweens(boolean recursive) {
    betweens.clear();
    parts.forEach((part, color) -> {
        for (EnumWireBetween between : EnumWireBetween.VALUES) {
            EnumWirePart[] betweenParts = between.parts;
            if (between.to == null) {
                if ((betweenParts[0] == part && getColorOfPart(betweenParts[1]) == color) || (betweenParts[1] == part && getColorOfPart(betweenParts[0]) == color)) {
                    betweens.put(between, color);
                }
            } else if (WireSystem.canWireConnect(holder, between.to)) {
                IPipe pipe = holder.getNeighbourPipe(between.to);
                if (pipe != null) {
                    IWireManager wireManager = pipe.getHolder().getWireManager();
                    if (betweenParts[0] == part && wireManager.getColorOfPart(betweenParts[1]) == color) {
                        betweens.put(between, color);
                    }
                }
            }
        }
    });
    if (!recursive) {
        for (EnumFacing side : EnumFacing.VALUES) {
            TileEntity tile = holder.getPipeWorld().getTileEntity(holder.getPipePos().offset(side));
            if (tile instanceof IPipeHolder) {
                ((IPipeHolder) tile).getWireManager().updateBetweens(true);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPipeHolder(buildcraft.api.transport.pipe.IPipeHolder) EnumWirePart(buildcraft.api.transport.EnumWirePart) EnumFacing(net.minecraft.util.EnumFacing) IPipe(buildcraft.api.transport.pipe.IPipe) IWireManager(buildcraft.api.transport.IWireManager)

Example 10 with EnumWirePart

use of buildcraft.api.transport.EnumWirePart in project BuildCraft by BuildCraft.

the class WireManager method readPayload.

@SideOnly(Side.CLIENT)
public void readPayload(PacketBufferBC buffer, Side side, MessageContext ctx) throws IOException {
    if (side == Side.CLIENT) {
        parts.clear();
        int count = buffer.readInt();
        for (int i = 0; i < count; i++) {
            EnumWirePart part = buffer.readEnumValue(EnumWirePart.class);
            EnumDyeColor colour = buffer.readEnumValue(EnumDyeColor.class);
            parts.put(part, colour);
        }
        updateBetweens(false);
    }
}
Also used : EnumWirePart(buildcraft.api.transport.EnumWirePart) EnumDyeColor(net.minecraft.item.EnumDyeColor) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

EnumWirePart (buildcraft.api.transport.EnumWirePart)11 EnumFacing (net.minecraft.util.EnumFacing)7 TilePipeHolder (buildcraft.transport.tile.TilePipeHolder)6 EnumWireBetween (buildcraft.transport.wire.EnumWireBetween)6 PipePluggable (buildcraft.api.transport.pluggable.PipePluggable)5 Pipe (buildcraft.transport.pipe.Pipe)5 RayTraceResult (net.minecraft.util.math.RayTraceResult)5 Vec3d (net.minecraft.util.math.Vec3d)4 ItemStack (net.minecraft.item.ItemStack)3 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)3 Nullable (javax.annotation.Nullable)2 EnumDyeColor (net.minecraft.item.EnumDyeColor)2 Item (net.minecraft.item.Item)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 EnumPipePart (buildcraft.api.core.EnumPipePart)1 IItemPluggable (buildcraft.api.transport.IItemPluggable)1 IWireManager (buildcraft.api.transport.IWireManager)1 WireNode (buildcraft.api.transport.WireNode)1 IPipe (buildcraft.api.transport.pipe.IPipe)1 IPipeHolder (buildcraft.api.transport.pipe.IPipeHolder)1