Skip to content

Commit

Permalink
Make randomEntity a local field to prevent leaking the world also min…
Browse files Browse the repository at this point in the history
…or refactor
  • Loading branch information
Pelotrio committed Nov 10, 2023
1 parent 398786a commit ac5af48
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@

public class RenderMobSoul implements IItemRenderer {

private Minecraft mc;
private Entity randomEntity = null;
private String[] randomEntitys = new String[] { "Pig", "Sheep", "Enderman", "Zombie", "Creeper", "Cow", "Chicken",
"Ozelot", "Witch", "Wolf", "MushroomCow", "Squid", "EntityHorse", "Spider", "Skeleton", "Blaze", "Bat",
"Villager", "Silverfish" };
private final Minecraft mc;
private final String[] randomEntities = new String[] { "Pig", "Sheep", "Enderman", "Zombie", "Creeper", "Cow",
"Chicken", "Ozelot", "Witch", "Wolf", "MushroomCow", "Squid", "EntityHorse", "Spider", "Skeleton", "Blaze",
"Bat", "Villager", "Silverfish" };

public RenderMobSoul() {
this.mc = Minecraft.getMinecraft();
Expand All @@ -40,8 +39,8 @@ public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRe
@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
Entity mob = EntityList.createEntityByName(ItemNBTHelper.getString(item, "Name", "Pig"), mc.theWorld);
randomEntity = EntityList
.createEntityByName(randomEntitys[(int) ((Minecraft.getSystemTime() / 1000) % 18)], mc.theWorld);
Entity randomEntity = EntityList
.createEntityByName(randomEntities[(int) ((Minecraft.getSystemTime() / 1000) % 18)], mc.theWorld);
if (ItemNBTHelper.getString(item, "Name", "Pig").equals("Any")) mob = randomEntity;
if (mob instanceof EntitySkeleton)
((EntitySkeleton) mob).setSkeletonType(ItemNBTHelper.getInteger(item, "SkeletonType", 0));
Expand Down

0 comments on commit ac5af48

Please sign in to comment.