Skip to content

Commit

Permalink
Use display lists for heart rendering. Closes #12
Browse files Browse the repository at this point in the history
This worked *perfect* first try. I'm scared.
  • Loading branch information
unascribed committed Sep 25, 2017
1 parent d80aa11 commit 3bf19b4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class ClientProxy extends CommonProxy {
private List<TileEntityGlassHeart> glassHearts = Lists.newArrayList();
public List<GuiParticle> guiParticles = Lists.newArrayList();

public static int ticks;

@Override
public void onPreInit() {
super.onPreInit();
Expand Down Expand Up @@ -169,6 +171,7 @@ public void onTooltip(ItemTooltipEvent e) {
public void onTick(ClientTickEvent e) {
if (e.phase == Phase.START) {
if (!Minecraft.getMinecraft().isGamePaused()) {
ticks++;
Minecraft.getMinecraft().mcProfiler.startSection("glasshearts:guiparticlesupdate"); {
Iterator<GuiParticle> iter = guiParticles.iterator();
while (iter.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@

public class RenderGlassHeart extends TileEntitySpecialRenderer<TileEntityGlassHeart> {

private int[] displayLists = new int[EnumGlassColor.values().length];
private int[] lastHash = new int[EnumGlassColor.values().length];

public static float getAnimTime(TileEntityGlassHeart te, float partialTicks) {
return (((te.getWorld().getTotalWorldTime()+te.hashCode())%24000)+partialTicks);
return (((ClientProxy.ticks+te.hashCode())%24000)+partialTicks);
}

@Override
Expand All @@ -45,6 +48,25 @@ public void render(TileEntityGlassHeart te, double x, double y, double z, float
IBlockState outerState = GlassHearts.inst.GLASS_HEART.getDefaultState().withProperty(BlockGlassHeart.INNER, false).withProperty(BlockGlassHeart.STAINED, stained);

IBakedModel outer = brd.getModelForState(outerState);

int listIdx = te.getColor().ordinal();
int hash = outer.hashCode();

if (lastHash[listIdx] != hash || displayLists[listIdx] == 0) {
if (displayLists[listIdx] != 0) {
GlStateManager.glDeleteLists(displayLists[listIdx], 1);
}
displayLists[listIdx] = GlStateManager.glGenLists(1);
lastHash[listIdx] = hash;
GlStateManager.glNewList(displayLists[listIdx], GL11.GL_COMPILE);
if (stained) {
float[] color = EntitySheep.getDyeRgb(te.getColor().dye);
bmr.renderModelBrightnessColor(outerState, outer, 1f, color[0], color[1], color[2]);
} else {
bmr.renderModelBrightnessColor(outerState, outer, 1f, 1f, 1f, 1f);
}
GlStateManager.glEndList();
}

bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
GlStateManager.pushMatrix();
Expand Down Expand Up @@ -108,7 +130,6 @@ public void render(TileEntityGlassHeart te, double x, double y, double z, float
GlStateManager.popMatrix();
}


if (stained) {
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA,
Expand All @@ -118,10 +139,9 @@ public void render(TileEntityGlassHeart te, double x, double y, double z, float
GlStateManager.disableBlend();
}
if (stained && MinecraftForgeClient.getRenderPass() == 1) {
float[] color = EntitySheep.getDyeRgb(te.getColor().dye);
bmr.renderModelBrightnessColor(outerState, outer, 1f, color[0], color[1], color[2]);
GlStateManager.callList(displayLists[listIdx]);
} else if (MinecraftForgeClient.getRenderPass() == 0) {
bmr.renderModelBrightnessColor(outerState, outer, 1f, 1f, 1f, 1f);
GlStateManager.callList(displayLists[listIdx]);
}
GlStateManager.disableRescaleNormal();
GlStateManager.disableBlend();
Expand Down

0 comments on commit 3bf19b4

Please sign in to comment.