From 7d8e9b6a94bf58eac4ebe50443810e8e8368f785 Mon Sep 17 00:00:00 2001 From: Quarri6343 Date: Wed, 29 May 2024 20:55:27 +0900 Subject: [PATCH 1/2] fix chest flickering --- .../render/SurfaceItemRenderHelper.java | 37 +++++++++++++++++++ .../client/render/SurfaceItemRenderer.java | 5 +-- 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 src/main/java/mcp/mobius/betterbarrels/client/render/SurfaceItemRenderHelper.java diff --git a/src/main/java/mcp/mobius/betterbarrels/client/render/SurfaceItemRenderHelper.java b/src/main/java/mcp/mobius/betterbarrels/client/render/SurfaceItemRenderHelper.java new file mode 100644 index 0000000..31794be --- /dev/null +++ b/src/main/java/mcp/mobius/betterbarrels/client/render/SurfaceItemRenderHelper.java @@ -0,0 +1,37 @@ +package mcp.mobius.betterbarrels.client.render; + +import java.nio.FloatBuffer; + +import net.minecraft.client.renderer.GLAllocation; + +import org.lwjgl.opengl.GL11; + +/** + * RenderHelper but no directional light setting + */ +public class SurfaceItemRenderHelper { + + private static FloatBuffer colorBuffer = GLAllocation.createDirectFloatBuffer(16); + private static FloatBuffer cachedLightSetting = GLAllocation.createDirectFloatBuffer(16); + + public static void disableStandardItemLighting() { + GL11.glDisable(GL11.GL_COLOR_MATERIAL); + GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, cachedLightSetting); + } + + public static void enableStandardItemLighting() { + GL11.glEnable(GL11.GL_COLOR_MATERIAL); + GL11.glColorMaterial(GL11.GL_FRONT_AND_BACK, GL11.GL_AMBIENT_AND_DIFFUSE); + float f = 0.4F; + GL11.glShadeModel(GL11.GL_FLAT); + GL11.glGetFloat(GL11.GL_LIGHT_MODEL_AMBIENT, cachedLightSetting); + GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, setColorBuffer(f, f, f, 1.0F)); + } + + private static FloatBuffer setColorBuffer(float p_74521_0_, float p_74521_1_, float p_74521_2_, float p_74521_3_) { + colorBuffer.clear(); + colorBuffer.put(p_74521_0_).put(p_74521_1_).put(p_74521_2_).put(p_74521_3_); + colorBuffer.flip(); + return colorBuffer; + } +} diff --git a/src/main/java/mcp/mobius/betterbarrels/client/render/SurfaceItemRenderer.java b/src/main/java/mcp/mobius/betterbarrels/client/render/SurfaceItemRenderer.java index 784808f..4c4eb59 100644 --- a/src/main/java/mcp/mobius/betterbarrels/client/render/SurfaceItemRenderer.java +++ b/src/main/java/mcp/mobius/betterbarrels/client/render/SurfaceItemRenderer.java @@ -5,7 +5,6 @@ import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.client.renderer.texture.TextureManager; @@ -142,7 +141,7 @@ private void renderGlint(int x, int y, int w, int h) { private void renderItemIntoGUIBlock(FontRenderer fontRenderer, TextureManager texManager, ItemStack itemStack, int x, int y, boolean renderEffect) { - RenderHelper.enableGUIStandardItemLighting(); + SurfaceItemRenderHelper.enableStandardItemLighting(); GL11.glDisable(GL11.GL_LIGHTING); texManager.bindTexture(TextureMap.locationBlocksTexture); @@ -186,6 +185,6 @@ private void renderItemIntoGUIBlock(FontRenderer fontRenderer, TextureManager te GL11.glPopMatrix(); - RenderHelper.disableStandardItemLighting(); + SurfaceItemRenderHelper.disableStandardItemLighting(); } } From 409e4237c6b343b7188af99df6bad7a6afd9ce06 Mon Sep 17 00:00:00 2001 From: Quarri6343 Date: Wed, 29 May 2024 21:15:27 +0900 Subject: [PATCH 2/2] refactor which should not change anything --- .../render/SurfaceItemRenderHelper.java | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/main/java/mcp/mobius/betterbarrels/client/render/SurfaceItemRenderHelper.java b/src/main/java/mcp/mobius/betterbarrels/client/render/SurfaceItemRenderHelper.java index 31794be..11c59cd 100644 --- a/src/main/java/mcp/mobius/betterbarrels/client/render/SurfaceItemRenderHelper.java +++ b/src/main/java/mcp/mobius/betterbarrels/client/render/SurfaceItemRenderHelper.java @@ -11,27 +11,20 @@ */ public class SurfaceItemRenderHelper { - private static FloatBuffer colorBuffer = GLAllocation.createDirectFloatBuffer(16); - private static FloatBuffer cachedLightSetting = GLAllocation.createDirectFloatBuffer(16); + private static final FloatBuffer ambientColorBuffer = (FloatBuffer) GLAllocation.createDirectFloatBuffer(16) + .put(0.4f).put(0.4f).put(0.4f).put(1.0f).flip(); + private static final FloatBuffer cachedAmbientColor = GLAllocation.createDirectFloatBuffer(16); public static void disableStandardItemLighting() { GL11.glDisable(GL11.GL_COLOR_MATERIAL); - GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, cachedLightSetting); + GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, cachedAmbientColor); } public static void enableStandardItemLighting() { GL11.glEnable(GL11.GL_COLOR_MATERIAL); GL11.glColorMaterial(GL11.GL_FRONT_AND_BACK, GL11.GL_AMBIENT_AND_DIFFUSE); - float f = 0.4F; GL11.glShadeModel(GL11.GL_FLAT); - GL11.glGetFloat(GL11.GL_LIGHT_MODEL_AMBIENT, cachedLightSetting); - GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, setColorBuffer(f, f, f, 1.0F)); - } - - private static FloatBuffer setColorBuffer(float p_74521_0_, float p_74521_1_, float p_74521_2_, float p_74521_3_) { - colorBuffer.clear(); - colorBuffer.put(p_74521_0_).put(p_74521_1_).put(p_74521_2_).put(p_74521_3_); - colorBuffer.flip(); - return colorBuffer; + GL11.glGetFloat(GL11.GL_LIGHT_MODEL_AMBIENT, cachedAmbientColor); + GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, ambientColorBuffer); } }