From c09c319b2a6f827d44e7d801320cf5f60833d23b Mon Sep 17 00:00:00 2001 From: DStrand1 Date: Fri, 25 Jun 2021 20:11:49 -0500 Subject: [PATCH] redo pipe rendering --- .../pipelike/fluidpipe/FluidPipeType.java | 8 +- .../common/render/FluidPipeRenderer.java | 116 ++++++++---------- 2 files changed, 57 insertions(+), 67 deletions(-) diff --git a/src/main/java/gregtech/common/pipelike/fluidpipe/FluidPipeType.java b/src/main/java/gregtech/common/pipelike/fluidpipe/FluidPipeType.java index b89b986e3cb..b032970a518 100644 --- a/src/main/java/gregtech/common/pipelike/fluidpipe/FluidPipeType.java +++ b/src/main/java/gregtech/common/pipelike/fluidpipe/FluidPipeType.java @@ -5,10 +5,10 @@ public enum FluidPipeType implements IMaterialPipeType { - TINY_OPAQUE("tiny", 0.20f, 1, OrePrefix.pipeTiny, true), - SMALL_OPAQUE("small", 0.30f, 2, OrePrefix.pipeSmall, true), - MEDIUM_OPAQUE("medium", 0.35f, 4, OrePrefix.pipeMedium, true), - LARGE_OPAQUE("large", 0.40f, 8, OrePrefix.pipeLarge, true); + TINY_OPAQUE("tiny", 0.2f, 1, OrePrefix.pipeTiny, true), + SMALL_OPAQUE("small", 0.4f, 2, OrePrefix.pipeSmall, true), + MEDIUM_OPAQUE("medium", 0.6f, 4, OrePrefix.pipeMedium, true), + LARGE_OPAQUE("large", 0.8f, 8, OrePrefix.pipeLarge, true); public final String name; public final float thickness; diff --git a/src/main/java/gregtech/common/render/FluidPipeRenderer.java b/src/main/java/gregtech/common/render/FluidPipeRenderer.java index 041fe2fad3c..a750e224421 100644 --- a/src/main/java/gregtech/common/render/FluidPipeRenderer.java +++ b/src/main/java/gregtech/common/render/FluidPipeRenderer.java @@ -1,7 +1,7 @@ package gregtech.common.render; import codechicken.lib.render.BlockRenderer; -import codechicken.lib.render.CCModel; +import codechicken.lib.render.BlockRenderer.BlockFace; import codechicken.lib.render.CCRenderState; import codechicken.lib.render.block.BlockRenderingRegistry; import codechicken.lib.render.block.ICCBlockRenderer; @@ -59,8 +59,8 @@ public class FluidPipeRenderer implements ICCBlockRenderer, IItemRenderer { public static ModelResourceLocation MODEL_LOCATION = new ModelResourceLocation(new ResourceLocation(GTValues.MODID, "fluid_pipe"), "normal"); public static FluidPipeRenderer INSTANCE = new FluidPipeRenderer(); public static EnumBlockRenderType BLOCK_RENDER_TYPE; - private Map pipeTextures = new HashMap<>(); - private Map pipeModels = new HashMap<>(); + private static final ThreadLocal blockFaces = ThreadLocal.withInitial(BlockFace::new); + private final Map pipeTextures = new HashMap<>(); private static class PipeTextureInfo { public final TextureAtlasSprite inTexture; @@ -72,16 +72,6 @@ public PipeTextureInfo(TextureAtlasSprite inTexture, TextureAtlasSprite sideText } } - private static class PipeModelInfo { - public final CCModel[] connectionModels; - public final CCModel[] fullBlockModels; - - public PipeModelInfo(CCModel[] connectionModels, CCModel[] fullBlockModels) { - this.connectionModels = connectionModels; - this.fullBlockModels = fullBlockModels; - } - } - public static void preInit() { BLOCK_RENDER_TYPE = BlockRenderingRegistry.createRenderType("gt_fluid_pipe"); BlockRenderingRegistry.registerRenderer(BLOCK_RENDER_TYPE, INSTANCE); @@ -98,18 +88,6 @@ public void registerIcons(TextureMap map) { TextureAtlasSprite sideTexture = map.registerSprite(sideLocation); this.pipeTextures.put(fluidPipeType, new PipeTextureInfo(inTexture, sideTexture)); } - - for (FluidPipeType fluidPipeType : FluidPipeType.values()) { - float thickness = fluidPipeType.getThickness(); - double height = (1.0f - thickness) / 2.0f; - int angles = 5 + fluidPipeType.ordinal(); - CCModel model = ShapeModelGenerator.generateModel(angles, height, thickness / 3.0f, height); - CCModel fullBlockModel = ShapeModelGenerator.generateModel(angles, 1.0f, thickness / 3.0f, height); - - CCModel[] rotatedVariants = ShapeModelGenerator.generateRotatedVariants(model); - CCModel[] fullBlockVariants = ShapeModelGenerator.generateFullBlockVariants(fullBlockModel); - this.pipeModels.put(fluidPipeType, new PipeModelInfo(rotatedVariants, fullBlockVariants)); - } } @SubscribeEvent @@ -131,7 +109,9 @@ public void renderItem(ItemStack rawItemStack, TransformType transformType) { FluidPipeType pipeType = blockFluidPipe.getItemPipeType(stack); Material material = blockFluidPipe.getItemMaterial(stack); if (pipeType != null && material != null) { - renderPipeBlock(material, pipeType, IPipeTile.DEFAULT_INSULATION_COLOR, renderState, new IVertexOperation[0], 0); + renderPipeBlock(material, pipeType, IPipeTile.DEFAULT_INSULATION_COLOR, renderState, new IVertexOperation[0], + 1 << EnumFacing.SOUTH.getIndex() | 1 << EnumFacing.NORTH.getIndex() | + 1 << (6 + EnumFacing.SOUTH.getIndex()) | 1 << (6 + EnumFacing.NORTH.getIndex())); } renderState.draw(); GlStateManager.disableBlend(); @@ -143,9 +123,10 @@ public boolean renderBlock(IBlockAccess world, BlockPos pos, IBlockState state, renderState.reset(); renderState.bind(buffer); renderState.setBrightness(world, pos); + IVertexOperation[] pipeline = {new Translation(pos)}; - BlockFluidPipe blockPipe = ((BlockFluidPipe) state.getBlock()); - TileEntityFluidPipe tileEntityPipe = (TileEntityFluidPipe) blockPipe.getPipeTileEntity(world, pos); + BlockFluidPipe blockFluidPipe = ((BlockFluidPipe) state.getBlock()); + TileEntityFluidPipe tileEntityPipe = (TileEntityFluidPipe) blockFluidPipe.getPipeTileEntity(world, pos); if (tileEntityPipe == null) { return false; @@ -154,15 +135,13 @@ public boolean renderBlock(IBlockAccess world, BlockPos pos, IBlockState state, FluidPipeType fluidPipeType = tileEntityPipe.getPipeType(); Material pipeMaterial = tileEntityPipe.getPipeMaterial(); int paintingColor = tileEntityPipe.getInsulationColor(); + int connectedSidesMap = blockFluidPipe.getActualConnections(tileEntityPipe, world); if (fluidPipeType != null && pipeMaterial != null) { BlockRenderLayer renderLayer = MinecraftForgeClient.getRenderLayer(); - if (renderLayer == BlockRenderLayer.CUTOUT) { - int connectedSidesMask = blockPipe.getActualConnections(tileEntityPipe, world); - IVertexOperation[] pipeline = new IVertexOperation[] {new Translation(pos)}; - renderPipeBlock(pipeMaterial, fluidPipeType, paintingColor, renderState, pipeline, connectedSidesMask); - } + if (renderLayer == BlockRenderLayer.CUTOUT) + renderPipeBlock(pipeMaterial, fluidPipeType, paintingColor, renderState, pipeline, connectedSidesMap); ICoverable coverable = tileEntityPipe.getCoverableImplementation(); coverable.renderCovers(renderState, new Matrix4().translate(pos.getX(), pos.getY(), pos.getZ()), renderLayer); @@ -176,43 +155,54 @@ private int getPipeColor(Material material, int insulationColor) { } else return insulationColor; } - public boolean renderPipeBlock(Material material, FluidPipeType pipeType, int insulationColor, CCRenderState state, IVertexOperation[] pipeline, int connectMask) { + public void renderPipeBlock(Material material, FluidPipeType pipeType, int insulationColor, CCRenderState state, IVertexOperation[] pipeline, int connectMask) { int pipeColor = GTUtility.convertRGBtoOpaqueRGBA_CL(getPipeColor(material, insulationColor)); + float thickness = pipeType.getThickness(); ColourMultiplier multiplier = new ColourMultiplier(pipeColor); - PipeTextureInfo textureInfo = this.pipeTextures.get(pipeType); - PipeModelInfo modelInfo = this.pipeModels.get(pipeType); - - IVertexOperation[] openingTexture = ArrayUtils.addAll(pipeline, new IconTransformation(textureInfo.inTexture), multiplier); - IVertexOperation[] sideTexture = ArrayUtils.addAll(pipeline, new IconTransformation(textureInfo.sideTexture), multiplier); - - int sidedConnMask = connectMask & 0b111111; - CCModel fullBlockModel = null; - if (sidedConnMask == 0b000011) { - fullBlockModel = modelInfo.fullBlockModels[0]; - } else if (sidedConnMask == 0b001100) { - fullBlockModel = modelInfo.fullBlockModels[1]; - } else if (sidedConnMask == 0b110000) { - fullBlockModel = modelInfo.fullBlockModels[2]; - } - if (fullBlockModel != null) { - state.setPipeline(fullBlockModel, 0, fullBlockModel.verts.length, sideTexture); - state.render(); - return true; + IVertexOperation[] pipeConnectSide = ArrayUtils.addAll(pipeline, new IconTransformation(textureInfo.inTexture), multiplier); + IVertexOperation[] pipeSide = ArrayUtils.addAll(pipeline, new IconTransformation(textureInfo.sideTexture), multiplier); + + Cuboid6 cuboid6 = BlockFluidPipe.getSideBox(null, thickness); + for (EnumFacing renderedSide : EnumFacing.VALUES) { + if ((connectMask & 1 << renderedSide.getIndex()) == 0) { + int oppositeIndex = renderedSide.getOpposite().getIndex(); + if ((connectMask & 1 << oppositeIndex) > 0 && (connectMask & ~(1 << oppositeIndex)) == 0) { + renderPipeSide(state, pipeConnectSide, renderedSide, cuboid6); + } else { + renderPipeSide(state, pipeSide, renderedSide, cuboid6); + } + } } + renderPipeCube(connectMask, state, pipeSide, pipeConnectSide, EnumFacing.DOWN, thickness); + renderPipeCube(connectMask, state, pipeSide, pipeConnectSide, EnumFacing.UP, thickness); + renderPipeCube(connectMask, state, pipeSide, pipeConnectSide, EnumFacing.WEST, thickness); + renderPipeCube(connectMask, state, pipeSide, pipeConnectSide, EnumFacing.EAST, thickness); + renderPipeCube(connectMask, state, pipeSide, pipeConnectSide, EnumFacing.NORTH, thickness); + renderPipeCube(connectMask, state, pipeSide, pipeConnectSide, EnumFacing.SOUTH, thickness); + } - Cuboid6 centerCuboid = BlockFluidPipe.getSideBox(null, pipeType.getThickness()); - state.setPipeline(openingTexture); - BlockRenderer.renderCuboid(state, centerCuboid, 0); - - for (EnumFacing side : EnumFacing.VALUES) { - if ((connectMask & 1 << side.getIndex()) > 0) { - CCModel model = modelInfo.connectionModels[side.getIndex()]; - state.setPipeline(model, 0, model.verts.length, sideTexture); - state.render(); + private static void renderPipeCube(int connections, CCRenderState renderState, IVertexOperation[] pipeline, IVertexOperation[] pipeConnectSide, EnumFacing side, float thickness) { + if ((connections & 1 << side.getIndex()) > 0) { + boolean renderFrontSide = (connections & 1 << (6 + side.getIndex())) > 0; + Cuboid6 cuboid6 = BlockFluidPipe.getSideBox(side, thickness); + for (EnumFacing renderedSide : EnumFacing.VALUES) { + if (renderedSide == side) { + if (renderFrontSide) { + renderPipeSide(renderState, pipeConnectSide, renderedSide, cuboid6); + } + } else if (renderedSide != side.getOpposite()) { + renderPipeSide(renderState, pipeline, renderedSide, cuboid6); + } } } - return true; + } + + private static void renderPipeSide(CCRenderState renderState, IVertexOperation[] pipeline, EnumFacing side, Cuboid6 cuboid6) { + BlockFace blockFace = blockFaces.get(); + blockFace.loadCuboidFace(cuboid6, side.getIndex()); + renderState.setPipeline(blockFace, 0, blockFace.verts.length, pipeline); + renderState.render(); } @Override