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 782513f commit 7331811
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
package com.klikli_dev.occultism.integration.emi.render;

import com.klikli_dev.occultism.client.gui.spirit.SpiritGui;
import com.klikli_dev.occultism.common.entity.spirit.FoliotEntity;
import com.klikli_dev.occultism.common.entity.spirit.SpiritEntity;
import com.klikli_dev.occultism.registry.OccultismEntities;
import dev.emi.emi.api.render.EmiRenderable;
import dev.emi.emi.api.widget.DrawableWidget;
import net.minecraft.client.Minecraft;
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 7331811

Please sign in to comment.