mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-02-13 08:14:23 +01:00
Fixed memory leak when repeatedly reloading textures
This commit is contained in:
parent
4e8fe18800
commit
90d5e00efc
2 changed files with 5 additions and 25 deletions
|
@ -13,10 +13,8 @@ import net.minecraft.client.render.entity.model.EntityModel;
|
|||
import net.minecraft.client.render.entity.model.ModelWithHat;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.resource.ReloadableResourceManager;
|
||||
import net.minecraft.resource.Resource;
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
import net.minecraft.resource.SynchronousResourceReloadListener;
|
||||
import net.minecraft.resource.Resource;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
@ -37,7 +35,7 @@ import java.util.Map;
|
|||
class NpcClothingFeature<
|
||||
T extends LivingEntity & VillagerDataContainer,
|
||||
M extends EntityModel<T> & IPonyModel<T> & ModelWithHat,
|
||||
C extends FeatureRendererContext<T, M> & IPonyRenderContext<T, M>> extends AbstractPonyFeature<T, M> implements SynchronousResourceReloadListener {
|
||||
C extends FeatureRendererContext<T, M> & IPonyRenderContext<T, M>> extends AbstractPonyFeature<T, M> {
|
||||
|
||||
private static final Int2ObjectMap<Identifier> LEVEL_TO_ID = Util.create(new Int2ObjectOpenHashMap<>(), a -> {
|
||||
a.put(1, new Identifier("stone"));
|
||||
|
@ -52,13 +50,11 @@ class NpcClothingFeature<
|
|||
|
||||
private final String entityType;
|
||||
|
||||
private final ReloadableResourceManager resourceManager;
|
||||
private final ResourceManager resourceManager = MinecraftClient.getInstance().getResourceManager();
|
||||
|
||||
public NpcClothingFeature(C context, String type) {
|
||||
super(context);
|
||||
entityType = type;
|
||||
resourceManager = (ReloadableResourceManager)MinecraftClient.getInstance().getResourceManager();
|
||||
resourceManager.registerListener(this);
|
||||
}
|
||||
|
||||
public static Identifier getClothingTexture(VillagerDataContainer entity, String entityType) {
|
||||
|
@ -131,12 +127,6 @@ class NpcClothingFeature<
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(ResourceManager manager) {
|
||||
profHatCache.clear();
|
||||
typeHatCache.clear();
|
||||
}
|
||||
|
||||
public Identifier findTexture(String category, Identifier identifier) {
|
||||
return new Identifier("minelittlepony", "textures/entity/" + entityType + "/" + category + "/" + identifier.getPath() + ".png");
|
||||
}
|
||||
|
|
|
@ -2,9 +2,7 @@ package com.minelittlepony.client.render.entity.npc;
|
|||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.resource.ReloadableResourceManager;
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
import net.minecraft.resource.SynchronousResourceReloadListener;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.village.VillagerData;
|
||||
import net.minecraft.village.VillagerDataContainer;
|
||||
|
@ -20,7 +18,7 @@ import java.util.Optional;
|
|||
/**
|
||||
* Cached pool of villager textures.
|
||||
*/
|
||||
public class PonyTextures<T extends LivingEntity & VillagerDataContainer> implements TextureSupplier<T>, SynchronousResourceReloadListener {
|
||||
public class PonyTextures<T extends LivingEntity & VillagerDataContainer> implements TextureSupplier<T> {
|
||||
|
||||
private final TextureSupplier<String> formatter;
|
||||
|
||||
|
@ -31,7 +29,7 @@ public class PonyTextures<T extends LivingEntity & VillagerDataContainer> implem
|
|||
private final Identifier egg;
|
||||
private final Identifier egg2;
|
||||
|
||||
private final ReloadableResourceManager resourceManager;
|
||||
private final ResourceManager resourceManager = MinecraftClient.getInstance().getResourceManager();
|
||||
|
||||
/**
|
||||
* Creates a new profession cache
|
||||
|
@ -41,18 +39,10 @@ public class PonyTextures<T extends LivingEntity & VillagerDataContainer> implem
|
|||
* @param fallback The default if any generated textures fail to load. This is stored in place of failing textures.
|
||||
*/
|
||||
public PonyTextures(TextureSupplier<String> formatter) {
|
||||
this.resourceManager = (ReloadableResourceManager)MinecraftClient.getInstance().getResourceManager();
|
||||
this.formatter = formatter;
|
||||
this.fallback = formatter.supplyTexture("villager_pony");
|
||||
this.egg = formatter.supplyTexture("silly_pony");
|
||||
this.egg2 = formatter.supplyTexture("tiny_silly_pony");
|
||||
|
||||
resourceManager.registerListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(ResourceManager manager) {
|
||||
cache.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue