|
10 | 10 | import net.minecraft.client.renderer.texture.TextureMap; |
11 | 11 | import net.minecraft.client.resources.IResource; |
12 | 12 | import net.minecraft.client.resources.SimpleResource; |
13 | | -import net.minecraft.util.IIcon; |
14 | 13 | import net.minecraft.util.ResourceLocation; |
15 | | -import org.spongepowered.asm.mixin.Final; |
16 | 14 | import org.spongepowered.asm.mixin.Mixin; |
17 | 15 | import org.spongepowered.asm.mixin.Shadow; |
| 16 | +import org.spongepowered.asm.mixin.Unique; |
18 | 17 | import org.spongepowered.asm.mixin.injection.At; |
19 | | -import org.spongepowered.asm.mixin.injection.Inject; |
20 | | -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; |
21 | | - |
22 | | -import java.util.Map; |
| 18 | +import org.spongepowered.asm.mixin.injection.ModifyVariable; |
23 | 19 |
|
24 | 20 | @Mixin(TextureMap.class) |
25 | 21 | public abstract class MixinTextureMap extends AbstractTexture implements ITickableTextureObject, IIconRegister { |
26 | 22 |
|
27 | 23 | @Shadow |
28 | | - @Final |
29 | | - private Map<String, TextureAtlasSprite> mapRegisteredSprites; |
| 24 | + public abstract ResourceLocation completeResourceLocation(ResourceLocation p_147634_1_, int p_147634_2_); |
30 | 25 |
|
31 | | - @Shadow |
32 | | - protected abstract ResourceLocation completeResourceLocation(ResourceLocation p_147634_1_, int p_147634_2_); |
| 26 | + @ModifyVariable(method = "registerIcon", at = @At(value = "STORE", ordinal = 3)) |
| 27 | + private Object registerInterpolatedIcon(Object original){ |
| 28 | + return createInterpolatedIcon(original); |
| 29 | + } |
| 30 | + |
| 31 | + @ModifyVariable(method = "registerIcon", at = @At(value = "STORE", ordinal = 4)) |
| 32 | + private Object registerInterpolatedIcon2(Object original){ |
| 33 | + return createInterpolatedIcon(original); |
| 34 | + } |
33 | 35 |
|
34 | | - @Inject(method = "registerIcon", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;<init>(Ljava/lang/String;)V"), cancellable = true) |
35 | | - private void registerInterpolatedIcon(String textureName, CallbackInfoReturnable<IIcon> cir) { |
36 | | - try { |
37 | | - IResource resource = Minecraft.getMinecraft().getResourceManager().getResource(completeResourceLocation(new ResourceLocation(textureName), 0)); |
38 | | - if (resource instanceof SimpleResource) { |
39 | | - //This returns IMetadataSections, which seems to already remove unused mcmeta fields in 1.7.10 |
40 | | - //I'm just running this to populate the mcmetaJson field more easily; this does it for us |
41 | | - if (resource.getMetadata("animation") != null) { |
42 | | - JsonObject mcmetaJson = ((SimpleResource) resource).mcmetaJson; |
43 | | - if (mcmetaJson.getAsJsonObject("animation").getAsJsonPrimitive("interpolate").getAsBoolean()) { |
44 | | - InterpolatedIcon interpolatedIcon = new InterpolatedIcon(textureName); |
45 | | - mapRegisteredSprites.put(textureName, interpolatedIcon); |
46 | | - cir.setReturnValue(interpolatedIcon); |
47 | | - } |
48 | | - } |
49 | | - } |
50 | | - } catch (Exception ignored) {/*Should quietly fail, no need to fail hard*/} |
51 | | - } |
| 36 | + @Unique |
| 37 | + private Object createInterpolatedIcon(Object original){ |
| 38 | + TextureAtlasSprite tas = (TextureAtlasSprite) original; |
| 39 | + String textureName = tas.getIconName(); |
| 40 | + try { |
| 41 | + IResource resource = Minecraft.getMinecraft().getResourceManager().getResource(completeResourceLocation(new ResourceLocation(textureName), 0)); |
| 42 | + if (resource instanceof SimpleResource) { |
| 43 | + //This returns IMetadataSections, which seems to already remove unused mcmeta fields in 1.7.10 |
| 44 | + //I'm just running this to populate the mcmetaJson field more easily; this does it for us |
| 45 | + if (resource.getMetadata("animation") != null) { |
| 46 | + JsonObject mcmetaJson = ((SimpleResource) resource).mcmetaJson; |
| 47 | + if (mcmetaJson.getAsJsonObject("animation").getAsJsonPrimitive("interpolate").getAsBoolean()) { |
| 48 | + return new InterpolatedIcon(textureName); |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | + } catch (Exception ignored) {/*Should quietly fail, no need to fail hard*/} |
| 53 | + return original; |
| 54 | + } |
52 | 55 | } |
0 commit comments