mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-12-01 16:27:59 +01:00
General cleanup
This commit is contained in:
parent
a9e7ca7b37
commit
02bc96d76c
7 changed files with 95 additions and 74 deletions
|
@ -10,7 +10,7 @@ public class DynamicTextureImage extends DynamicTexture {
|
|||
|
||||
public DynamicTextureImage(BufferedImage bufferedImage) {
|
||||
super(bufferedImage);
|
||||
this.image = bufferedImage;
|
||||
image = bufferedImage;
|
||||
}
|
||||
|
||||
public BufferedImage getImage() {
|
||||
|
@ -20,7 +20,7 @@ public class DynamicTextureImage extends DynamicTexture {
|
|||
@Override
|
||||
public void deleteGlTexture() {
|
||||
super.deleteGlTexture();
|
||||
this.image = null;
|
||||
image = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -82,6 +82,7 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
|
|||
|
||||
private Map<UUID, Map<Type, ResourceLocation>> skinCache = Maps.newHashMap();
|
||||
|
||||
// TODO: Garggling marbles
|
||||
private LoadingCache<GameProfile, Map<Type, MinecraftProfileTexture>> skins = CacheBuilder.newBuilder()
|
||||
.initialCapacity(20)
|
||||
.maximumSize(100)
|
||||
|
@ -248,16 +249,16 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
|
|||
}
|
||||
|
||||
public Class<? extends SkinServer> getSkinServerClass(String type) {
|
||||
return this.skinServerTypes.get(type);
|
||||
return skinServerTypes.get(type);
|
||||
}
|
||||
|
||||
public void addSkinServer(SkinServer skinServer) {
|
||||
this.skinServers.add(skinServer);
|
||||
skinServers.add(skinServer);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public SkinServer getGatewayServer() {
|
||||
return this.skinServers.get(0);
|
||||
return skinServers.get(0);
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
|
@ -278,9 +279,10 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
|
|||
try {
|
||||
FileUtils.deleteDirectory(new File(LiteLoader.getAssetsDirectory(), "skins"));
|
||||
FileUtils.deleteDirectory(new File(LiteLoader.getAssetsDirectory(), "hd"));
|
||||
|
||||
TextureManager textures = Minecraft.getMinecraft().getTextureManager();
|
||||
INSTANCE.skinCache.values().stream()
|
||||
.flatMap(m -> m.values().stream())
|
||||
|
||||
INSTANCE.skinCache.values().stream().flatMap(m -> m.values().stream())
|
||||
.forEach(textures::deleteTexture);
|
||||
INSTANCE.skinCache.clear();
|
||||
INSTANCE.skins.invalidateAll();
|
||||
|
@ -313,13 +315,11 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
|
|||
}
|
||||
|
||||
public void convertSkin(BufferedImage image, Graphics dest) {
|
||||
for (ISkinModifier skin : skinModifiers) {
|
||||
skin.convertSkin(image, dest);
|
||||
}
|
||||
skinModifiers.forEach(a -> a.convertSkin(image, dest));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager resourceManager) {
|
||||
this.resources.onResourceManagerReload(resourceManager);
|
||||
resources.onResourceManagerReload(resourceManager);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,16 +6,21 @@ import net.minecraft.util.ResourceLocation;
|
|||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||
|
||||
public class PreviewTexture extends ThreadDownloadImageData {
|
||||
|
||||
private boolean uploaded;
|
||||
|
||||
private String model;
|
||||
|
||||
public PreviewTexture(@Nullable String model, String url, ResourceLocation fallbackTexture, @Nullable IImageBuffer imageBuffer) {
|
||||
super(null, url, fallbackTexture, imageBuffer);
|
||||
public PreviewTexture(MinecraftProfileTexture texture, ResourceLocation fallbackTexture, @Nullable IImageBuffer imageBuffer) {
|
||||
super(null, texture.getUrl(), fallbackTexture, imageBuffer);
|
||||
|
||||
this.model = model == null ? "default" : model;
|
||||
model = texture.getMetadata("model");
|
||||
if (model == null) {
|
||||
model = "default";
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isTextureUploaded() {
|
||||
|
@ -25,7 +30,7 @@ public class PreviewTexture extends ThreadDownloadImageData {
|
|||
@Override
|
||||
public void deleteGlTexture() {
|
||||
super.deleteGlTexture();
|
||||
this.uploaded = true;
|
||||
uploaded = true;
|
||||
}
|
||||
|
||||
public boolean hasModel() {
|
||||
|
@ -35,4 +40,8 @@ public class PreviewTexture extends ThreadDownloadImageData {
|
|||
public boolean usesThinArms() {
|
||||
return "thin".equals(model);
|
||||
}
|
||||
|
||||
public String getModel() {
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package com.voxelmodpack.hdskins;
|
|||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.IImageBuffer;
|
||||
import net.minecraft.client.resources.SkinManager;
|
||||
|
@ -18,22 +20,20 @@ import javax.annotation.Nullable;
|
|||
*/
|
||||
public class PreviewTextureManager {
|
||||
|
||||
private final Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> textures;
|
||||
private final Map<Type, MinecraftProfileTexture> textures;
|
||||
|
||||
PreviewTextureManager(Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> textures) {
|
||||
PreviewTextureManager(Map<Type, MinecraftProfileTexture> textures) {
|
||||
this.textures = textures;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PreviewTexture getPreviewTexture(ResourceLocation location, MinecraftProfileTexture.Type type, ResourceLocation def,
|
||||
@Nullable SkinManager.SkinAvailableCallback callback) {
|
||||
if (!textures.containsKey(type)) {
|
||||
private IImageBuffer getPreviewImageBuffer(MinecraftProfileTexture texture, ResourceLocation location, Type type, SkinManager.SkinAvailableCallback callback) {
|
||||
if (type != Type.SKIN) {
|
||||
return null;
|
||||
}
|
||||
MinecraftProfileTexture texture = textures.get(type);
|
||||
|
||||
IImageBuffer buffer = new ImageBufferDownloadHD();
|
||||
PreviewTexture skinTexture = new PreviewTexture(texture.getMetadata("model"), texture.getUrl(), def,
|
||||
type == MinecraftProfileTexture.Type.SKIN ? new IImageBuffer() {
|
||||
|
||||
return new IImageBuffer() {
|
||||
@Override
|
||||
@Nullable
|
||||
public BufferedImage parseUserSkin(BufferedImage image) {
|
||||
|
@ -46,7 +46,18 @@ public class PreviewTextureManager {
|
|||
callback.skinAvailable(type, location, new MinecraftProfileTexture(texture.getUrl(), Maps.newHashMap()));
|
||||
}
|
||||
}
|
||||
} : null);
|
||||
};
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PreviewTexture getPreviewTexture(ResourceLocation location, Type type, ResourceLocation def, @Nullable SkinManager.SkinAvailableCallback callback) {
|
||||
if (!textures.containsKey(type)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MinecraftProfileTexture texture = textures.get(type);
|
||||
PreviewTexture skinTexture = new PreviewTexture(texture, def, getPreviewImageBuffer(texture, location, type, callback));
|
||||
|
||||
Minecraft.getMinecraft().getTextureManager().loadTexture(location, skinTexture);
|
||||
|
||||
return skinTexture;
|
||||
|
|
|
@ -6,9 +6,11 @@ import net.minecraft.util.ResourceLocation;
|
|||
|
||||
public class TextureLoader {
|
||||
|
||||
private static Minecraft mc = Minecraft.getMinecraft();
|
||||
private static final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
public static void loadTexture(final ResourceLocation textureLocation, final ITextureObject textureObj) {
|
||||
mc.addScheduledTask((Runnable) () -> mc.getTextureManager().loadTexture(textureLocation, textureObj));
|
||||
public static void loadTexture(ResourceLocation textureLocation, ITextureObject textureObj) {
|
||||
mc.addScheduledTask(() -> {
|
||||
mc.getTextureManager().loadTexture(textureLocation, textureObj);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ import org.apache.http.Header;
|
|||
import org.apache.http.HttpHeaders;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
@ -36,6 +35,7 @@ public class ThreadDownloadImageETag extends SimpleTexture {
|
|||
private final File cacheFile;
|
||||
private final File eTagFile;
|
||||
private final String imageUrl;
|
||||
|
||||
@Nullable
|
||||
private final IImageBuffer imageBuffer;
|
||||
|
||||
|
@ -47,35 +47,32 @@ public class ThreadDownloadImageETag extends SimpleTexture {
|
|||
|
||||
public ThreadDownloadImageETag(@Nonnull File cacheFileIn, String imageUrlIn, ResourceLocation defLocation, @Nullable IImageBuffer imageBufferIn) {
|
||||
super(defLocation);
|
||||
this.cacheFile = cacheFileIn;
|
||||
this.eTagFile = new File(cacheFile.getParentFile(), cacheFile.getName() + ".etag");
|
||||
this.imageUrl = imageUrlIn;
|
||||
this.imageBuffer = imageBufferIn;
|
||||
}
|
||||
|
||||
private void checkTextureUploaded() {
|
||||
if (!this.textureUploaded) {
|
||||
if (this.bufferedImage != null) {
|
||||
if (this.textureLocation != null) {
|
||||
this.deleteGlTexture();
|
||||
}
|
||||
|
||||
TextureUtil.uploadTextureImage(super.getGlTextureId(), this.bufferedImage);
|
||||
this.textureUploaded = true;
|
||||
}
|
||||
}
|
||||
cacheFile = cacheFileIn;
|
||||
eTagFile = new File(cacheFile.getParentFile(), cacheFile.getName() + ".etag");
|
||||
imageUrl = imageUrlIn;
|
||||
imageBuffer = imageBufferIn;
|
||||
}
|
||||
|
||||
public int getGlTextureId() {
|
||||
this.checkTextureUploaded();
|
||||
if (!textureUploaded) {
|
||||
if (bufferedImage != null) {
|
||||
if (textureLocation != null) {
|
||||
deleteGlTexture();
|
||||
}
|
||||
|
||||
TextureUtil.uploadTextureImage(super.getGlTextureId(), bufferedImage);
|
||||
textureUploaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
return super.getGlTextureId();
|
||||
}
|
||||
|
||||
private void setBufferedImage(@Nonnull BufferedImage bufferedImageIn) {
|
||||
this.bufferedImage = bufferedImageIn;
|
||||
bufferedImage = bufferedImageIn;
|
||||
|
||||
if (this.imageBuffer != null) {
|
||||
this.imageBuffer.skinAvailable();
|
||||
if (imageBuffer != null) {
|
||||
imageBuffer.skinAvailable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,22 +82,22 @@ public class ThreadDownloadImageETag extends SimpleTexture {
|
|||
}
|
||||
|
||||
public void loadTexture(IResourceManager resourceManager) throws IOException {
|
||||
if (this.bufferedImage == null && this.textureLocation != null) {
|
||||
if (bufferedImage == null && textureLocation != null) {
|
||||
super.loadTexture(resourceManager);
|
||||
}
|
||||
|
||||
if (this.imageThread == null) {
|
||||
this.imageThread = new Thread(this::loadTexture, "Texture Downloader #" + THREAD_ID.incrementAndGet());
|
||||
this.imageThread.setDaemon(true);
|
||||
this.imageThread.start();
|
||||
if (imageThread == null) {
|
||||
imageThread = new Thread(this::loadTexture, "Texture Downloader #" + THREAD_ID.incrementAndGet());
|
||||
imageThread.setDaemon(true);
|
||||
imageThread.start();
|
||||
}
|
||||
}
|
||||
|
||||
private void loadTexture() {
|
||||
HttpResponse response = null;
|
||||
try {
|
||||
HttpClient client = HttpClientBuilder.create().build();
|
||||
response = client.execute(new HttpGet(imageUrl));
|
||||
response = HttpClientBuilder.create().build().execute(new HttpGet(imageUrl));
|
||||
|
||||
int status = response.getStatusLine().getStatusCode();
|
||||
if (status == HttpStatus.SC_NOT_FOUND) {
|
||||
// delete the cache files in case we can't connect in the future
|
||||
|
@ -133,10 +130,11 @@ public class ThreadDownloadImageETag extends SimpleTexture {
|
|||
}
|
||||
LOGGER.error("Couldn't load skin {} ", imageUrl, e);
|
||||
} finally {
|
||||
if (response != null)
|
||||
if (response != null) {
|
||||
EntityUtils.consumeQuietly(response.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setLocalCache() throws IOException {
|
||||
if (cacheFile.isFile()) {
|
||||
|
@ -149,8 +147,8 @@ public class ThreadDownloadImageETag extends SimpleTexture {
|
|||
}
|
||||
|
||||
private void clearCache() {
|
||||
FileUtils.deleteQuietly(this.cacheFile);
|
||||
FileUtils.deleteQuietly(this.eTagFile);
|
||||
FileUtils.deleteQuietly(cacheFile);
|
||||
FileUtils.deleteQuietly(eTagFile);
|
||||
}
|
||||
|
||||
private boolean checkETag(HttpResponse response) {
|
||||
|
@ -158,14 +156,15 @@ public class ThreadDownloadImageETag extends SimpleTexture {
|
|||
if (cacheFile.isFile()) {
|
||||
String localETag = Files.readFirstLine(eTagFile, Charsets.UTF_8);
|
||||
Header remoteETag = response.getFirstHeader(HttpHeaders.ETAG);
|
||||
|
||||
// true if no remote etag or does match
|
||||
return remoteETag == null || localETag.equals(remoteETag.getValue());
|
||||
}
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
// it failed, so re-fetch.
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
return false; // it failed, so re-fetch.
|
||||
}
|
||||
|
||||
private void loadTextureFromServer(HttpResponse response) {
|
||||
|
|
|
@ -17,6 +17,6 @@ public class GuiItemStackButton extends GuiButton {
|
|||
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
|
||||
super.drawButton(mc, mouseX, mouseY, partialTicks);
|
||||
|
||||
mc.getRenderItem().renderItemIntoGUI(itemStack, this.x + 2, this.y + 2);
|
||||
mc.getRenderItem().renderItemIntoGUI(itemStack, x + 2, y + 2);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue