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