Skip to content

Commit

Permalink
Fix Escritoire Crash when loading minecraft
Browse files Browse the repository at this point in the history
  • Loading branch information
Nedelosk committed Sep 28, 2018
1 parent 1dbff62 commit 813c382
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/main/java/forestry/core/render/RenderAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ private void render(ItemStack itemstack, @Nullable World world, EnumFacing orien
return;
}
EntityItem dummyItem = dummyItem(world);
dummyItem.world = world;
float renderScale = 1.0f;

GlStateManager.pushMatrix();
Expand Down
22 changes: 16 additions & 6 deletions src/main/java/forestry/core/render/RenderEscritoire.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,19 @@ public class RenderEscritoire extends TileEntitySpecialRenderer<TileEscritoire>

private static final ResourceLocation texture = new ForestryResource(Constants.TEXTURE_PATH_BLOCKS + "/escritoire.png");
private final ModelEscritoire modelEscritoire = new ModelEscritoire();
private final EntityItem dummyEntityItem = new EntityItem(null);
@Nullable
private EntityItem dummyEntityItem;
private long lastTick;

private EntityItem dummyItem(World world){
if(dummyEntityItem == null){
dummyEntityItem = new EntityItem(world);
}else{
dummyEntityItem.world = world;
}
return dummyEntityItem;
}

/**
* @param escritoire If it null its render the item else it render the tile entity.
*/
Expand Down Expand Up @@ -87,27 +97,27 @@ private void render(ItemStack itemstack, @Nullable World world, EnumFacing orien
GlStateManager.popMatrix();

if (!itemstack.isEmpty() && world != null) {
dummyEntityItem.world = world;
EntityItem dummyItem = dummyItem(world);

float renderScale = 0.75f;

GlStateManager.pushMatrix();
{
GlStateManager.translate((float) x + 0.5f, (float) y + 0.6f, (float) z + 0.5f);
GlStateManager.scale(renderScale, renderScale, renderScale);
dummyEntityItem.setItem(itemstack);
dummyItem.setItem(itemstack);

if (world.getTotalWorldTime() != lastTick) {
lastTick = world.getTotalWorldTime();
dummyEntityItem.onUpdate();
dummyItem.onUpdate();
}

RenderManager rendermanager = minecraft.getRenderManager();
rendermanager.renderEntity(dummyEntityItem, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F, false);
rendermanager.renderEntity(dummyItem, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F, false);
}
GlStateManager.popMatrix();

dummyEntityItem.world = null; // prevent leaking the world object
dummyItem.world = null; // prevent leaking the world object
}
}
}

0 comments on commit 813c382

Please sign in to comment.