Search in sources :

Example 1 with Offset

use of crazypants.enderio.base.conduit.geom.Offset in project EnderIO by SleepyTrousers.

the class ItemConduitRenderer method addConduitQuads.

@Override
protected void addConduitQuads(@Nonnull IConduitBundle bundle, @Nonnull IConduit conduit, @Nonnull TextureAtlasSprite tex, @Nonnull CollidableComponent component, float selfIllum, BlockRenderLayer layer, @Nonnull List<BakedQuad> quads) {
    super.addConduitQuads(bundle, conduit, tex, component, selfIllum, layer, quads);
    if (layer == null || component.dir == null) {
        return;
    }
    EnumFacing dir = component.dir;
    if (!conduit.getExternalConnections().contains(dir)) {
        return;
    }
    IItemConduit pc = (IItemConduit) conduit;
    DyeColor inChannel = null;
    DyeColor outChannel = null;
    TextureAtlasSprite inTex = null;
    TextureAtlasSprite outTex = null;
    boolean render = true;
    if (conduit.getConnectionMode(dir) == ConnectionMode.INPUT) {
        inTex = pc.getTextureForInputMode();
        inChannel = pc.getInputColor(dir);
    } else if (conduit.getConnectionMode(dir) == ConnectionMode.OUTPUT) {
        outTex = pc.getTextureForOutputMode();
        outChannel = pc.getOutputColor(dir);
    } else if (conduit.getConnectionMode(dir) == ConnectionMode.IN_OUT) {
        inTex = pc.getTextureForInOutMode(true);
        outTex = pc.getTextureForInOutMode(false);
        inChannel = pc.getInputColor(dir);
        outChannel = pc.getOutputColor(dir);
    } else {
        render = false;
    }
    if (render) {
        Offset offset = bundle.getOffset(IItemConduit.class, dir);
        ConnectionModeGeometry.addModeConnectorQuads(dir, offset, pc.getTextureForInOutBackground(), null, quads);
        if (inChannel != null) {
            ConnectionModeGeometry.addModeConnectorQuads(dir, offset, inTex, ColorUtil.toFloat4(inChannel.getColor()), quads);
        }
        if (outChannel != null) {
            ConnectionModeGeometry.addModeConnectorQuads(dir, offset, outTex, ColorUtil.toFloat4(outChannel.getColor()), quads);
        }
    }
}
Also used : TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) EnumFacing(net.minecraft.util.EnumFacing) DyeColor(com.enderio.core.common.util.DyeColor) Offset(crazypants.enderio.base.conduit.geom.Offset)

Example 2 with Offset

use of crazypants.enderio.base.conduit.geom.Offset in project EnderIO by SleepyTrousers.

the class AdvancedLiquidConduitRenderer method addConduitQuads.

@Override
protected void addConduitQuads(@Nonnull IConduitBundle bundle, @Nonnull IConduit conduit, @Nonnull TextureAtlasSprite tex, @Nonnull CollidableComponent component, float selfIllum, BlockRenderLayer layer, @Nonnull List<BakedQuad> quads) {
    super.addConduitQuads(bundle, conduit, tex, component, selfIllum, layer, quads);
    if (!isNSEWUD(component.dir)) {
        return;
    }
    AdvancedLiquidConduit lc = (AdvancedLiquidConduit) conduit;
    for (EnumFacing dir : conduit.getExternalConnections()) {
        TextureAtlasSprite ioTex = null;
        if (conduit.getConnectionMode(dir) == ConnectionMode.INPUT) {
            ioTex = lc.getTextureForInputMode();
        } else if (conduit.getConnectionMode(dir) == ConnectionMode.OUTPUT) {
            ioTex = lc.getTextureForOutputMode();
        }
        if (ioTex != null) {
            Offset offset = bundle.getOffset(ILiquidConduit.class, dir);
            ConnectionModeGeometry.addModeConnectorQuads(dir, offset, ioTex, new Vector4f(1, 1, 1, 1), quads);
        }
    }
    FluidStack fluid = lc.getFluidType();
    @Nonnull TextureAtlasSprite texture = fluid != null ? RenderUtil.getStillTexture(fluid) : lc.getNotSetEdgeTexture();
    float scaleFactor = 0.75f;
    float xLen = Math.abs(component.dir.getFrontOffsetX()) == 1 ? 1 : scaleFactor;
    float yLen = Math.abs(component.dir.getFrontOffsetY()) == 1 ? 1 : scaleFactor;
    float zLen = Math.abs(component.dir.getFrontOffsetZ()) == 1 ? 1 : scaleFactor;
    BoundingBox cube = component.bound;
    BoundingBox bb = cube.scale(xLen, yLen, zLen);
    List<Vertex> vertices = new ArrayList<Vertex>();
    for (EnumFacing d : EnumFacing.VALUES) {
        if (d != component.dir && d != component.dir.getOpposite()) {
            EnumFacing vDir = RenderUtil.getVDirForFace(d);
            if (component.dir == EnumFacing.UP || component.dir == EnumFacing.DOWN) {
                vDir = RenderUtil.getUDirForFace(d);
            } else if ((component.dir == EnumFacing.NORTH || component.dir == EnumFacing.SOUTH) && d.getFrontOffsetY() != 0) {
                vDir = RenderUtil.getUDirForFace(d);
            }
            float minU = texture.getMinU();
            float maxU = texture.getMaxU();
            float minV = texture.getMinV();
            float maxV = texture.getMaxV();
            double sideScale = Math.max(bb.sizeX(), bb.sizeY()) * 2 / 16f;
            sideScale = Math.max(sideScale, bb.sizeZ() * 2 / 16f);
            double width = Math.min(bb.sizeX(), bb.sizeY()) * 15f / 16f;
            List<Vertex> corners = bb.getCornersWithUvForFace(d, minU, maxU, minV, maxV);
            moveEdgeCorners(corners, vDir, width);
            moveEdgeCorners(corners, component.dir.getOpposite(), sideScale);
            for (Vertex c : corners) {
                vertices.add(c);
            }
            corners = bb.getCornersWithUvForFace(d, minU, maxU, minV, maxV);
            moveEdgeCorners(corners, vDir.getOpposite(), width);
            moveEdgeCorners(corners, component.dir.getOpposite(), sideScale);
            for (Vertex c : corners) {
                vertices.add(c);
            }
        }
    }
    if (conduit.getConnectionMode(component.dir) == ConnectionMode.DISABLED) {
        tex = ConduitBundleRenderManager.instance.getConnectorIcon(component.data);
        List<Vertex> corners = component.bound.getCornersWithUvForFace(component.dir, tex.getMinU(), tex.getMaxU(), tex.getMinV(), tex.getMaxV());
        for (Vertex c : corners) {
            vertices.add(c);
        }
        // back face
        for (int i = corners.size() - 1; i >= 0; i--) {
            Vertex c = corners.get(i);
            vertices.add(c);
        }
    }
    BakedQuadBuilder.addBakedQuads(quads, vertices, texture, null);
}
Also used : Vertex(com.enderio.core.common.vecmath.Vertex) Nonnull(javax.annotation.Nonnull) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) FluidStack(net.minecraftforge.fluids.FluidStack) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) Offset(crazypants.enderio.base.conduit.geom.Offset) Vector4f(com.enderio.core.common.vecmath.Vector4f) BoundingBox(com.enderio.core.client.render.BoundingBox)

Example 3 with Offset

use of crazypants.enderio.base.conduit.geom.Offset in project EnderIO by SleepyTrousers.

the class ConduitBuilder method build.

// BUILD NETWORK
@SuppressWarnings("unused")
public ConduitBuilder build() {
    checkState(state.acceptNetworkBuild || state.acceptConduitBuild);
    if (state.acceptNetworkBuild) {
        final UUID networkUUID2 = networkUUID;
        if (networkUUID2 != null) {
            final Class<? extends IConduit> baseType2 = baseType;
            if (baseType2 != null) {
                final Offset none2 = none;
                if (none2 != null) {
                    final Offset x2 = x;
                    if (x2 != null) {
                        final Offset y2 = y;
                        if (y2 != null) {
                            final Offset z2 = z;
                            if (z2 != null) {
                                network = new ConduitTypeDefinition(networkUUID2, baseType2, none2, x2, y2, z2, canConnectToAnything);
                                network.getAliases().addAll(networkAliases);
                                state = State.PRE_CONDUIT;
                                return this;
                            }
                        }
                    }
                }
            }
        }
    } else {
        final ConduitTypeDefinition network2 = network;
        if (network2 != null) {
            final UUID conduitUUID2 = conduitUUID;
            if (conduitUUID2 != null) {
                final Class<? extends IServerConduit> serverClass2 = serverClass;
                if (serverClass2 != null) {
                    final Class<? extends IClientConduit> clientClass2 = clientClass;
                    if (clientClass2 != null) {
                        new ConduitDefinition(network2, conduitUUID2, serverClass2, clientClass2).getAliases().addAll(conduitAliases);
                        conduitUUID = null;
                        conduitAliases.clear();
                        serverClass = null;
                        clientClass = null;
                        state = State.POST_CONDUIT;
                        return this;
                    }
                }
            }
        }
    }
    throw new RuntimeException("State error in Conduit Builder---data missing");
}
Also used : UUID(java.util.UUID) Offset(crazypants.enderio.base.conduit.geom.Offset)

Example 4 with Offset

use of crazypants.enderio.base.conduit.geom.Offset in project EnderIO by SleepyTrousers.

the class ConduitRegistry method register.

/**
 * Register a new conduit type.
 * <p>
 * Will throw a RuntimeException if no location in the bundle could be found for the conduit.
 */
public static void register(ConduitTypeDefinition info) {
    UUID_TO_NETWORK.put(info.getUUID(), info);
    for (UUID uuid : info.getAliases()) {
        UUID_TO_NETWORK.put(uuid, info);
    }
    CLASS_TO_UUID.put(info.getBaseType(), info.getUUID());
    for (ConduitDefinition member : info.getMembers()) {
        UUID_TO_CONDUIT.put(member.getUUID(), member);
        for (UUID uuid : member.getAliases()) {
            UUID_TO_CONDUIT.put(uuid, member);
        }
        CLASS_TO_UUID.put(member.getServerClass(), member.getUUID());
        CLASS_TO_UUID.put(member.getClientClass(), member.getUUID());
        // pre-classload the instances
        getServerInstance(member.getUUID());
        if (!EnderIO.proxy.isDedicatedServer()) {
            getClientInstance(member.getUUID());
        }
    }
    Offset none = info.getPreferedOffsetForNone(), x = info.getPreferedOffsetForX(), y = info.getPreferedOffsetForY(), z = info.getPreferedOffsetForZ();
    while (!Offsets.registerOffsets(info.getBaseType(), none, x, y, z)) {
        z = z.next();
        if (z == null) {
            z = Offset.first();
        }
        if (z == info.getPreferedOffsetForZ()) {
            y = y.next();
            if (y == null) {
                y = Offset.first();
            }
            if (y == info.getPreferedOffsetForY()) {
                x = x.next();
                if (x == null) {
                    x = Offset.first();
                }
                if (x == info.getPreferedOffsetForX()) {
                    none = none.next();
                    if (none == null) {
                        none = Offset.first();
                    }
                }
            }
        }
        if (z == info.getPreferedOffsetForZ() && y == info.getPreferedOffsetForY() && x == info.getPreferedOffsetForX() && none == info.getPreferedOffsetForNone()) {
            throw new RuntimeException("Failed to find free offsets for " + info.getBaseType());
        }
    }
}
Also used : UUID(java.util.UUID) Offset(crazypants.enderio.base.conduit.geom.Offset)

Example 5 with Offset

use of crazypants.enderio.base.conduit.geom.Offset in project EnderIO by SleepyTrousers.

the class PowerConduitRenderer method addConduitQuads.

@Override
protected void addConduitQuads(@Nonnull IConduitBundle bundle, @Nonnull IConduit conduit, @Nonnull TextureAtlasSprite tex, @Nonnull CollidableComponent component, float selfIllum, BlockRenderLayer layer, @Nonnull List<BakedQuad> quads) {
    if (IPowerConduit.COLOR_CONTROLLER_ID.equals(component.data)) {
        IPowerConduit pc = (IPowerConduit) conduit;
        ConnectionMode conMode = pc.getConnectionMode(component.dir);
        if (conduit.containsExternalConnection(component.dir) && pc.getExtractionRedstoneMode(component.dir) != RedstoneControlMode.IGNORE && conMode != ConnectionMode.DISABLED) {
            int cInt = ((IPowerConduit) conduit).getExtractionSignalColor(component.dir).getColor();
            Vector4f col = ColorUtil.toFloat4(cInt);
            BoundingBox bound = component.bound;
            if (conMode != ConnectionMode.IN_OUT && conMode != ConnectionMode.NOT_SET) {
                Vector3d trans = ForgeDirectionOffsets.offsetScaled(component.dir, -0.12);
                bound = bound.translate(trans);
            }
            addQuadsForSection(bound, tex, component.dir, quads, col);
        }
        return;
    }
    super.addConduitQuads(bundle, conduit, tex, component, selfIllum, layer, quads);
    if (component.dir == null) {
        return;
    }
    IPowerConduit pc = (IPowerConduit) conduit;
    ConnectionMode mode = pc.getConnectionMode(component.dir);
    if (mode != ConnectionMode.INPUT && mode != ConnectionMode.OUTPUT) {
        return;
    }
    if (mode == ConnectionMode.INPUT) {
        tex = pc.getTextureForInputMode();
    } else {
        tex = pc.getTextureForOutputMode();
    }
    Offset offset = bundle.getOffset(IPowerConduit.class, component.dir);
    ConnectionModeGeometry.addModeConnectorQuads(component.dir, offset, tex, null, quads);
}
Also used : Vector4f(com.enderio.core.common.vecmath.Vector4f) Vector3d(com.enderio.core.common.vecmath.Vector3d) BoundingBox(com.enderio.core.client.render.BoundingBox) ConnectionMode(crazypants.enderio.base.conduit.ConnectionMode) Offset(crazypants.enderio.base.conduit.geom.Offset)

Aggregations

Offset (crazypants.enderio.base.conduit.geom.Offset)6 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)3 EnumFacing (net.minecraft.util.EnumFacing)3 BoundingBox (com.enderio.core.client.render.BoundingBox)2 Vector4f (com.enderio.core.common.vecmath.Vector4f)2 UUID (java.util.UUID)2 DyeColor (com.enderio.core.common.util.DyeColor)1 Vector3d (com.enderio.core.common.vecmath.Vector3d)1 Vertex (com.enderio.core.common.vecmath.Vertex)1 ConnectionMode (crazypants.enderio.base.conduit.ConnectionMode)1 ArrayList (java.util.ArrayList)1 Nonnull (javax.annotation.Nonnull)1 FluidStack (net.minecraftforge.fluids.FluidStack)1