diff --git a/src/main/java/gregtech/api/gui/resources/TextTexture.java b/src/main/java/gregtech/api/gui/resources/TextTexture.java index 19928d07c8b..2750890d749 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.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/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) { 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..c5379c4e3af 100644 --- a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java +++ b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java @@ -1,10 +1,13 @@ 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; import gregtech.client.utils.RenderUtil; +import gregtech.common.ConfigHolder; import gregtech.common.metatileentities.storage.MetaTileEntityQuantumChest; import net.minecraft.client.Minecraft; @@ -19,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; @@ -40,6 +44,8 @@ public class QuantumStorageRenderer implements TextureUtils.IIconRegister { private static final EnumMap boxFacingMap = new EnumMap<>(EnumFacing.class); + private static final TextTexture textRenderer = new TextTexture().setWidth(32); + @SideOnly(Side.CLIENT) private TextureAtlasSprite glassTexture; @@ -62,30 +68,48 @@ 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); 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, - 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, ItemStack stack, long count, float partialTicks) { - if (stack.isEmpty() || count == 0) + if (!ConfigHolder.client.enableFancyChestRender || stack.isEmpty() || count == 0) return; float lastBrightnessX = OpenGlHelper.lastBrightnessX; @@ -93,15 +117,19 @@ 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); @@ -110,20 +138,20 @@ 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) { - float lastBrightnessX = OpenGlHelper.lastBrightnessX; - float lastBrightnessY = OpenGlHelper.lastBrightnessY; + FluidStack stack = tank.getFluid(); + if (stack == null || stack.amount == 0 || !ConfigHolder.client.enableFancyChestRender) + return; + 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); 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; @@ -133,15 +161,34 @@ 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); + GlStateManager.resetColor(); 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; + } + public static void renderTankAmount(double x, double y, double z, EnumFacing frontFacing, long amount) { float lastBrightnessX = OpenGlHelper.lastBrightnessX; float lastBrightnessY = OpenGlHelper.lastBrightnessY; @@ -153,6 +200,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 || !canRender(x, y, z, 64)) + return; + GlStateManager.pushMatrix(); GlStateManager.translate(x, y, z); GlStateManager.translate(frontFacing.getXOffset() * -1 / 16f, frontFacing.getYOffset() * -1 / 16f, @@ -167,7 +217,8 @@ 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.setText(amountText); + textRenderer.draw(0, 24, 64, 28); GlStateManager.enableLighting(); GlStateManager.popMatrix(); } diff --git a/src/main/java/gregtech/common/ConfigHolder.java b/src/main/java/gregtech/common/ConfigHolder.java index 290fb9f7d64..caf04defc48 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" }) 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..7e5d244f556 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,9 +135,17 @@ 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)); + 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 @@ -266,7 +275,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); @@ -282,6 +291,7 @@ 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; + QuantumStorageRenderer.renderTankAmount(x, y, z, this.getFrontFacing(), this.fluidTank.getFluid().amount); } @@ -457,10 +467,12 @@ public void receiveCustomData(int dataId, PacketBuffer buf) { } 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());