From 836fdf2d728ecf6cd902d946920734945b087064 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 22 Dec 2023 00:35:57 -0700 Subject: [PATCH 01/21] improve QuantumStorageRenderer --- .../custom/QuantumStorageRenderer.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java index 7e6485a155d..e42e1f6d790 100644 --- a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java +++ b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java @@ -69,18 +69,21 @@ public void renderMachine(CCRenderState renderState, Matrix4 translation, IVerte TextureAtlasSprite hullTexture = Textures.VOLTAGE_CASINGS[tier] .getSpriteOnSide(RenderSide.bySide(EnumFacing.NORTH)); - boxFacingMap.keySet().forEach(facing -> { - for (EnumFacing box : EnumFacing.VALUES) { - if ((facing != frontFacing || box != frontFacing) && - (facing != EnumFacing.DOWN || box.getAxis().isVertical())) { // Don't render the front facing - // box from the front, nor allow - // Z-fighting to occur on the - // bottom - Textures.renderFace(renderState, translation, pipeline, facing, boxFacingMap.get(box), hullTexture, + for (EnumFacing facing : EnumFacing.VALUES) { + for (EnumFacing boxFace : EnumFacing.VALUES) { + // do not render the box when "facing" is "frontFacing", otherwise + // render when the box face matches facing, or + // render when the box face is opposite of facing, or + // render when the box face is the front face + if (facing != frontFacing && + (boxFace == facing || boxFace == facing.getOpposite() || boxFace == frontFacing)) { + + Textures.renderFace(renderState, translation, pipeline, boxFace, boxFacingMap.get(facing), + hullTexture, BlockRenderLayer.CUTOUT_MIPPED); } } - }); + } } public static void renderChestStack(double x, double y, double z, MetaTileEntityQuantumChest machine, From c099317099929363f35ee0d9c371e433a542324d Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Mon, 25 Dec 2023 19:44:19 -0700 Subject: [PATCH 02/21] rework rendering logic to remove the inner for loop + spobless --- .../custom/QuantumStorageRenderer.java | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java index e42e1f6d790..d93ea766e49 100644 --- a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java +++ b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java @@ -69,21 +69,32 @@ public void renderMachine(CCRenderState renderState, Matrix4 translation, IVerte TextureAtlasSprite hullTexture = Textures.VOLTAGE_CASINGS[tier] .getSpriteOnSide(RenderSide.bySide(EnumFacing.NORTH)); - for (EnumFacing facing : EnumFacing.VALUES) { - for (EnumFacing boxFace : EnumFacing.VALUES) { - // do not render the box when "facing" is "frontFacing", otherwise - // render when the box face matches facing, or - // render when the box face is opposite of facing, or - // render when the box face is the front face - if (facing != frontFacing && - (boxFace == facing || boxFace == facing.getOpposite() || boxFace == frontFacing)) { - - Textures.renderFace(renderState, translation, pipeline, boxFace, boxFacingMap.get(facing), - hullTexture, - BlockRenderLayer.CUTOUT_MIPPED); - } - } + + for (var facing : boxFacingMap.keySet()) { + // do not render the box at the front face when "facing" is "frontFacing" + if (facing == frontFacing) continue; + + // render when the box face matches facing + Textures.renderFace(renderState, translation, pipeline, facing, boxFacingMap.get(facing), + hullTexture, BlockRenderLayer.CUTOUT_MIPPED); + + // render when the box face is opposite of facing + Textures.renderFace(renderState, translation, pipeline, facing.getOpposite(), boxFacingMap.get(facing), + hullTexture, BlockRenderLayer.CUTOUT_MIPPED); } + + // render the sides of the box that face the front face + if (frontFacing.getAxis() == EnumFacing.Axis.Y) return; + Textures.renderFace(renderState, translation, pipeline, frontFacing, boxFacingMap.get(EnumFacing.DOWN), + hullTexture, BlockRenderLayer.CUTOUT_MIPPED); + Textures.renderFace(renderState, translation, pipeline, frontFacing, boxFacingMap.get(EnumFacing.UP), + hullTexture, BlockRenderLayer.CUTOUT_MIPPED); + + EnumFacing facing = frontFacing.rotateYCCW(); + Textures.renderFace(renderState, translation, pipeline, frontFacing, boxFacingMap.get(facing), + hullTexture, BlockRenderLayer.CUTOUT_MIPPED); + Textures.renderFace(renderState, translation, pipeline, frontFacing, boxFacingMap.get(facing.getOpposite()), + hullTexture, BlockRenderLayer.CUTOUT_MIPPED); } public static void renderChestStack(double x, double y, double z, MetaTileEntityQuantumChest machine, From 15ce779b0642e047a6c92fbeef18e707a8028935 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Mon, 1 Jan 2024 19:49:46 -0700 Subject: [PATCH 03/21] enhanced instanceof --- .../gregtech/client/renderer/handler/MetaTileEntityTESR.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/gregtech/client/renderer/handler/MetaTileEntityTESR.java b/src/main/java/gregtech/client/renderer/handler/MetaTileEntityTESR.java index c22b454748a..04f29382669 100644 --- a/src/main/java/gregtech/client/renderer/handler/MetaTileEntityTESR.java +++ b/src/main/java/gregtech/client/renderer/handler/MetaTileEntityTESR.java @@ -46,12 +46,12 @@ public void render(@NotNull MetaTileEntityHolder te, double x, double y, double buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); MetaTileEntity metaTileEntity = te.getMetaTileEntity(); - if (metaTileEntity instanceof IFastRenderMetaTileEntity) { + if (metaTileEntity instanceof IFastRenderMetaTileEntity fastRender) { CCRenderState renderState = CCRenderState.instance(); renderState.reset(); renderState.bind(buffer); renderState.setBrightness(te.getWorld(), te.getPos()); - ((IFastRenderMetaTileEntity) metaTileEntity).renderMetaTileEntityFast(renderState, + fastRender.renderMetaTileEntityFast(renderState, new Matrix4().translate(x, y, z), partialTicks); } if (metaTileEntity != null) { From 64e783ab93807676cd9516c33fdd6f244443b253 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Mon, 1 Jan 2024 19:51:41 -0700 Subject: [PATCH 04/21] pass in the MTE directly --- .../renderer/texture/custom/QuantumStorageRenderer.java | 8 ++++++-- .../storage/MetaTileEntityCreativeChest.java | 2 +- .../storage/MetaTileEntityCreativeTank.java | 2 +- .../storage/MetaTileEntityQuantumChest.java | 2 +- .../storage/MetaTileEntityQuantumTank.java | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java index d93ea766e49..7cd680eadf1 100644 --- a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java +++ b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java @@ -1,6 +1,8 @@ package gregtech.client.renderer.texture.custom; import gregtech.api.gui.resources.TextTexture; +import gregtech.api.metatileentity.ITieredMetaTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.util.TextFormattingUtil; import gregtech.client.renderer.texture.Textures; import gregtech.client.renderer.texture.cube.SimpleSidedCubeRenderer.RenderSide; @@ -62,8 +64,10 @@ public void registerIcons(TextureMap textureMap) { .registerSprite(new ResourceLocation("gregtech:blocks/overlay/machine/overlay_screen_glass")); } - public void renderMachine(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline, - EnumFacing frontFacing, int tier) { + public void renderMachine(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline, + T mte) { + EnumFacing frontFacing = mte.getFrontFacing(); + int tier = mte.getTier(); Textures.renderFace(renderState, translation, pipeline, frontFacing, glassBox, glassTexture, BlockRenderLayer.CUTOUT_MIPPED); diff --git a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityCreativeChest.java b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityCreativeChest.java index 50dd8dc5cbe..e34f104d679 100644 --- a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityCreativeChest.java +++ b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityCreativeChest.java @@ -69,7 +69,7 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, Textures.QUANTUM_STORAGE_RENDERER.renderMachine(renderState, translation, ArrayUtils.add(pipeline, new ColourMultiplier(GTUtility.convertRGBtoOpaqueRGBA_CL(getPaintingColorForRendering()))), - this.getFrontFacing(), this.getTier()); + this); Textures.CREATIVE_CONTAINER_OVERLAY.renderSided(EnumFacing.UP, renderState, translation, pipeline); Textures.PIPE_OUT_OVERLAY.renderSided(this.getOutputFacing(), renderState, translation, pipeline); Textures.ITEM_OUTPUT_OVERLAY.renderSided(this.getOutputFacing(), renderState, translation, pipeline); diff --git a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityCreativeTank.java b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityCreativeTank.java index 1f35630af35..3e93c1bcbd5 100644 --- a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityCreativeTank.java +++ b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityCreativeTank.java @@ -52,7 +52,7 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, Textures.QUANTUM_STORAGE_RENDERER.renderMachine(renderState, translation, ArrayUtils.add(pipeline, new ColourMultiplier(GTUtility.convertRGBtoOpaqueRGBA_CL(getPaintingColorForRendering()))), - this.getFrontFacing(), this.getTier()); + this); Textures.CREATIVE_CONTAINER_OVERLAY.renderSided(EnumFacing.UP, renderState, translation, pipeline); if (this.getOutputFacing() != null) { Textures.PIPE_OUT_OVERLAY.renderSided(this.getOutputFacing(), renderState, translation, pipeline); diff --git a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumChest.java b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumChest.java index be6c63f5dec..bd6dca83fb8 100644 --- a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumChest.java +++ b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumChest.java @@ -102,7 +102,7 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, Textures.QUANTUM_STORAGE_RENDERER.renderMachine(renderState, translation, ArrayUtils.add(pipeline, new ColourMultiplier(GTUtility.convertRGBtoOpaqueRGBA_CL(getPaintingColorForRendering()))), - this.getFrontFacing(), this.tier); + this); Textures.QUANTUM_CHEST_OVERLAY.renderSided(EnumFacing.UP, renderState, translation, pipeline); if (outputFacing != null) { Textures.PIPE_OUT_OVERLAY.renderSided(outputFacing, renderState, translation, pipeline); diff --git a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java index d6624d95823..8a569d46d60 100644 --- a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java +++ b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java @@ -266,7 +266,7 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, Textures.QUANTUM_STORAGE_RENDERER.renderMachine(renderState, translation, ArrayUtils.add(pipeline, new ColourMultiplier(GTUtility.convertRGBtoOpaqueRGBA_CL(getPaintingColorForRendering()))), - this.getFrontFacing(), this.tier); + this); Textures.QUANTUM_TANK_OVERLAY.renderSided(EnumFacing.UP, renderState, translation, pipeline); if (outputFacing != null) { Textures.PIPE_OUT_OVERLAY.renderSided(outputFacing, renderState, translation, pipeline); From adecf5b8cccaa99b17bb2e2483dc8f70153a88e0 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Mon, 1 Jan 2024 19:52:00 -0700 Subject: [PATCH 05/21] disable text render (testing) --- .../renderer/texture/custom/QuantumStorageRenderer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java index 7cd680eadf1..9771c1dd134 100644 --- a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java +++ b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java @@ -122,7 +122,7 @@ public static void renderChestStack(double x, double y, double z, MetaTileEntity GlStateManager.popMatrix(); OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240); - renderAmountText(x, y, z, count, frontFacing); +// renderAmountText(x, y, z, count, frontFacing); OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, lastBrightnessX, lastBrightnessY); } @@ -165,7 +165,7 @@ public static void renderTankAmount(double x, double y, double z, EnumFacing fro float lastBrightnessY = OpenGlHelper.lastBrightnessY; OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240); - renderAmountText(x, y, z, amount, frontFacing); +// renderAmountText(x, y, z, amount, frontFacing); OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, lastBrightnessX, lastBrightnessY); } From f6a5da6b09fb2c5ac281d56ce79c947e4c56987d Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 20 Jan 2024 09:52:13 -0700 Subject: [PATCH 06/21] add text renderer back use static variable instead of creating a new renderer every frame --- .../texture/custom/QuantumStorageRenderer.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java index 9771c1dd134..ead36059469 100644 --- a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java +++ b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java @@ -42,6 +42,8 @@ public class QuantumStorageRenderer implements TextureUtils.IIconRegister { private static final EnumMap boxFacingMap = new EnumMap<>(EnumFacing.class); + private static final TextTexture textRenderer = new TextTexture("0", 0xFFFFFF); + @SideOnly(Side.CLIENT) private TextureAtlasSprite glassTexture; @@ -122,7 +124,7 @@ public static void renderChestStack(double x, double y, double z, MetaTileEntity GlStateManager.popMatrix(); OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240); -// renderAmountText(x, y, z, count, frontFacing); + renderAmountText(x, y, z, count, frontFacing); OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, lastBrightnessX, lastBrightnessY); } @@ -165,7 +167,7 @@ public static void renderTankAmount(double x, double y, double z, EnumFacing fro float lastBrightnessY = OpenGlHelper.lastBrightnessY; OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240); -// renderAmountText(x, y, z, amount, frontFacing); + renderAmountText(x, y, z, amount, frontFacing); OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, lastBrightnessX, lastBrightnessY); } @@ -185,7 +187,9 @@ public static void renderAmountText(double x, double y, double z, long amount, E GlStateManager.scale(1f / 64, 1f / 64, 0); GlStateManager.translate(-32, -32, 0); GlStateManager.disableLighting(); - new TextTexture(amountText, 0xFFFFFF).draw(0, 24, 64, 28); + textRenderer.text = amountText; + textRenderer.setWidth(32); + textRenderer.draw(0, 24, 64, 28); GlStateManager.enableLighting(); GlStateManager.popMatrix(); } From 16532a45d9b40576910094c110a44524daedbf05 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 20 Jan 2024 10:05:58 -0700 Subject: [PATCH 07/21] only two faces are needed to render the fluid --- .../texture/custom/QuantumStorageRenderer.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java index ead36059469..628bc6f62a1 100644 --- a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java +++ b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java @@ -143,7 +143,8 @@ public static void renderTankFluid(CCRenderState renderState, Matrix4 translatio 14.9375 / 16.0, 14.9375 / 16.0); double fillFraction = (double) stack.amount / tank.getCapacity(); - if (tank.getFluid().getFluid().isGaseous()) { + boolean gas = stack.getFluid().isGaseous(); + if (gas) { partialFluidBox.min.y = Math.max(13.9375 - (11.875 * fillFraction), 2.0) / 16.0; } else { partialFluidBox.max.y = Math.min((11.875 * fillFraction) + 2.0625, 14.0) / 16.0; @@ -153,10 +154,17 @@ public static void renderTankFluid(CCRenderState renderState, Matrix4 translatio ResourceLocation fluidStill = stack.getFluid().getStill(stack); TextureAtlasSprite fluidStillSprite = Minecraft.getMinecraft().getTextureMapBlocks() .getAtlasSprite(fluidStill.toString()); - for (EnumFacing facing : EnumFacing.VALUES) { - Textures.renderFace(renderState, translation, pipeline, facing, partialFluidBox, fluidStillSprite, - BlockRenderLayer.CUTOUT_MIPPED); - } + + Textures.renderFace(renderState, translation, pipeline, frontFacing, partialFluidBox, fluidStillSprite, + BlockRenderLayer.CUTOUT_MIPPED); + + Textures.renderFace(renderState, translation, pipeline, gas ? EnumFacing.DOWN : EnumFacing.UP, partialFluidBox, fluidStillSprite, + BlockRenderLayer.CUTOUT_MIPPED); + +// for (EnumFacing facing : EnumFacing.VALUES) { +// Textures.renderFace(renderState, translation, pipeline, facing, partialFluidBox, fluidStillSprite, +// BlockRenderLayer.CUTOUT_MIPPED); +// } GlStateManager.resetColor(); renderState.reset(); From 1a012948d1d4a0227b526fabd2db057617e5c93d Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 20 Jan 2024 10:31:20 -0700 Subject: [PATCH 08/21] only schedule rerender once the fluid amount changes enough --- .../storage/MetaTileEntityQuantumTank.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java index 8a569d46d60..7db593213b6 100644 --- a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java +++ b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java @@ -40,6 +40,7 @@ import net.minecraft.util.EnumHand; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.MathHelper; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentTranslation; @@ -134,11 +135,16 @@ public void update() { updatePreviousFluid(null); } else if (previousFluid.getFluid().equals(currentFluid.getFluid()) && previousFluid.amount != currentFluid.amount) { - // tank has fluid with changed amount - previousFluid.amount = currentFluid.amount; - writeCustomData(UPDATE_FLUID_AMOUNT, buf -> buf.writeInt(currentFluid.amount)); - } else - if (!previousFluid.equals(currentFluid)) { + int currentFill = MathHelper.floor(16 * ((float) currentFluid.amount) / fluidTank.getCapacity()); + int previousFill = MathHelper.floor(16 * ((float) previousFluid.amount) / fluidTank.getCapacity()); + // tank has fluid with changed amount + previousFluid.amount = currentFluid.amount; + writeCustomData(UPDATE_FLUID_AMOUNT, buf -> { + buf.writeInt(currentFluid.amount); + buf.writeBoolean(currentFill != previousFill); + }); + + } else if (!previousFluid.equals(currentFluid)) { // tank has a different fluid from before updatePreviousFluid(currentFluid); } @@ -450,8 +456,8 @@ public void receiveCustomData(int dataId, PacketBuffer buf) { try { this.fluidTank.setFluid(FluidStack.loadFluidStackFromNBT(buf.readCompoundTag())); } catch (IOException ignored) { - GTLog.logger.warn("Failed to load fluid from NBT in a quantum tank at {} on a routine fluid update", - this.getPos()); + GTLog.logger.warn("Failed to load fluid from NBT in a quantum tank at " + this.getPos() + + " on a routine fluid update"); } scheduleRenderUpdate(); } else if (dataId == UPDATE_FLUID_AMOUNT) { From 35c56a03e1c06d7bbe5942b7fb6373c898e66484 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 20 Jan 2024 10:39:31 -0700 Subject: [PATCH 09/21] spotless why --- .../custom/QuantumStorageRenderer.java | 17 ++++++++------ .../storage/MetaTileEntityQuantumTank.java | 23 +++++++++++-------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java index 628bc6f62a1..9a4628e7b56 100644 --- a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java +++ b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java @@ -66,8 +66,10 @@ public void registerIcons(TextureMap textureMap) { .registerSprite(new ResourceLocation("gregtech:blocks/overlay/machine/overlay_screen_glass")); } - public void renderMachine(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline, - T mte) { + public void renderMachine(CCRenderState renderState, + Matrix4 translation, + IVertexOperation[] pipeline, + T mte) { EnumFacing frontFacing = mte.getFrontFacing(); int tier = mte.getTier(); Textures.renderFace(renderState, translation, pipeline, frontFacing, glassBox, glassTexture, @@ -158,13 +160,14 @@ public static void renderTankFluid(CCRenderState renderState, Matrix4 translatio Textures.renderFace(renderState, translation, pipeline, frontFacing, partialFluidBox, fluidStillSprite, BlockRenderLayer.CUTOUT_MIPPED); - Textures.renderFace(renderState, translation, pipeline, gas ? EnumFacing.DOWN : EnumFacing.UP, partialFluidBox, fluidStillSprite, + Textures.renderFace(renderState, translation, pipeline, gas ? EnumFacing.DOWN : EnumFacing.UP, partialFluidBox, + fluidStillSprite, BlockRenderLayer.CUTOUT_MIPPED); -// for (EnumFacing facing : EnumFacing.VALUES) { -// Textures.renderFace(renderState, translation, pipeline, facing, partialFluidBox, fluidStillSprite, -// BlockRenderLayer.CUTOUT_MIPPED); -// } + // for (EnumFacing facing : EnumFacing.VALUES) { + // Textures.renderFace(renderState, translation, pipeline, facing, partialFluidBox, fluidStillSprite, + // BlockRenderLayer.CUTOUT_MIPPED); + // } GlStateManager.resetColor(); renderState.reset(); diff --git a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java index 7db593213b6..8bc3036b056 100644 --- a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java +++ b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java @@ -135,16 +135,19 @@ public void update() { updatePreviousFluid(null); } else if (previousFluid.getFluid().equals(currentFluid.getFluid()) && previousFluid.amount != currentFluid.amount) { - int currentFill = MathHelper.floor(16 * ((float) currentFluid.amount) / fluidTank.getCapacity()); - int previousFill = MathHelper.floor(16 * ((float) previousFluid.amount) / fluidTank.getCapacity()); - // tank has fluid with changed amount - previousFluid.amount = currentFluid.amount; - writeCustomData(UPDATE_FLUID_AMOUNT, buf -> { - buf.writeInt(currentFluid.amount); - buf.writeBoolean(currentFill != previousFill); - }); - - } else if (!previousFluid.equals(currentFluid)) { + int currentFill = MathHelper + .floor(16 * ((float) currentFluid.amount) / fluidTank.getCapacity()); + int previousFill = MathHelper + .floor(16 * ((float) previousFluid.amount) / fluidTank.getCapacity()); + // tank has fluid with changed amount + previousFluid.amount = currentFluid.amount; + writeCustomData(UPDATE_FLUID_AMOUNT, buf -> { + buf.writeInt(currentFluid.amount); + buf.writeBoolean(currentFill != previousFill); + }); + + } else + if (!previousFluid.equals(currentFluid)) { // tank has a different fluid from before updatePreviousFluid(currentFluid); } From 3aa41a9f2fc271f966caf20a182c867cd63fa7dd Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 20 Jan 2024 11:17:08 -0700 Subject: [PATCH 10/21] add config for rendering --- .../texture/custom/QuantumStorageRenderer.java | 14 ++++++++++---- src/main/java/gregtech/common/ConfigHolder.java | 6 +++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java index 9a4628e7b56..021e55f1d3d 100644 --- a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java +++ b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java @@ -7,6 +7,7 @@ import gregtech.client.renderer.texture.Textures; import gregtech.client.renderer.texture.cube.SimpleSidedCubeRenderer.RenderSide; import gregtech.client.utils.RenderUtil; +import gregtech.common.ConfigHolder; import gregtech.common.metatileentities.storage.MetaTileEntityQuantumChest; import net.minecraft.client.Minecraft; @@ -107,7 +108,7 @@ public void renderMachine(CCR public static void renderChestStack(double x, double y, double z, MetaTileEntityQuantumChest machine, ItemStack stack, long count, float partialTicks) { - if (stack.isEmpty() || count == 0) + if (stack.isEmpty() || count == 0 || !ConfigHolder.client.enableFancyChestRender) return; float lastBrightnessX = OpenGlHelper.lastBrightnessX; @@ -132,14 +133,16 @@ public static void renderChestStack(double x, double y, double z, MetaTileEntity public static void renderTankFluid(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline, FluidTank tank, IBlockAccess world, BlockPos pos, EnumFacing frontFacing) { + FluidStack stack = tank.getFluid(); + if (stack == null || stack.amount == 0 || !ConfigHolder.client.enableFancyChestRender) + return; + float lastBrightnessX = OpenGlHelper.lastBrightnessX; float lastBrightnessY = OpenGlHelper.lastBrightnessY; + if (world != null) { renderState.setBrightness(world, pos); } - FluidStack stack = tank.getFluid(); - if (stack == null || stack.amount == 0) - return; Cuboid6 partialFluidBox = new Cuboid6(1.0625 / 16.0, 2.0625 / 16.0, 1.0625 / 16.0, 14.9375 / 16.0, 14.9375 / 16.0, 14.9375 / 16.0); @@ -184,6 +187,9 @@ public static void renderTankAmount(double x, double y, double z, EnumFacing fro } public static void renderAmountText(double x, double y, double z, long amount, EnumFacing frontFacing) { + if (!ConfigHolder.client.enableFancyChestRender) + return; + GlStateManager.pushMatrix(); GlStateManager.translate(x, y, z); GlStateManager.translate(frontFacing.getXOffset() * -1 / 16f, frontFacing.getYOffset() * -1 / 16f, diff --git a/src/main/java/gregtech/common/ConfigHolder.java b/src/main/java/gregtech/common/ConfigHolder.java index 290fb9f7d64..d4f97264240 100644 --- a/src/main/java/gregtech/common/ConfigHolder.java +++ b/src/main/java/gregtech/common/ConfigHolder.java @@ -404,7 +404,7 @@ public static class ClientOptions { @Config.Comment({ "Whether or not to enable Emissive Textures for Electric Blast Furnace Coils when the multiblock is working.", - "Default: false" }) + "Default: true" }) public boolean coilsActiveEmissiveTextures = true; @Config.Comment({ "Whether or not sounds should be played when using tools outside of crafting.", @@ -456,6 +456,10 @@ public static class ClientOptions { @Config.Comment({ "Prevent optical and laser cables from animating when active.", "Default: false" }) public boolean preventAnimatedCables = false; + @Config.Comment({"Enable the fancy rendering for Super/Quantum Chests/Tanks.", + "Default: true"}) + public boolean enableFancyChestRender = true; + public static class GuiConfig { @Config.Comment({ "The scrolling speed of widgets", "Default: 13" }) From 73a918334da949fe629d865cbe16b596a89041c0 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 20 Jan 2024 12:52:50 -0700 Subject: [PATCH 11/21] remove commented code --- .../renderer/texture/custom/QuantumStorageRenderer.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java index 021e55f1d3d..46ad00ea24d 100644 --- a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java +++ b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java @@ -167,10 +167,6 @@ public static void renderTankFluid(CCRenderState renderState, Matrix4 translatio fluidStillSprite, BlockRenderLayer.CUTOUT_MIPPED); - // for (EnumFacing facing : EnumFacing.VALUES) { - // Textures.renderFace(renderState, translation, pipeline, facing, partialFluidBox, fluidStillSprite, - // BlockRenderLayer.CUTOUT_MIPPED); - // } GlStateManager.resetColor(); renderState.reset(); From 4baa845187631743af727aee1613b0188507dd67 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 20 Jan 2024 13:36:34 -0700 Subject: [PATCH 12/21] don't render fast tesr if player is too far --- .../metatileentities/storage/MetaTileEntityQuantumTank.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java index 8bc3036b056..e20a45fb1d4 100644 --- a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java +++ b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java @@ -291,6 +291,12 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, public void renderMetaTileEntity(double x, double y, double z, float partialTicks) { if (this.fluidTank.getFluid() == null || this.fluidTank.getFluid().amount == 0) return; + + int range = 9; + if (x > range || y > range || z > range || + x < -range || y < -range ||z < -range) + return; + QuantumStorageRenderer.renderTankAmount(x, y, z, this.getFrontFacing(), this.fluidTank.getFluid().amount); } From 0617b5583d26d6c212ee5b9f0c5f218b79f2013d Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 20 Jan 2024 22:26:27 -0700 Subject: [PATCH 13/21] move range check to better places --- .../texture/custom/QuantumStorageRenderer.java | 10 ++++++++++ .../storage/MetaTileEntityQuantumTank.java | 5 ----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java index 46ad00ea24d..bcb54836344 100644 --- a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java +++ b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java @@ -111,6 +111,11 @@ public static void renderChestStack(double x, double y, double z, MetaTileEntity if (stack.isEmpty() || count == 0 || !ConfigHolder.client.enableFancyChestRender) return; + int range = 9; + if (x > range || y > range || z > range || + x < -range || y < -range ||z < -range) + return; + float lastBrightnessX = OpenGlHelper.lastBrightnessX; float lastBrightnessY = OpenGlHelper.lastBrightnessY; World world = machine.getWorld(); @@ -173,6 +178,11 @@ public static void renderTankFluid(CCRenderState renderState, Matrix4 translatio } public static void renderTankAmount(double x, double y, double z, EnumFacing frontFacing, long amount) { + int range = 9; + if (x > range || y > range || z > range || + x < -range || y < -range ||z < -range) + return; + float lastBrightnessX = OpenGlHelper.lastBrightnessX; float lastBrightnessY = OpenGlHelper.lastBrightnessY; OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240); diff --git a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java index e20a45fb1d4..526ea3e1acf 100644 --- a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java +++ b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java @@ -292,11 +292,6 @@ public void renderMetaTileEntity(double x, double y, double z, float partialTick if (this.fluidTank.getFluid() == null || this.fluidTank.getFluid().amount == 0) return; - int range = 9; - if (x > range || y > range || z > range || - x < -range || y < -range ||z < -range) - return; - QuantumStorageRenderer.renderTankAmount(x, y, z, this.getFrontFacing(), this.fluidTank.getFluid().amount); } From db98576574c2145399fbe85b3e4d0caa8a44fd13 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sun, 21 Jan 2024 17:08:00 -0700 Subject: [PATCH 14/21] some improvements to TextTexture --- .../api/gui/resources/TextTexture.java | 29 +++++++++++++++---- .../custom/QuantumStorageRenderer.java | 5 ++-- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/main/java/gregtech/api/gui/resources/TextTexture.java b/src/main/java/gregtech/api/gui/resources/TextTexture.java index 19928d07c8b..3f4ca1da91d 100644 --- a/src/main/java/gregtech/api/gui/resources/TextTexture.java +++ b/src/main/java/gregtech/api/gui/resources/TextTexture.java @@ -20,16 +20,26 @@ public class TextTexture implements IGuiTexture { public TextType type; @SideOnly(Side.CLIENT) private List texts; + private final boolean isClient = FMLCommonHandler.instance().getSide().isClient(); public TextTexture(String text, int color) { this.color = color; this.type = TextType.NORMAL; - if (FMLCommonHandler.instance().getSide().isClient()) { + if (isClient) { this.text = I18n.format(text); texts = Collections.singletonList(this.text); } } + public TextTexture() { + this.color = 0xFFFFFF; + this.type = TextType.NORMAL; + this.text = ""; + + if (isClient) + this.texts = Collections.singletonList(this.text); + } + public TextTexture setColor(int color) { this.color = color; return this; @@ -42,11 +52,18 @@ public TextTexture setDropShadow(boolean dropShadow) { public TextTexture setWidth(int width) { this.width = width; - if (FMLCommonHandler.instance().getSide().isClient()) { - if (this.width > 0) { - texts = Minecraft.getMinecraft().fontRenderer.listFormattedStringToWidth(text, width); - } else { - texts = Collections.singletonList(text); + return this; + } + + public TextTexture setText(String text) { + if (this.text.isEmpty() || !this.text.equals(text)) { + this.text = text; + if (isClient) { + if (this.width > 0) { + texts = Minecraft.getMinecraft().fontRenderer.listFormattedStringToWidth(text, width); + } else { + texts = Collections.singletonList(text); + } } } return this; diff --git a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java index bcb54836344..a4ccecccaf2 100644 --- a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java +++ b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java @@ -43,7 +43,7 @@ public class QuantumStorageRenderer implements TextureUtils.IIconRegister { private static final EnumMap boxFacingMap = new EnumMap<>(EnumFacing.class); - private static final TextTexture textRenderer = new TextTexture("0", 0xFFFFFF); + private static final TextTexture textRenderer = new TextTexture().setWidth(32); @SideOnly(Side.CLIENT) private TextureAtlasSprite glassTexture; @@ -210,8 +210,7 @@ public static void renderAmountText(double x, double y, double z, long amount, E GlStateManager.scale(1f / 64, 1f / 64, 0); GlStateManager.translate(-32, -32, 0); GlStateManager.disableLighting(); - textRenderer.text = amountText; - textRenderer.setWidth(32); + textRenderer.setText(amountText); textRenderer.draw(0, 24, 64, 28); GlStateManager.enableLighting(); GlStateManager.popMatrix(); From 9199a234aeab2b6a9dd834322dbed021f7c238ee Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 20 Feb 2024 01:25:42 -0700 Subject: [PATCH 15/21] sboblss --- .../renderer/texture/custom/QuantumStorageRenderer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java index a4ccecccaf2..0c1a1096a8c 100644 --- a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java +++ b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java @@ -113,7 +113,7 @@ public static void renderChestStack(double x, double y, double z, MetaTileEntity int range = 9; if (x > range || y > range || z > range || - x < -range || y < -range ||z < -range) + x < -range || y < -range || z < -range) return; float lastBrightnessX = OpenGlHelper.lastBrightnessX; @@ -180,7 +180,7 @@ public static void renderTankFluid(CCRenderState renderState, Matrix4 translatio public static void renderTankAmount(double x, double y, double z, EnumFacing frontFacing, long amount) { int range = 9; if (x > range || y > range || z > range || - x < -range || y < -range ||z < -range) + x < -range || y < -range || z < -range) return; float lastBrightnessX = OpenGlHelper.lastBrightnessX; From 81f17e9e2a4698f9eb73b4d26b6842fc9d025399 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Wed, 20 Mar 2024 11:52:43 -0700 Subject: [PATCH 16/21] address reviews --- src/main/java/gregtech/api/gui/resources/TextTexture.java | 2 +- src/main/java/gregtech/common/ConfigHolder.java | 4 ++-- .../storage/MetaTileEntityQuantumTank.java | 8 +++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/gregtech/api/gui/resources/TextTexture.java b/src/main/java/gregtech/api/gui/resources/TextTexture.java index 3f4ca1da91d..2750890d749 100644 --- a/src/main/java/gregtech/api/gui/resources/TextTexture.java +++ b/src/main/java/gregtech/api/gui/resources/TextTexture.java @@ -56,7 +56,7 @@ public TextTexture setWidth(int width) { } public TextTexture setText(String text) { - if (this.text.isEmpty() || !this.text.equals(text)) { + if (!this.text.equals(text)) { this.text = text; if (isClient) { if (this.width > 0) { diff --git a/src/main/java/gregtech/common/ConfigHolder.java b/src/main/java/gregtech/common/ConfigHolder.java index d4f97264240..caf04defc48 100644 --- a/src/main/java/gregtech/common/ConfigHolder.java +++ b/src/main/java/gregtech/common/ConfigHolder.java @@ -456,8 +456,8 @@ public static class ClientOptions { @Config.Comment({ "Prevent optical and laser cables from animating when active.", "Default: false" }) public boolean preventAnimatedCables = false; - @Config.Comment({"Enable the fancy rendering for Super/Quantum Chests/Tanks.", - "Default: true"}) + @Config.Comment({ "Enable the fancy rendering for Super/Quantum Chests/Tanks.", + "Default: true" }) public boolean enableFancyChestRender = true; public static class GuiConfig { diff --git a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java index 526ea3e1acf..7e5d244f556 100644 --- a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java +++ b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java @@ -460,17 +460,19 @@ public void receiveCustomData(int dataId, PacketBuffer buf) { try { this.fluidTank.setFluid(FluidStack.loadFluidStackFromNBT(buf.readCompoundTag())); } catch (IOException ignored) { - GTLog.logger.warn("Failed to load fluid from NBT in a quantum tank at " + this.getPos() + - " on a routine fluid update"); + GTLog.logger.warn("Failed to load fluid from NBT in a quantum tank at {} on a routine fluid update", + this.getPos()); } scheduleRenderUpdate(); } else if (dataId == UPDATE_FLUID_AMOUNT) { // amount must always be read even if it cannot be used to ensure the reader index advances int amount = buf.readInt(); + boolean updateRendering = buf.readBoolean(); FluidStack stack = fluidTank.getFluid(); if (stack != null) { stack.amount = Math.min(amount, fluidTank.getCapacity()); - scheduleRenderUpdate(); + if (updateRendering) + scheduleRenderUpdate(); } } else if (dataId == UPDATE_IS_VOIDING) { setVoiding(buf.readBoolean()); From 00ddf444f0171aa0dbc311188ebf0b36e32aff37 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Wed, 27 Mar 2024 14:25:24 -0700 Subject: [PATCH 17/21] increase range to a chunk --- .../renderer/texture/custom/QuantumStorageRenderer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java index 0c1a1096a8c..9fe28734937 100644 --- a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java +++ b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java @@ -111,7 +111,7 @@ public static void renderChestStack(double x, double y, double z, MetaTileEntity if (stack.isEmpty() || count == 0 || !ConfigHolder.client.enableFancyChestRender) return; - int range = 9; + int range = 16; if (x > range || y > range || z > range || x < -range || y < -range || z < -range) return; @@ -178,7 +178,7 @@ public static void renderTankFluid(CCRenderState renderState, Matrix4 translatio } public static void renderTankAmount(double x, double y, double z, EnumFacing frontFacing, long amount) { - int range = 9; + int range = 16; if (x > range || y > range || z > range || x < -range || y < -range || z < -range) return; From 870939968e25284338be26bc1f844a94e76cd1fe Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Wed, 27 Mar 2024 14:53:32 -0700 Subject: [PATCH 18/21] mimic item entity rendering for distance calculation --- .../custom/QuantumStorageRenderer.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java index 9fe28734937..7e571748d01 100644 --- a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java +++ b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java @@ -22,6 +22,7 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.fluids.FluidStack; @@ -108,12 +109,7 @@ public void renderMachine(CCR public static void renderChestStack(double x, double y, double z, MetaTileEntityQuantumChest machine, ItemStack stack, long count, float partialTicks) { - if (stack.isEmpty() || count == 0 || !ConfigHolder.client.enableFancyChestRender) - return; - - int range = 16; - if (x > range || y > range || z > range || - x < -range || y < -range || z < -range) + if (!ConfigHolder.client.enableFancyChestRender || stack.isEmpty() || count == 0 || !canRender(x, y, z)) return; float lastBrightnessX = OpenGlHelper.lastBrightnessX; @@ -177,10 +173,19 @@ public static void renderTankFluid(CCRenderState renderState, Matrix4 translatio renderState.reset(); } + public static boolean canRender(double x, double y, double z) { + double distance = (x * x) + (y * y) + (z * z); + return canRender(distance); + } + + public static boolean canRender(double distanceSq) { + double range = 8 * + MathHelper.clamp((double) Minecraft.getMinecraft().gameSettings.renderDistanceChunks / 8, 1.0, 2.5); + return distanceSq < range * range; + } + public static void renderTankAmount(double x, double y, double z, EnumFacing frontFacing, long amount) { - int range = 16; - if (x > range || y > range || z > range || - x < -range || y < -range || z < -range) + if (!canRender(x, y, z)) return; float lastBrightnessX = OpenGlHelper.lastBrightnessX; From 280f4fe767cdca09a6b86fabe988445601f702b5 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:18:02 -0700 Subject: [PATCH 19/21] improve render distance calculation to mimic sign render distance as well split rendering of text and chest stack --- .../custom/QuantumStorageRenderer.java | 40 ++++++++----------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java index 7e571748d01..f579d59e171 100644 --- a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java +++ b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java @@ -109,7 +109,7 @@ public void renderMachine(CCR public static void renderChestStack(double x, double y, double z, MetaTileEntityQuantumChest machine, ItemStack stack, long count, float partialTicks) { - if (!ConfigHolder.client.enableFancyChestRender || stack.isEmpty() || count == 0 || !canRender(x, y, z)) + if (!ConfigHolder.client.enableFancyChestRender || stack.isEmpty() || count == 0) return; float lastBrightnessX = OpenGlHelper.lastBrightnessX; @@ -117,15 +117,18 @@ public static void renderChestStack(double x, double y, double z, MetaTileEntity World world = machine.getWorld(); setLightingCorrectly(world, machine.getPos()); EnumFacing frontFacing = machine.getFrontFacing(); - RenderItem itemRenderer = Minecraft.getMinecraft().getRenderItem(); - float tick = world.getWorldTime() + partialTicks; - GlStateManager.pushMatrix(); - GlStateManager.translate(x, y, z); - GlStateManager.translate(0.5D, 0.5D, 0.5D); - GlStateManager.rotate(tick * (float) Math.PI * 2 / 40, 0, 1, 0); - GlStateManager.scale(0.6f, 0.6f, 0.6f); - itemRenderer.renderItem(stack, ItemCameraTransforms.TransformType.FIXED); - GlStateManager.popMatrix(); + + if (canRender(x, y, z, 8 * MathHelper.clamp((double) Minecraft.getMinecraft().gameSettings.renderDistanceChunks / 8, 1.0, 2.5))) { + RenderItem itemRenderer = Minecraft.getMinecraft().getRenderItem(); + float tick = world.getWorldTime() + partialTicks; + GlStateManager.pushMatrix(); + GlStateManager.translate(x, y, z); + GlStateManager.translate(0.5D, 0.5D, 0.5D); + GlStateManager.rotate(tick * (float) Math.PI * 2 / 40, 0, 1, 0); + GlStateManager.scale(0.6f, 0.6f, 0.6f); + itemRenderer.renderItem(stack, ItemCameraTransforms.TransformType.FIXED); + GlStateManager.popMatrix(); + } OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240); renderAmountText(x, y, z, count, frontFacing); @@ -138,9 +141,6 @@ public static void renderTankFluid(CCRenderState renderState, Matrix4 translatio if (stack == null || stack.amount == 0 || !ConfigHolder.client.enableFancyChestRender) return; - float lastBrightnessX = OpenGlHelper.lastBrightnessX; - float lastBrightnessY = OpenGlHelper.lastBrightnessY; - if (world != null) { renderState.setBrightness(world, pos); } @@ -173,20 +173,12 @@ public static void renderTankFluid(CCRenderState renderState, Matrix4 translatio renderState.reset(); } - public static boolean canRender(double x, double y, double z) { + public static boolean canRender(double x, double y, double z, double range) { double distance = (x * x) + (y * y) + (z * z); - return canRender(distance); - } - - public static boolean canRender(double distanceSq) { - double range = 8 * - MathHelper.clamp((double) Minecraft.getMinecraft().gameSettings.renderDistanceChunks / 8, 1.0, 2.5); - return distanceSq < range * range; + return distance < range * range; } public static void renderTankAmount(double x, double y, double z, EnumFacing frontFacing, long amount) { - if (!canRender(x, y, z)) - return; float lastBrightnessX = OpenGlHelper.lastBrightnessX; float lastBrightnessY = OpenGlHelper.lastBrightnessY; @@ -198,7 +190,7 @@ public static void renderTankAmount(double x, double y, double z, EnumFacing fro } public static void renderAmountText(double x, double y, double z, long amount, EnumFacing frontFacing) { - if (!ConfigHolder.client.enableFancyChestRender) + if (!ConfigHolder.client.enableFancyChestRender || !canRender(x, y, z, 64)) return; GlStateManager.pushMatrix(); From 2e38708446ce1ef12b44651fe88f1162be0e3ed3 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:18:44 -0700 Subject: [PATCH 20/21] sbobl --- .../renderer/texture/custom/QuantumStorageRenderer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java index f579d59e171..37c7a7d82d1 100644 --- a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java +++ b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java @@ -118,7 +118,8 @@ public static void renderChestStack(double x, double y, double z, MetaTileEntity setLightingCorrectly(world, machine.getPos()); EnumFacing frontFacing = machine.getFrontFacing(); - if (canRender(x, y, z, 8 * MathHelper.clamp((double) Minecraft.getMinecraft().gameSettings.renderDistanceChunks / 8, 1.0, 2.5))) { + if (canRender(x, y, z, 8 * + MathHelper.clamp((double) Minecraft.getMinecraft().gameSettings.renderDistanceChunks / 8, 1.0, 2.5))) { RenderItem itemRenderer = Minecraft.getMinecraft().getRenderItem(); float tick = world.getWorldTime() + partialTicks; GlStateManager.pushMatrix(); @@ -179,7 +180,6 @@ public static boolean canRender(double x, double y, double z, double range) { } public static void renderTankAmount(double x, double y, double z, EnumFacing frontFacing, long amount) { - float lastBrightnessX = OpenGlHelper.lastBrightnessX; float lastBrightnessY = OpenGlHelper.lastBrightnessY; OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240); From 7c2d6908d828bdd7273cc15d2bf74ab6ae369392 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:23:05 -0700 Subject: [PATCH 21/21] javadoc --- .../texture/custom/QuantumStorageRenderer.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java index 37c7a7d82d1..c5379c4e3af 100644 --- a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java +++ b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java @@ -174,6 +174,16 @@ public static void renderTankFluid(CCRenderState renderState, Matrix4 translatio renderState.reset(); } + /** + * Takes in the difference in x, y, and z from the camera to the rendering TE and + * calculates the squared distance and checks if it's within the range squared + * + * @param x the difference in x from entity to this rendering TE + * @param y the difference in y from entity to this rendering TE + * @param z the difference in z from entity to this rendering TE + * @param range distance needed to be rendered + * @return true if the camera is within the given range, otherwise false + */ public static boolean canRender(double x, double y, double z, double range) { double distance = (x * x) + (y * y) + (z * z); return distance < range * range;