diff --git a/src/main/java/mizurin/shieldmod/ColoredArmorTexture.java b/src/main/java/mizurin/shieldmod/ColoredArmorTexture.java index 8203751..e2cd1c9 100644 --- a/src/main/java/mizurin/shieldmod/ColoredArmorTexture.java +++ b/src/main/java/mizurin/shieldmod/ColoredArmorTexture.java @@ -1,2 +1,19 @@ -package mizurin.shieldmod;public class ColoredArmorTexture { +package mizurin.shieldmod; + +import java.awt.*; + +public class ColoredArmorTexture { + protected String armorTexture; + protected Color color; + + public ColoredArmorTexture(String armorTexture, Color color){ + this.armorTexture = armorTexture; + this.color = color; + } + public String getArmorTexture(){ + return armorTexture; + } + public Color getColor(){ + return color; + } } diff --git a/src/main/java/mizurin/shieldmod/IColoredArmor.java b/src/main/java/mizurin/shieldmod/IColoredArmor.java index 6bd6c54..30b7377 100644 --- a/src/main/java/mizurin/shieldmod/IColoredArmor.java +++ b/src/main/java/mizurin/shieldmod/IColoredArmor.java @@ -1,2 +1,9 @@ -package mizurin.shieldmod;public class IColoredArmor { +package mizurin.shieldmod; + +import net.minecraft.core.item.ItemStack; + +import java.awt.*; + +public interface IColoredArmor { + ColoredArmorTexture[] getArmorTextures(ItemStack stack); } diff --git a/src/main/java/mizurin/shieldmod/mixins/LivingRendererMixin.java b/src/main/java/mizurin/shieldmod/mixins/LivingRendererMixin.java index b64e072..2a4f156 100644 --- a/src/main/java/mizurin/shieldmod/mixins/LivingRendererMixin.java +++ b/src/main/java/mizurin/shieldmod/mixins/LivingRendererMixin.java @@ -1,2 +1,74 @@ -package mizurin.shieldmod.mixins;public class LivingRendererMixin { +package mizurin.shieldmod.mixins; + +import mizurin.shieldmod.ColoredArmorTexture; +import mizurin.shieldmod.IColoredArmor; +import net.minecraft.client.render.entity.LivingRenderer; +import net.minecraft.client.render.model.ModelBase; +import net.minecraft.core.entity.EntityLiving; +import net.minecraft.core.entity.player.EntityPlayer; +import net.minecraft.core.item.ItemStack; +import org.lwjgl.opengl.GL11; +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.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +@Mixin(value = LivingRenderer.class, remap = false) +public abstract class LivingRendererMixin { + @Shadow protected abstract boolean shouldRenderPass(T entity, int renderPass, float partialTick); + + @Shadow protected ModelBase renderPassModel; + @Unique + float limbSwing; + @Unique + float limbYaw; + @Unique + float ticksExisted; + @Unique + float headYaw; + @Unique + float headYawOffset; + @Unique + float headPitch; + @Unique + float scale; + @Inject(method = "render(Lnet/minecraft/core/entity/EntityLiving;DDDFF)V", + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/LivingRenderer;shouldRenderPass(Lnet/minecraft/core/entity/EntityLiving;IF)Z", shift = At.Shift.BEFORE), + locals = LocalCapture.CAPTURE_FAILHARD) + private void captureLocals(T entity, double x, double y, double z, float yaw1, float partialTick1, CallbackInfo ci, float headYawOffset, float headYaw, float headPitch, float ticksExisted, float scale, float limbYaw, float limbSwing, int renderPass){ + this.limbSwing = limbSwing; + this.limbYaw = limbYaw; + this.ticksExisted = ticksExisted; + this.headYaw = headYaw; + this.headYawOffset = headYawOffset; + this.headPitch = headPitch; + this.scale = scale; + } + @Redirect(method = "render(Lnet/minecraft/core/entity/EntityLiving;DDDFF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/LivingRenderer;shouldRenderPass(Lnet/minecraft/core/entity/EntityLiving;IF)Z")) + private boolean hijackRenderPass(LivingRenderer instance, T entity, int renderPass, float partialTick){ + PrismaticLibe.playerArmorRenderOffset = 0; + if (entity instanceof EntityPlayer){ + ItemStack itemstack = ((EntityPlayer) entity).inventory.armorItemInSlot(3 - renderPass); + if (itemstack != null && itemstack.getItem() instanceof IColoredArmor){ + // do stuff + ColoredArmorTexture[] cTex = ((IColoredArmor) itemstack.getItem()).getArmorTextures(itemstack); + for (ColoredArmorTexture ignored : cTex) { + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(770, 771); + shouldRenderPass(entity, renderPass, partialTick); + this.renderPassModel.render(limbSwing, limbYaw, ticksExisted, headYaw - headYawOffset, headPitch, scale); + GL11.glDisable(3042); + GL11.glEnable(3008); + PrismaticLibe.playerArmorRenderOffset++; + } + PrismaticLibe.playerArmorRenderOffset = 0; + return false; + } + } + return this.shouldRenderPass(entity, renderPass, partialTick); + } } diff --git a/src/main/java/mizurin/shieldmod/mixins/PlayerRendererMixin.java b/src/main/java/mizurin/shieldmod/mixins/PlayerRendererMixin.java index 99adf6e..f4793cf 100644 --- a/src/main/java/mizurin/shieldmod/mixins/PlayerRendererMixin.java +++ b/src/main/java/mizurin/shieldmod/mixins/PlayerRendererMixin.java @@ -1,2 +1,55 @@ -package mizurin.shieldmod.mixins;public class PlayerRendererMixin { +package mizurin.shieldmod.mixins; + +import mizurin.shieldmod.ColoredArmorTexture; +import mizurin.shieldmod.IColoredArmor; +import mizurin.shieldmod.item.ArmorColored; +import net.minecraft.client.Minecraft; +import net.minecraft.client.render.entity.PlayerRenderer; +import net.minecraft.core.entity.player.EntityPlayer; +import net.minecraft.core.item.ItemStack; +import org.lwjgl.opengl.GL11; +import org.spongepowered.asm.mixin.Mixin; +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.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.awt.*; + +@Mixin(value = PlayerRenderer.class, remap = false) +public class PlayerRendererMixin { + @Unique + private final Minecraft mc = Minecraft.getMinecraft(this); + @Unique + private ColoredArmorTexture[] armorTextures; + @Inject(method = "setArmorModel(Lnet/minecraft/core/entity/player/EntityPlayer;IF)Z", at = @At("HEAD")) + private void colorArmor(EntityPlayer entity, int renderPass, float partialTick, CallbackInfoReturnable cir){ + float brightness = mc.fullbright ? 1f : entity.getBrightness(0); + GL11.glColor4f(brightness,brightness,brightness,1f); + ItemStack itemstack = entity.inventory.armorItemInSlot(3 - renderPass); + armorTextures = null; + if (itemstack != null && itemstack.getItem() instanceof IColoredArmor){ + armorTextures =((IColoredArmor) itemstack.getItem()).getArmorTextures(itemstack); + if (PrismaticLibe.playerArmorRenderOffset > armorTextures.length) return; + Color color = armorTextures[PrismaticLibe.playerArmorRenderOffset].getColor(); + GL11.glColor4f((color.getRed()/255f) * brightness, (color.getGreen()/255f) * brightness, (color.getBlue()/255f) * brightness,color.getAlpha()/255f); + } + } + @Inject(method = "setArmorModel(Lnet/minecraft/core/entity/player/EntityPlayer;IF)Z", at = @At("TAIL")) + private void colorArmorOff(EntityPlayer entity, int renderPass, float partialTick, CallbackInfoReturnable cir){ + float brightness = mc.fullbright ? 1f : entity.getBrightness(0); + GL11.glColor4f(brightness,brightness,brightness,1f); + } + @Redirect(method = "setArmorModel(Lnet/minecraft/core/entity/player/EntityPlayer;IF)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/PlayerRenderer;loadTexture(Ljava/lang/String;)V", ordinal = 3)) + private void customArmorTexture(PlayerRenderer instance, String string){ + if (armorTextures != null){ + if (PrismaticLibe.playerArmorRenderOffset > armorTextures.length) return; + String tmp = string.replace(".png", ""); + int renderPass = Integer.decode(String.valueOf(tmp.charAt(tmp.length()-1))); + ((EntityRendererAccessor)instance).invokeLoadTexture("/armor/" + armorTextures[PrismaticLibe.playerArmorRenderOffset].getArmorTexture() + "_" + (renderPass != 2 ? 1 : 2) + ".png"); + } else { + ((EntityRendererAccessor)instance).invokeLoadTexture(string); + } + } } diff --git a/src/main/resources/shieldmod.mixins.json b/src/main/resources/shieldmod.mixins.json index 61cea8b..6974978 100644 --- a/src/main/resources/shieldmod.mixins.json +++ b/src/main/resources/shieldmod.mixins.json @@ -8,6 +8,7 @@ "FieldMixin", "ShieldMixin", "WorldFeatureLabyrinthMixin", + "PlayerRendererMixin" ], "injectors": { "defaultRequire": 1