mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-10-26 14:24:30 +00:00
Add compat for hodgepodge's async icon loading (#1799)
This commit is contained in:
1 parent
0d209d426d
commit
b639d5c646
1 file changed
+31
-28
+31
-28
@@ -10,43 +10,46 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.SimpleResource;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.Map;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
|
||||
@Mixin(TextureMap.class)
|
||||
public abstract class MixinTextureMap extends AbstractTexture implements ITickableTextureObject, IIconRegister {
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private Map<String, TextureAtlasSprite> mapRegisteredSprites;
|
||||
public abstract ResourceLocation completeResourceLocation(ResourceLocation p_147634_1_, int p_147634_2_);
|
||||
|
||||
@Shadow
|
||||
protected abstract ResourceLocation completeResourceLocation(ResourceLocation p_147634_1_, int p_147634_2_);
|
||||
@ModifyVariable(method = "registerIcon", at = @At(value = "STORE", ordinal = 3))
|
||||
private Object registerInterpolatedIcon(Object original){
|
||||
return createInterpolatedIcon(original);
|
||||
}
|
||||
|
||||
@Inject(method = "registerIcon", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;<init>(Ljava/lang/String;)V"), cancellable = true)
|
||||
private void registerInterpolatedIcon(String textureName, CallbackInfoReturnable<IIcon> cir) {
|
||||
try {
|
||||
IResource resource = Minecraft.getMinecraft().getResourceManager().getResource(completeResourceLocation(new ResourceLocation(textureName), 0));
|
||||
if (resource instanceof SimpleResource) {
|
||||
//This returns IMetadataSections, which seems to already remove unused mcmeta fields in 1.7.10
|
||||
//I'm just running this to populate the mcmetaJson field more easily; this does it for us
|
||||
if (resource.getMetadata("animation") != null) {
|
||||
JsonObject mcmetaJson = ((SimpleResource) resource).mcmetaJson;
|
||||
if (mcmetaJson.getAsJsonObject("animation").getAsJsonPrimitive("interpolate").getAsBoolean()) {
|
||||
InterpolatedIcon interpolatedIcon = new InterpolatedIcon(textureName);
|
||||
mapRegisteredSprites.put(textureName, interpolatedIcon);
|
||||
cir.setReturnValue(interpolatedIcon);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {/*Should quietly fail, no need to fail hard*/}
|
||||
}
|
||||
@ModifyVariable(method = "registerIcon", at = @At(value = "STORE", ordinal = 4))
|
||||
private Object registerInterpolatedIcon2(Object original){
|
||||
return createInterpolatedIcon(original);
|
||||
}
|
||||
|
||||
@Unique
|
||||
private Object createInterpolatedIcon(Object original){
|
||||
TextureAtlasSprite tas = (TextureAtlasSprite) original;
|
||||
String textureName = tas.getIconName();
|
||||
try {
|
||||
IResource resource = Minecraft.getMinecraft().getResourceManager().getResource(completeResourceLocation(new ResourceLocation(textureName), 0));
|
||||
if (resource instanceof SimpleResource) {
|
||||
//This returns IMetadataSections, which seems to already remove unused mcmeta fields in 1.7.10
|
||||
//I'm just running this to populate the mcmetaJson field more easily; this does it for us
|
||||
if (resource.getMetadata("animation") != null) {
|
||||
JsonObject mcmetaJson = ((SimpleResource) resource).mcmetaJson;
|
||||
if (mcmetaJson.getAsJsonObject("animation").getAsJsonPrimitive("interpolate").getAsBoolean()) {
|
||||
return new InterpolatedIcon(textureName);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {/*Should quietly fail, no need to fail hard*/}
|
||||
return original;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user