generated from Turnip-Labs/bta-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rin
committed
Aug 31, 2024
1 parent
1a6d4ce
commit 53d086a
Showing
5 changed files
with
154 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
74 changes: 73 additions & 1 deletion
74
src/main/java/mizurin/shieldmod/mixins/LivingRendererMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<T extends EntityLiving> { | ||
@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); | ||
} | ||
} |
55 changes: 54 additions & 1 deletion
55
src/main/java/mizurin/shieldmod/mixins/PlayerRendererMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Boolean> 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<Boolean> 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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters