mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-25 13:57:59 +01:00
Fix build error
This commit is contained in:
parent
c9d7a394ad
commit
df7c04ad30
1 changed files with 16 additions and 11 deletions
|
@ -5,17 +5,18 @@ import com.voxelmodpack.hdskins.ImageBufferDownloadHD;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.texture.TextureUtil;
|
import net.minecraft.client.renderer.texture.TextureUtil;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class ImageLoader implements Supplier<ResourceLocation> {
|
public class ImageLoader implements Supplier<ResourceLocation> {
|
||||||
|
|
||||||
private Minecraft mc = Minecraft.getMinecraft();
|
private static Minecraft mc = Minecraft.getMinecraft();
|
||||||
|
|
||||||
private final ResourceLocation original;
|
private final ResourceLocation original;
|
||||||
|
|
||||||
|
@ -35,18 +36,22 @@ public class ImageLoader implements Supplier<ResourceLocation> {
|
||||||
// don't load a new image
|
// don't load a new image
|
||||||
return this.original;
|
return this.original;
|
||||||
}
|
}
|
||||||
return this.mc.addScheduledTask(() -> loadSkin(updated)).get();
|
return addTaskAndGet(() -> loadSkin(updated));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <V> V addTaskAndGet(Callable<V> callable) {
|
||||||
|
try {
|
||||||
|
return mc.addScheduledTask(callable).get();
|
||||||
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static BufferedImage getImage(ResourceLocation res) {
|
private static BufferedImage getImage(ResourceLocation res) {
|
||||||
try {
|
|
||||||
InputStream in = Minecraft.getMinecraft().getResourceManager().getResource(res).getInputStream();
|
try (InputStream in = mc.getResourceManager().getResource(res).getInputStream()) {
|
||||||
try {
|
return TextureUtil.readBufferedImage(in);
|
||||||
return TextureUtil.readBufferedImage(in);
|
|
||||||
} finally {
|
|
||||||
IOUtils.closeQuietly(in);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -56,7 +61,7 @@ public class ImageLoader implements Supplier<ResourceLocation> {
|
||||||
private ResourceLocation loadSkin(BufferedImage image) {
|
private ResourceLocation loadSkin(BufferedImage image) {
|
||||||
|
|
||||||
ResourceLocation conv = new ResourceLocation(original.getResourceDomain() + "-converted", original.getResourcePath());
|
ResourceLocation conv = new ResourceLocation(original.getResourceDomain() + "-converted", original.getResourcePath());
|
||||||
boolean success= this.mc.getTextureManager().loadTexture(conv, new DynamicTextureImage(image));
|
boolean success = mc.getTextureManager().loadTexture(conv, new DynamicTextureImage(image));
|
||||||
return success ? conv : null;
|
return success ? conv : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue