mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-22 13:19:44 +00:00
Add interpolated icon support (Roadhog360)
This commit is contained in:
1 parent
5511759b6d
commit
9b06c5a210
4 files changed
+122
-1
No files matched your search
@@ -251,7 +251,9 @@ public enum Mixins {
|
||||
"toggle.MixinEntityRenderer",
|
||||
"toggle.MixinGuiIngame",
|
||||
"toggle.MixinRender",
|
||||
"toggle.MixinRenderItem"
|
||||
"toggle.MixinRenderItem",
|
||||
|
||||
"interpolatedtexturemap.MixinTextureMap"
|
||||
))
|
||||
),
|
||||
BETTER_FACE_CULLING(new Builder("Better face culling")
|
||||
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package com.gtnewhorizons.angelica.mixins.early.notfine.interpolatedtexturemap;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import jss.notfine.render.InterpolatedIcon;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.AbstractTexture;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.client.renderer.texture.ITickableTextureObject;
|
||||
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.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Mixin(TextureMap.class)
|
||||
public abstract class MixinTextureMap extends AbstractTexture implements ITickableTextureObject, IIconRegister {
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private Map mapRegisteredSprites;
|
||||
|
||||
@Shadow
|
||||
protected abstract ResourceLocation completeResourceLocation(ResourceLocation p_147634_1_, int p_147634_2_);
|
||||
|
||||
@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*/}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package jss.notfine.render;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.texture.TextureUtil;
|
||||
|
||||
/**
|
||||
* Originally created by ganymedes01 for Et Futurum.
|
||||
* Ported to NotFine and cleaned up by Roadhog360.
|
||||
* @author ganymedes01
|
||||
* @author Roadhog360
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class InterpolatedIcon extends TextureAtlasSprite {
|
||||
|
||||
protected int[][] interpolatedFrameData;
|
||||
|
||||
public InterpolatedIcon(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAnimation() {
|
||||
super.updateAnimation();
|
||||
try {
|
||||
updateAnimationInterpolated();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateAnimationInterpolated() throws IllegalArgumentException, IllegalAccessException {
|
||||
|
||||
double d0 = 1.0D - tickCounter / (double) animationMetadata.getFrameTimeSingle(frameCounter);
|
||||
int i = animationMetadata.getFrameIndex(frameCounter);
|
||||
int j = animationMetadata.getFrameCount() == 0 ? framesTextureData.size() : animationMetadata.getFrameCount();
|
||||
int k = animationMetadata.getFrameIndex((frameCounter + 1) % j);
|
||||
|
||||
if (i != k && k >= 0 && k < framesTextureData.size()) {
|
||||
int[][] aint = (int[][]) framesTextureData.get(i);
|
||||
int[][] aint1 = (int[][]) framesTextureData.get(k);
|
||||
|
||||
if (interpolatedFrameData == null || interpolatedFrameData.length != aint.length)
|
||||
interpolatedFrameData = new int[aint.length][];
|
||||
|
||||
for (int l = 0; l < aint.length; l++) {
|
||||
if (interpolatedFrameData[l] == null)
|
||||
interpolatedFrameData[l] = new int[aint[l].length];
|
||||
|
||||
if (l < aint1.length && aint1[l].length == aint[l].length)
|
||||
for (int i1 = 0; i1 < aint[l].length; ++i1) {
|
||||
int j1 = aint[l][i1];
|
||||
int k1 = aint1[l][i1];
|
||||
int l1 = (int) (((j1 & 16711680) >> 16) * d0 + ((k1 & 16711680) >> 16) * (1.0D - d0));
|
||||
int i2 = (int) (((j1 & 65280) >> 8) * d0 + ((k1 & 65280) >> 8) * (1.0D - d0));
|
||||
int j2 = (int) ((j1 & 255) * d0 + (k1 & 255) * (1.0D - d0));
|
||||
interpolatedFrameData[l][i1] = j1 & -16777216 | l1 << 16 | i2 << 8 | j2;
|
||||
}
|
||||
}
|
||||
|
||||
TextureUtil.uploadTextureMipmap(interpolatedFrameData, width, height, originX, originY, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user