Remove the cache again

This commit is contained in:
Sollace 2019-07-14 01:23:14 +02:00
parent e3a496be16
commit 310e713d71

View file

@ -1,9 +1,6 @@
package com.minelittlepony.client.pony; package com.minelittlepony.client.pony;
import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.minelittlepony.client.MineLittlePony; import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.client.PonyRenderManager; import com.minelittlepony.client.PonyRenderManager;
import com.minelittlepony.client.render.IPonyRender; import com.minelittlepony.client.render.IPonyRender;
@ -16,8 +13,6 @@ import net.minecraft.block.Material;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.texture.MissingSprite; import net.minecraft.client.texture.MissingSprite;
import net.minecraft.client.texture.NativeImage; import net.minecraft.client.texture.NativeImage;
import net.minecraft.client.texture.NativeImageBackedTexture;
import net.minecraft.client.texture.Texture;
import net.minecraft.client.texture.TextureManager; import net.minecraft.client.texture.TextureManager;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.EquipmentSlot;
@ -37,8 +32,6 @@ import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.Immutable;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import static com.mojang.blaze3d.platform.GlStateManager.getTexLevelParameter; import static com.mojang.blaze3d.platform.GlStateManager.getTexLevelParameter;
@ -49,10 +42,6 @@ public class Pony implements IPony {
private static final AtomicInteger ponyCount = new AtomicInteger(); private static final AtomicInteger ponyCount = new AtomicInteger();
private static final LoadingCache<Identifier, NativeImage> nativeCache = CacheBuilder.newBuilder()
.expireAfterAccess(30, TimeUnit.SECONDS)
.build(CacheLoader.from(Pony::constructFromGlBuffer));
private final int ponyId = ponyCount.getAndIncrement(); private final int ponyId = ponyCount.getAndIncrement();
private final Identifier texture; private final Identifier texture;
@ -104,24 +93,10 @@ public class Pony implements IPony {
} }
private static NativeImage getBufferedImage(@Nullable Identifier resource) { private static NativeImage getBufferedImage(@Nullable Identifier resource) {
if (resource != null) { if (resource == null) {
try { return MissingSprite.getMissingSpriteTexture().getImage();
Texture texture = MinecraftClient.getInstance().getTextureManager().getTexture(resource);
if (texture instanceof NativeImageBackedTexture) {
return ((NativeImageBackedTexture)texture).getImage();
}
return nativeCache.get(resource);
} catch (ExecutionException e) {
MineLittlePony.logger.fatal("Error fetching native image from gl buffer", e);
}
} }
return MissingSprite.getMissingSpriteTexture().getImage();
}
private static NativeImage constructFromGlBuffer(Identifier resource) {
MinecraftClient mc = MinecraftClient.getInstance(); MinecraftClient mc = MinecraftClient.getInstance();
TextureManager textures = mc.getTextureManager(); TextureManager textures = mc.getTextureManager();