Skip to content

Commit

Permalink
fix: memory leak
Browse files Browse the repository at this point in the history
Closes #1227
  • Loading branch information
klikli-dev committed Oct 8, 2024
1 parent 9255cf2 commit dd0187b
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,23 @@
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.world.entity.EntityType;

import java.lang.ref.WeakReference;

public class SpiritRenderable<T extends SpiritEntity> implements EmiRenderable{
T spiritEntity;

public class SpiritRenderable<T extends SpiritEntity> implements EmiRenderable {
WeakReference<T> spiritEntity;
EntityType<T> spiritType;

public SpiritRenderable(EntityType<T> spiritType) {
this.spiritType=spiritType;
this.spiritType = spiritType;
}

@Override
public void render(GuiGraphics draw, int x, int y, float delta) {
if(spiritEntity==null)
spiritEntity= (T) spiritType.create(Minecraft.getInstance().level);
SpiritGui.drawEntityToGui(draw, (int) (x+8),(int)(y+(spiritEntity.getEyeHeight()*15)+5),15,1,1,spiritEntity);
if (this.spiritEntity == null || this.spiritEntity.get() == null)
this.spiritEntity = new WeakReference(this.spiritType.create(Minecraft.getInstance().level));


SpiritGui.drawEntityToGui(draw, x + 8, (int) (y + (this.spiritEntity.get().getEyeHeight() * 15) + 5), 15, 1, 1, this.spiritEntity.get());
}
}

0 comments on commit dd0187b

Please sign in to comment.