Skip to content

Commit

Permalink
Fix chest flickering when a barrel is in sight (#33)
Browse files Browse the repository at this point in the history
* fix chest flickering

* refactor which should not change anything
  • Loading branch information
Quarri6343 authored Jul 7, 2024
1 parent 6435914 commit ea798c4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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 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, cachedAmbientColor);
}

public static void enableStandardItemLighting() {
GL11.glEnable(GL11.GL_COLOR_MATERIAL);
GL11.glColorMaterial(GL11.GL_FRONT_AND_BACK, GL11.GL_AMBIENT_AND_DIFFUSE);
GL11.glShadeModel(GL11.GL_FLAT);
GL11.glGetFloat(GL11.GL_LIGHT_MODEL_AMBIENT, cachedAmbientColor);
GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, ambientColorBuffer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -186,6 +185,6 @@ private void renderItemIntoGUIBlock(FontRenderer fontRenderer, TextureManager te

GL11.glPopMatrix();

RenderHelper.disableStandardItemLighting();
SurfaceItemRenderHelper.disableStandardItemLighting();
}
}

0 comments on commit ea798c4

Please sign in to comment.