Search in sources :

Example 1 with IClientConduit

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

the class ConduitBundleRenderer method addBreakingQuads.

private void addBreakingQuads(@Nonnull IConduitBundle bundle, @Nonnull List<BakedQuad> quads) {
    Class<? extends IConduit> conduitType = null;
    RayTraceResult hit = Minecraft.getMinecraft().objectMouseOver;
    if (NullHelper.untrust(hit) != null && (hit.hitInfo instanceof CollidableComponent)) {
        conduitType = ((CollidableComponent) hit.hitInfo).conduitType;
    }
    if (breakingAnimOnWholeConduit) {
        for (IClientConduit c : bundle.getClientConduits()) {
            if (conduitType == c.getClass() || conduitType == c.getBaseConduitType()) {
                IConduitRenderer renderer = getRendererForConduit(c);
                renderer.addBakedQuads(this, bundle, (IClientConduit.WithDefaultRendering) c, 1, BlockRenderLayer.CUTOUT, quads);
            }
        }
    }
    List<CollidableComponent> connectors = bundle.getConnectors();
    for (CollidableComponent component : connectors) {
        if (component != null) {
            if (component.conduitType == conduitType || conduitType == null) {
                IClientConduit.WithDefaultRendering conduit = (IClientConduit.WithDefaultRendering) bundle.getConduit(component.conduitType);
                if (conduit != null) {
                    TextureAtlasSprite tex = conduit.getTextureForState(component);
                    BakedQuadBuilder.addBakedQuads(quads, component.bound, tex);
                }
            }
        }
    }
}
Also used : IClientConduit(crazypants.enderio.base.conduit.IClientConduit) CollidableComponent(crazypants.enderio.base.conduit.geom.CollidableComponent) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) RayTraceResult(net.minecraft.util.math.RayTraceResult) IConduitRenderer(crazypants.enderio.base.conduit.IConduitRenderer)

Example 2 with IClientConduit

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

the class ConduitBundleRenderer method render.

// TESR rendering
@Override
public void render(@Nonnull TileConduitBundle te, double x, double y, double z, float partialTick, int b, float alpha) {
    IConduitBundle bundle = te;
    EntityPlayerSP player = Minecraft.getMinecraft().player;
    if (bundle.hasFacade() && bundle.getPaintSource().isOpaqueCube() && !YetaUtil.isFacadeHidden(bundle, player)) {
        return;
    }
    float brightness = -1;
    boolean hasDynamic = false;
    for (IClientConduit c : bundle.getClientConduits()) {
        // TODO Temporary work around
        IClientConduit.WithDefaultRendering con = (IClientConduit.WithDefaultRendering) c;
        if (YetaUtil.renderConduit(player, con)) {
            IConduitRenderer renderer = getRendererForConduit(con);
            if (renderer.isDynamic()) {
                if (!hasDynamic) {
                    hasDynamic = true;
                    BlockPos loc = bundle.getLocation();
                    brightness = bundle.getEntity().getWorld().getLightFor(EnumSkyBlock.SKY, loc);
                    RenderUtil.setupLightmapCoords(te.getPos(), te.getWorld());
                    RenderUtil.bindBlockTexture();
                    GlStateManager.enableNormalize();
                    GlStateManager.enableBlend();
                    GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
                    GlStateManager.shadeModel(GL11.GL_SMOOTH);
                    GlStateManager.pushMatrix();
                    GlStateManager.translate(x, y, z);
                    Tessellator tessellator = Tessellator.getInstance();
                    BufferBuilder tes = tessellator.getBuffer();
                    tes.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
                }
                renderer.renderDynamicEntity(this, bundle, con, x, y, z, partialTick, brightness);
            }
        }
    }
    if (hasDynamic) {
        Tessellator.getInstance().draw();
        GlStateManager.disableNormalize();
        GlStateManager.disableBlend();
        GlStateManager.shadeModel(GL11.GL_FLAT);
        GlStateManager.popMatrix();
    }
}
Also used : IClientConduit(crazypants.enderio.base.conduit.IClientConduit) Tessellator(net.minecraft.client.renderer.Tessellator) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) IConduitBundle(crazypants.enderio.base.conduit.IConduitBundle) BlockPos(net.minecraft.util.math.BlockPos) IConduitRenderer(crazypants.enderio.base.conduit.IConduitRenderer) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP)

Example 3 with IClientConduit

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

the class ConduitBundleRenderer method addConduitQuads.

private void addConduitQuads(@Nonnull IBlockStateWrapper state, @Nonnull IConduitBundle bundle, float brightness, @Nonnull BlockRenderLayer layer, @Nonnull List<BakedQuad> quads) {
    // Conduits
    Set<EnumFacing> externals = new HashSet<EnumFacing>();
    List<BoundingBox> wireBounds = new ArrayList<BoundingBox>();
    if (bundle.hasFacade() && state.getYetaDisplayMode().isHideFacades()) {
        wireBounds.add(BoundingBox.UNIT_CUBE);
    }
    for (IClientConduit c : bundle.getClientConduits()) {
        // TODO Temporary Workaround
        IClientConduit.WithDefaultRendering con = (IClientConduit.WithDefaultRendering) c;
        if (state.getYetaDisplayMode().renderConduit(con)) {
            IConduitRenderer renderer = getRendererForConduit(con);
            renderer.addBakedQuads(this, bundle, con, brightness, layer, quads);
            Set<EnumFacing> extCons = con.getExternalConnections();
            for (EnumFacing dir : extCons) {
                if (con.getConnectionMode(dir) != ConnectionMode.DISABLED && con.getConnectionMode(dir) != ConnectionMode.NOT_SET) {
                    externals.add(dir);
                }
            }
        } else if (con != null) {
            Collection<CollidableComponent> components = con.getCollidableComponents();
            for (CollidableComponent component : components) {
                addWireBounds(wireBounds, component);
            }
        }
    }
    // Internal connectors between conduits
    List<CollidableComponent> connectors = bundle.getConnectors();
    for (CollidableComponent component : connectors) {
        if (component != null) {
            if (component.conduitType != null) {
                // TODO Make an actual check before assuming a default render
                IClientConduit.WithDefaultRendering conduit = (IClientConduit.WithDefaultRendering) bundle.getConduit(component.conduitType);
                if (conduit != null) {
                    if (state.getYetaDisplayMode().renderConduit(component.conduitType)) {
                        TextureAtlasSprite tex = conduit.getTextureForState(component);
                        if (tex == null) {
                            tex = Minecraft.getMinecraft().getTextureMapBlocks().getMissingSprite();
                        }
                        BakedQuadBuilder.addBakedQuads(quads, component.bound, tex);
                    } else {
                        addWireBounds(wireBounds, component);
                    }
                }
            } else if (state.getYetaDisplayMode().getDisplayMode().isAll()) {
                TextureAtlasSprite tex = ConduitBundleRenderManager.instance.getConnectorIcon(component.data);
                BakedQuadBuilder.addBakedQuads(quads, component.bound, tex);
            }
        }
    }
    // render these after the 'normal' conduits so help with proper blending
    for (BoundingBox wireBound : wireBounds) {
        BakedQuadBuilder.addBakedQuads(quads, wireBound, ConduitBundleRenderManager.instance.getWireFrameIcon());
    }
    // External connection terminations
    for (EnumFacing dir : externals) {
        addQuadsForExternalConnection(dir, quads);
    }
    if (quads.isEmpty() && !bundle.hasFacade()) {
        BakedQuadBuilder.addBakedQuads(quads, BoundingBox.UNIT_CUBE.scale(.10), ConduitBundleRenderManager.instance.getWireFrameIcon());
        BakedQuadBuilder.addBakedQuads(quads, BoundingBox.UNIT_CUBE.scale(.15), ConduitBundleRenderManager.instance.getWireFrameIcon());
        BakedQuadBuilder.addBakedQuads(quads, BoundingBox.UNIT_CUBE.scale(.20), ConduitBundleRenderManager.instance.getWireFrameIcon());
        BakedQuadBuilder.addBakedQuads(quads, BoundingBox.UNIT_CUBE.scale(.25), ConduitBundleRenderManager.instance.getWireFrameIcon());
    }
}
Also used : TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) IClientConduit(crazypants.enderio.base.conduit.IClientConduit) CollidableComponent(crazypants.enderio.base.conduit.geom.CollidableComponent) BoundingBox(com.enderio.core.client.render.BoundingBox) Collection(java.util.Collection) IConduitRenderer(crazypants.enderio.base.conduit.IConduitRenderer) HashSet(java.util.HashSet)

Example 4 with IClientConduit

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

the class TileConduitBundle method onAfterNbtRead.

@Override
protected void onAfterNbtRead() {
    super.onAfterNbtRead();
    if (world.isRemote) {
        // keep conduits sorted so the client side cache key is stable
        ConduitRegistry.sort(conduits);
        CopyOnWriteArrayList<IClientConduit> temp = new CopyOnWriteArrayList<>();
        for (IConduit c : conduits) {
            if (c instanceof IClientConduit) {
                c.setBundle(this);
                temp.add((IClientConduit) c);
            }
        }
        final ConduitCacheKey oldHashCode = new ConduitCacheKey(), newHashCode = new ConduitCacheKey();
        makeConduitHashCode(getClientConduits(), oldHashCode);
        makeConduitHashCode(temp, newHashCode);
        if (hasWorld() && getWorld().isRemote && oldHashCode.hashCode() != newHashCode.hashCode()) {
            clientUpdated = true;
        }
        // switch over atomically to avoid threading issues
        clientConduits = temp;
        conduits = new CopyOnWriteArrayList<IConduit>();
    } else {
        // no threads on server-side. but to be safe, conduits only go into the list after they got a bundle set
        // (a.k.a. "do better than World.addTileEntities()"
        serverConduits.clear();
        for (IConduit c : conduits) {
            if (c instanceof IServerConduit) {
                c.setBundle(this);
                serverConduits.add((IServerConduit) c);
            }
        }
        conduits.clear();
    }
    cachedCollidables.clear();
}
Also used : IClientConduit(crazypants.enderio.base.conduit.IClientConduit) IServerConduit(crazypants.enderio.base.conduit.IServerConduit) ConduitCacheKey(crazypants.enderio.conduits.render.BlockStateWrapperConduitBundle.ConduitCacheKey) IConduit(crazypants.enderio.base.conduit.IConduit) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Aggregations

IClientConduit (crazypants.enderio.base.conduit.IClientConduit)4 IConduitRenderer (crazypants.enderio.base.conduit.IConduitRenderer)3 CollidableComponent (crazypants.enderio.base.conduit.geom.CollidableComponent)2 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)2 BoundingBox (com.enderio.core.client.render.BoundingBox)1 IConduit (crazypants.enderio.base.conduit.IConduit)1 IConduitBundle (crazypants.enderio.base.conduit.IConduitBundle)1 IServerConduit (crazypants.enderio.base.conduit.IServerConduit)1 ConduitCacheKey (crazypants.enderio.conduits.render.BlockStateWrapperConduitBundle.ConduitCacheKey)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)1 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)1 Tessellator (net.minecraft.client.renderer.Tessellator)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1