Skip to content

Commit

Permalink
fix chest flickering
Browse files Browse the repository at this point in the history
  • Loading branch information
Quarri6343 committed May 29, 2024
1 parent 6435914 commit 7d8e9b6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
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 7d8e9b6

Please sign in to comment.