Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.14.4] Using custom Models for armor.


Trufuj
 Share

Recommended Posts

So I've been working on this mod for a little bit of time and I had little problems getting "3-D" weapon models to work, and "2-D" re textures of base vanilla armor to work, but I can't seem to get my 3-D armor to work. Can someone show me an appropriate way to get it to render these are the two main classes I believe you will need for reference. for reference my helmet is called w1_helmet! Here are the classes. Just for a note the armor works technically, just without a model.

 

Balemia Class (main class)

package trunix.balemia;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.SwordItem;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import trunix.balemia.lists.ArmorMaterialList;
import trunix.balemia.lists.ItemList;
import trunix.balemia.lists.ToolMaterialList;

@Mod("balemia")
public class Balemia {

	public static Balemia instance;
	public static final String modid = "balemia";
	private static final Logger logger = LogManager.getLogger(modid);
	
	public static final ItemGroup balemia = new BalemiaItemGroup();
	
	public Balemia() {
		instance = this;
		
		FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
		FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientRegistries);
		
		MinecraftForge.EVENT_BUS.register(this);
	}
	
	private void setup (final FMLCommonSetupEvent event) {
		logger.info("setup reached");
	}
	
	private void clientRegistries (final FMLClientSetupEvent event) {
		logger.info("clientRegistries reached");
	}
	
	@Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
	public static class RegistryEvents {
		
		@SubscribeEvent
		public static void registerItems(final RegistryEvent.Register<Item> event) {
			
			event.getRegistry().registerAll (
				
				//Maces
				ItemList.woodenoak_mace = new SwordItem(ToolMaterialList.mace_mat, -1, -3.2f, new Item.Properties().group(balemia)).setRegistryName(location("woodenoak_mace")),
				ItemList.woodenspruce_mace = new SwordItem(ToolMaterialList.mace_mat, -1, -3.2f, new Item.Properties().group(balemia)).setRegistryName(location("woodenspruce_mace")),
				ItemList.woodenbirch_mace = new SwordItem(ToolMaterialList.mace_mat, -1, -3.2f, new Item.Properties().group(balemia)).setRegistryName(location("woodenbirch_mace")),
				ItemList.woodenjungle_mace = new SwordItem(ToolMaterialList.mace_mat, -1, -3.2f, new Item.Properties().group(balemia)).setRegistryName(location("woodenjungle_mace")),
				ItemList.woodenacacia_mace = new SwordItem(ToolMaterialList.mace_mat, -1, -3.2f, new Item.Properties().group(balemia)).setRegistryName(location("woodenacacia_mace")),
				ItemList.woodendarkoak_mace = new SwordItem(ToolMaterialList.mace_mat, -1, -3.2f, new Item.Properties().group(balemia)).setRegistryName(location("woodendarkoak_mace")),
				ItemList.stone_mace = new SwordItem(ToolMaterialList.mace_mat, 3, -3.2f, new Item.Properties().group(balemia)).setRegistryName(location("stone_mace")),
				ItemList.iron_mace = new SwordItem(ToolMaterialList.mace_mat, 5, -3.2f, new Item.Properties().group(balemia)).setRegistryName(location("iron_mace")),
				ItemList.gold_mace = new SwordItem(ToolMaterialList.mace_mat, 3, -3.2f, new Item.Properties().group(balemia)).setRegistryName(location("gold_mace")),
				ItemList.diamond_mace = new SwordItem(ToolMaterialList.mace_mat, 7, -3.2f, new Item.Properties().group(balemia)).setRegistryName(location("diamond_mace")),
				
				//Swords
				ItemList.w1_sword = new SwordItem(ToolMaterialList.w_mat, 6, -2.4f, new Item.Properties().group(balemia)).setRegistryName(location("w1_sword")),
				ItemList.w2_sword = new SwordItem(ToolMaterialList.w_mat, 8, -2.4f, new Item.Properties().group(balemia)).setRegistryName(location("w2_sword")),
				ItemList.w3_sword = new SwordItem(ToolMaterialList.w_mat, 10, -2.4f, new Item.Properties().group(balemia)).setRegistryName(location("w3_sword")),
				
				//Armor
				ItemList.w1_helmet = new ArmorItem(ArmorMaterialList.w_mat,EquipmentSlotType.HEAD,new Item.Properties().group(balemia)).setRegistryName(location("w1_helmet"))
				
				//Shields
				
					
					
			);
			
			logger.info("items reached");
		}
		
		private static ResourceLocation location(String name) {
			return new ResourceLocation(modid,name);
		}
	}
}

 

and here is my ArmorMaterialList enum:

package trunix.balemia.lists;
 
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.IArmorMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
import trunix.balemia.Balemia;

public enum ArmorMaterialList implements IArmorMaterial{
	
	w_mat("w_mat",400, new int[] {2,5,6,2}, 25, ItemList.w_mat, "item.armor.equip_iron", 0.0f);

	private static final int[] max_damage_array = new int[]{13,15,16,11};
	private String name, equipSound;
	private int durability, enchantability;
	private Item repairItem;
	private int[] damageReductionAmounts;
	private float toughness;
	

	private ArmorMaterialList(String name, int durability, int[] damageReductionAmounts, int enchantability, Item repairItem, String equipSound, float toughness) {
		this.name=name;
		this.equipSound=equipSound;
		this.durability=durability;
		this.enchantability=enchantability;
		this.repairItem=repairItem;
		this.damageReductionAmounts=damageReductionAmounts;
		this.toughness=toughness;
	}

	@Override
	public int getDurability(EquipmentSlotType slot) {
		return max_damage_array[slot.getIndex()]*this.durability;
	}

	@Override
	public int getDamageReductionAmount(EquipmentSlotType slot) {
		return this.damageReductionAmounts[slot.getIndex()];
	}

	@Override
	public int getEnchantability() {
		return this.enchantability;
	}

	@Override
	public SoundEvent getSoundEvent() {
		return new SoundEvent(new ResourceLocation(equipSound));
	}

	@Override
	public Ingredient getRepairMaterial() {
		return Ingredient.fromItems(this.repairItem);
	}

	@Override
	public String getName() {
		return Balemia.modid + ":" + this.name;
	}

	@Override
	public float getToughness() {
		return this.toughness;
	}

}

 

Edited by Trufuj
Link to comment
Share on other sites

This is very crude but it should at least help you get going. You need to put this in a custom ArmorItem class and have your armor items be of your custom ArmorItem:

 

    @OnlyIn(Dist.CLIENT)
    @Override
    public BipedModel getArmorModel(LivingEntity entity, ItemStack stack, EquipmentSlotType slot, BipedModel _default)
    {
        YOUR_ARMOR_MODEL model = new YOUR_ARMOR_MODEL();

        return model;
    }

    @Override
    public String getArmorTexture(ItemStack stack, Entity entity, EquipmentSlotType slot, String type)
    {
        return YOUR_TEXTURE_LOCATION;
    }

 

  • Like 1
Link to comment
Share on other sites

Ok so I'm not the best programmer, and thanks by the way for the starting code, so I threw it into a customArmorItem class like so:

package trunix.balemia;

import net.minecraft.client.renderer.entity.model.BipedModel;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import trunix.balemia.items.w1_armor;

public class customArmorItem {
    @OnlyIn(Dist.CLIENT)
    @Override
    public BipedModel getArmorModel(LivingEntity entity, ItemStack stack, EquipmentSlotType slot, BipedModel _default)
    {
        w1_armor model = new w1_armor();

        return model;
    }

    @Override
    public String getArmorTexture(ItemStack stack, Entity entity, EquipmentSlotType slot, String type)
    {
        return YOUR_TEXTURE_LOCATION;
    }
}

Couple of things there are errors such as "remove override" and other issues, what else must i do to make this work, since there are frequent issues. Also how would i call this in my main/balemia class which I posted earlier?

Link to comment
Share on other sites

package trunix.balemia;

import net.minecraft.client.renderer.entity.model.BipedModel;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.IArmorMaterial;
import net.minecraft.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import trunix.balemia.items.w1_armor;

public class CustomArmorItem extends ArmorItem {
    public CustomArmorItem(IArmorMaterial materialIn, EquipmentSlotType slot, Properties builder) {
		super(materialIn, slot, builder);
		// TODO Auto-generated constructor stub
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@OnlyIn(Dist.CLIENT)
    @Override
    public BipedModel getArmorModel(LivingEntity entity, ItemStack stack, EquipmentSlotType slot, BipedModel _default)
    {
        w1_armor model = new w1_armor(material, slot, null);

        return model;
    }

    @Override
    public String getArmorTexture(ItemStack stack, Entity entity, EquipmentSlotType slot, String type)
    {
        return "balemia:textures/models/armor/w1_helmet.png";
    }
} 

Okay awesome every error except one is fixed. Above is the entire class.

@OnlyIn(Dist.CLIENT)
    @Override
    public BipedModel getArmorModel(LivingEntity entity, ItemStack stack, EquipmentSlotType slot, BipedModel _default)
    {
        w1_armor model = new w1_armor(material, slot, null);

        return model;
    }

the return model line has an error where it want me to "change type of 'model' to 'Biped Model' or change method return type to 'w1_armor' both of which are wrong. I did change the main class method as well and set CustomArmorItem  properly. Let me know if you need more information, and thank you so much by the way it means a lot!  

Edited by Trufuj
Link to comment
Share on other sites

 

I think you mean this

 

 

 @Override
    @OnlyIn(Dist.CLIENT)
    public BipedModel getArmorModel(LivingEntity entityLiving, ItemStack itemStack, EquipmentSlotType armorSlot, BipedModel original) {
        return new Girl_Armor_Model(1.0f);
    }

 

 

I'm sorry to tell you that this code used to cause lag in the second and third person

 

Link to comment
Share on other sites

9 hours ago, Trufuj said:

package trunix.balemia;

import net.minecraft.client.renderer.entity.model.BipedModel;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.IArmorMaterial;
import net.minecraft.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import trunix.balemia.items.w1_armor;

public class CustomArmorItem extends ArmorItem {
    public CustomArmorItem(IArmorMaterial materialIn, EquipmentSlotType slot, Properties builder) {
		super(materialIn, slot, builder);
		// TODO Auto-generated constructor stub
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@OnlyIn(Dist.CLIENT)
    @Override
    public BipedModel getArmorModel(LivingEntity entity, ItemStack stack, EquipmentSlotType slot, BipedModel _default)
    {
        w1_armor model = new w1_armor(material, slot, null);

        return model;
    }

    @Override
    public String getArmorTexture(ItemStack stack, Entity entity, EquipmentSlotType slot, String type)
    {
        return "balemia:textures/models/armor/w1_helmet.png";
    }
} 

Okay awesome every error except one is fixed. Above is the entire class.


@OnlyIn(Dist.CLIENT)
    @Override
    public BipedModel getArmorModel(LivingEntity entity, ItemStack stack, EquipmentSlotType slot, BipedModel _default)
    {
        w1_armor model = new w1_armor(material, slot, null);

        return model;
    }

the return model line has an error where it want me to "change type of 'model' to 'Biped Model' or change method return type to 'w1_armor' both of which are wrong. I did change the main class method as well and set CustomArmorItem  properly. Let me know if you need more information, and thank you so much by the way it means a lot!  

You need to return your armor model, not the item (and your model class needs to extend BipedModel).

Edited by DarKnighT_0_9
Typo
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.