Last active
November 3, 2020 09:11
-
-
Save JTK222/fc376133b6d7562e9b9bea3bae9b7186 to your computer and use it in GitHub Desktop.
An example .java file for a custom Armor Model
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
//This is the base class, it does handle about 90% of the actual work. | |
//Just copy the class into your project. | |
//Methods that you shouldn't mess with are final | |
//See ArmorModelImplementation.java for an example Model using this | |
public abstract class ArmorBaseModel extends ModelBiped { | |
protected final ModelRenderer armorHead; | |
protected final ModelRenderer armorBody; | |
protected final ModelRenderer armorRightArm; | |
protected final ModelRenderer armorLeftArm; | |
protected final ModelRenderer armorRightLeg; | |
protected final ModelRenderer armorLeftLeg; | |
protected final ModelRenderer armorRightBoot; | |
protected final ModelRenderer armorLeftBoot; | |
private String texture; | |
public ArmorBaseModel(int textureWidth, int textureHeight, ResourceLocation texture){ | |
this.textureWidth = textureWidth; | |
this.textureHeight = textureHeight; | |
this.texture = texture.toString(); | |
armorHead = new ModelRenderer(this); | |
armorHead.setRotationPoint(0.0F, 0.0F, 0.0F); | |
bipedHead.addChild(armorHead); | |
armorBody = new ModelRenderer(this); | |
armorBody.setRotationPoint(0.0F, 0.0F, 0.0F); | |
bipedBody.addChild(armorBody); | |
armorRightArm = new ModelRenderer(this); | |
armorRightArm.setRotationPoint(0.0F, 0.0F, 0.0F); | |
bipedRightArm.addChild(armorRightArm); | |
armorLeftArm = new ModelRenderer(this); | |
armorLeftArm.setRotationPoint(0.0F, 0.0F, 0.0F); | |
bipedLeftArm.addChild(armorLeftArm); | |
armorRightLeg = new ModelRenderer(this); | |
armorRightLeg.setRotationPoint(0.0F, 0.0F, 0.0F); | |
bipedRightLeg.addChild(armorRightLeg); | |
armorLeftLeg = new ModelRenderer(this); | |
armorLeftLeg.setRotationPoint(0.0F, 0.0F, 0.0F); | |
bipedLeftLeg.addChild(armorLeftLeg); | |
armorRightBoot = new ModelRenderer(this); | |
armorRightBoot.setRotationPoint(0.0F, 0.0F, 0.0F); | |
bipedRightLeg.addChild(armorRightBoot); | |
armorLeftBoot = new ModelRenderer(this); | |
armorLeftBoot.setRotationPoint(0.0F, 0.0F, 0.0F); | |
bipedLeftLeg.addChild(armorLeftBoot); | |
setupArmorParts(); | |
} | |
public abstract void setupArmorParts(); | |
public final String getTexture(){ | |
return this.texture; | |
} | |
/** | |
* Feel free to override this method as needed. | |
* It's just required to hide armor parts depending on the equipment slot | |
*/ | |
public ModelBiped applySlot(EntityEquipmentSlot slot){ | |
armorHead.isHidden = true; | |
armorBody.isHidden = true; | |
armorRightArm.isHidden = true; | |
armorLeftArm.isHidden = true; | |
armorRightLeg.isHidden = true; | |
armorLeftLeg.isHidden = true; | |
armorRightBoot.isHidden = true; | |
armorLeftBoot.isHidden = true; | |
switch(slot){ | |
case HEAD: | |
armorHead.isHidden = false; | |
break; | |
case CHEST: | |
armorBody.isHidden = false; | |
armorRightArm.isHidden = false; | |
armorLeftArm.isHidden = false; | |
break; | |
case LEGS: | |
armorRightLeg.isHidden = false; | |
armorLeftLeg.isHidden = false; | |
break; | |
case FEET: | |
armorRightBoot.isHidden = false; | |
armorLeftBoot.isHidden = false; | |
break; | |
default: | |
break; | |
} | |
return this; | |
} | |
public final ArmorBaseModel applyEntityStats(ModelBiped defaultArmor){ | |
this.isChild = defaultArmor.isChild; | |
this.isSneak = defaultArmor.isSneak; | |
this.isRiding = defaultArmor.isRiding; | |
this.rightArmPose = defaultArmor.rightArmPose; | |
this.leftArmPose = defaultArmor.leftArmPose; | |
return this; | |
} | |
@Override | |
public final void render(Entity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale) { | |
this.setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale, entity); | |
copyModelAngles(this.bipedHead, this.armorHead); | |
copyModelAngles(this.bipedBody, this.armorBody); | |
copyModelAngles(this.bipedRightArm, this.armorRightArm); | |
copyModelAngles(this.bipedLeftArm, this.armorLeftArm); | |
copyModelAngles(this.bipedRightLeg, this.armorRightLeg); | |
copyModelAngles(this.bipedLeftLeg, this.armorLeftLeg); | |
copyModelAngles(this.bipedRightLeg, this.armorRightBoot); | |
copyModelAngles(this.bipedLeftLeg, this.armorLeftBoot); | |
GlStateManager.pushMatrix(); | |
if (isSneak) GlStateManager.translate(0.0F, 0.2F, 0.0F); | |
this.armorHead.render(scale); | |
this.armorBody.render(scale); | |
this.armorRightArm.render(scale); | |
this.armorLeftArm.render(scale); | |
this.armorRightLeg.render(scale); | |
this.armorLeftLeg.render(scale); | |
this.armorRightBoot.render(scale); | |
this.armorLeftBoot.render(scale); | |
GlStateManager.popMatrix(); | |
} | |
public final void setRotationAngle(ModelRenderer modelRenderer, float x, float y, float z) { | |
modelRenderer.rotateAngleX = x; | |
modelRenderer.rotateAngleY = y; | |
modelRenderer.rotateAngleZ = z; | |
} | |
} |
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
public class ArmorBaseItem extends ItemArmor { | |
private Supplier<Supplier<ArmorBaseModel>> armorModel; | |
public ArmorBaseItem(ArmorMaterial material, EntityEquipmentSlot equipmentSlot,, Supplier<Supplier<ArmorBaseModel>> armorModel) { | |
//The Render Index is not required for custom modelled armor, you can just default it to 0 | |
super(material, 0, equipmentSlot); | |
this.armorModel = armorModel; | |
//set the creative tab, and everything you might want to set here additionally | |
} | |
@Nullable | |
@Override | |
public final ModelBiped getArmorModel(EntityLivingBase entity, ItemStack itemStack, EntityEquipmentSlot armorSlot, ModelBiped defaultArmor) { | |
return armorModel.get().get().applyEntityStats(defaultArmor).applySlot(armorSlot); | |
} | |
@Nullable | |
@Override | |
public final String getArmorTexture(ItemStack stack, Entity entity, EntityEquipmentSlot slot, String type) { | |
return armorModel.getTexture(); | |
} | |
} |
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
public class ArmorModelImplementation extends ArmorBaseModel { | |
public WowAllianceArmor() { | |
super(/*texture width*/, /*texture height*/, new ResourceLocation(/*Texture path*/)); | |
} | |
@Override | |
public void setupArmorParts() { | |
//You need to cut out some parts from Blockbenchs exported model, and paste them here. | |
//You can see 2 examples of how this may look, adding a cube to the head | |
//and a rotated cube on the chest | |
//Export the unedited armor template to see which parts you should **not** copy over | |
armorHead.cubeList.add(new ModelBox(armorHead, 0, 18, -0.5F, -22.0F, -5.0F, 1, 22, 10, 0.0F, false)); | |
ModelRenderer bone = new ModelRenderer(this); | |
bone.setRotationPoint(0.0F, 0.0F, 0.0F); | |
setRotationAngle(bone, 0.0F, 0.0F, -0.7854F); | |
armorBody.addChild(bone); | |
bone.cubeList.add(new ModelBox(bone, 18, 82, -4.0F, 1.0F, -3.0F, 3, 3, 1, 0.0F, false)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment