Skip to content

Commit

Permalink
wip 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Rin committed Aug 31, 2024
1 parent 53d086a commit e49c0fe
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 9 deletions.
16 changes: 16 additions & 0 deletions src/main/java/mizurin/shieldmod/EntityRendererAccessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package mizurin.shieldmod;


import net.minecraft.client.render.EntityRenderDispatcher;
import net.minecraft.client.render.entity.EntityRenderer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(value = EntityRenderer.class, remap = false)
public interface EntityRendererAccessor {
@Accessor
EntityRenderDispatcher getRenderDispatcher();
@Invoker("loadTexture")
void invokeLoadTexture(String texture);
}
1 change: 1 addition & 0 deletions src/main/java/mizurin/shieldmod/ShieldMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
public class ShieldMod implements ModInitializer, GameStartEntrypoint, ClientStartEntrypoint{
public static final String MOD_ID = "shieldmod";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
public static int playerArmorRenderOffset = 0;

public static int itemID;
public static int entityID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import mizurin.shieldmod.ColoredArmorTexture;
import mizurin.shieldmod.IColoredArmor;
import mizurin.shieldmod.ShieldMod;
import net.minecraft.client.render.entity.LivingRenderer;
import net.minecraft.client.render.model.ModelBase;
import net.minecraft.core.entity.EntityLiving;
Expand Down Expand Up @@ -50,7 +51,7 @@ private void captureLocals(T entity, double x, double y, double z, float yaw1, f
}
@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;
ShieldMod.playerArmorRenderOffset = 0;
if (entity instanceof EntityPlayer){
ItemStack itemstack = ((EntityPlayer) entity).inventory.armorItemInSlot(3 - renderPass);
if (itemstack != null && itemstack.getItem() instanceof IColoredArmor){
Expand All @@ -63,9 +64,9 @@ private boolean hijackRenderPass(LivingRenderer instance, T entity, int renderPa
this.renderPassModel.render(limbSwing, limbYaw, ticksExisted, headYaw - headYawOffset, headPitch, scale);
GL11.glDisable(3042);
GL11.glEnable(3008);
PrismaticLibe.playerArmorRenderOffset++;
ShieldMod.playerArmorRenderOffset++;
}
PrismaticLibe.playerArmorRenderOffset = 0;
ShieldMod.playerArmorRenderOffset = 0;
return false;
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/mizurin/shieldmod/mixins/PlayerRendererMixin.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package mizurin.shieldmod.mixins;

import mizurin.shieldmod.ColoredArmorTexture;
import mizurin.shieldmod.EntityRendererAccessor;
import mizurin.shieldmod.IColoredArmor;
import mizurin.shieldmod.ShieldMod;
import mizurin.shieldmod.item.ArmorColored;
import net.minecraft.client.Minecraft;
import net.minecraft.client.render.entity.PlayerRenderer;
Expand Down Expand Up @@ -31,8 +33,8 @@ private void colorArmor(EntityPlayer entity, int renderPass, float partialTick,
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();
if (ShieldMod.playerArmorRenderOffset > armorTextures.length) return;
Color color = armorTextures[ShieldMod.playerArmorRenderOffset].getColor();
GL11.glColor4f((color.getRed()/255f) * brightness, (color.getGreen()/255f) * brightness, (color.getBlue()/255f) * brightness,color.getAlpha()/255f);
}
}
Expand All @@ -44,10 +46,10 @@ private void colorArmorOff(EntityPlayer entity, int renderPass, float partialTic
@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;
if (ShieldMod.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");
((EntityRendererAccessor)instance).invokeLoadTexture("/armor/" + armorTextures[ShieldMod.playerArmorRenderOffset].getArmorTexture() + "_" + (renderPass != 2 ? 1 : 2) + ".png");
} else {
((EntityRendererAccessor)instance).invokeLoadTexture(string);
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/shieldmod.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
"mixins": [
"BlockFarmlandMixin",
"FieldMixin",
"LivingRendererMixin",
"PlayerRendererMixin",
"ShieldMixin",
"WorldFeatureLabyrinthMixin",
"PlayerRendererMixin"
"WorldFeatureLabyrinthMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit e49c0fe

Please sign in to comment.