Jump to content

Recommended Posts

Posted

Hi,

I was wondering how to create an Item so that it can be used as a piece of wearable armor.

Here is my armor class:

package uc.armor;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraftforge.common.ISpecialArmor.ArmorProperties;
import uc.mainmod.UltraCraft;

public class EmeraldArmor extends ItemArmor {
public EmeraldArmor(ArmorMaterial p_i45325_1_, int p_i45325_2_,
		int p_i45325_3_) {
	super(p_i45325_1_, p_i45325_2_, p_i45325_3_);
}

public ArmorProperties getProperties(EntityLivingBase player,
		ItemStack armor, DamageSource source, double damage, int slot) {
	return new ArmorProperties(0, 0, 0);
}

public int getArmorDisplay(EntityPlayer player, ItemStack armor, int slot) {
	return 4;
}

public void damageArmor(EntityLivingBase entity, ItemStack stack,
		DamageSource source, int damage, int slot) {
	stack.damageItem(damage * 2, entity);
}

public String getArmorTexture(ItemStack armor, Entity entity, int slot,
		String type) {
	if (armor.getItem() == UltraCraft.emeraldLeggings) {
		return "UltraCraft:textures/armor/emerald_layer_2.png";
	} else {
		return "UltraCraft:textures/armor/emerald_layer_1.png";
	}
}

public CreativeTabs[] getCreativeTabs() {
	return new CreativeTabs[] { CreativeTabs.tabCombat };
}

public boolean getIsRepairable(ItemStack armor, ItemStack stack) {
	return stack.getItem() == Items.emerald;
}
}

 

I also have:

public static Item emeraldHelmet;
public static Item emeraldChestplate;
public static Item emeraldLeggings;
public static Item emeraldBoots;

 

But how do I make those items pieces of wearable armor?

Sup bruh.

Posted

Also, where do I call the constructor for EmeraldArmor? What should I give for its parameters?

 

It's a fucking item.  Call its constructor the same place and the same time as you call the constructors for all your other items.

 

And its parameter types are clearly listed, especially if you follow the super constructor and actually LOOK at ItemArmor.  ArmorMaterial, armorType (what slot it goes in), and renderID.

 

Hint:

You will need to define a new ArmorMaterial.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

public class EmeraldArmor extends ItemArmor {
public addarmor(String name, int index, int type) {
	super(yourmainclass.ArmorMaterial_EMERALD, index, type);

	this.setCreativeTab(CreativeTabs.tabCombat);
	this.setUnlocalizedName(name);
	GameRegistry.registerItem(this, name);
}

@Override
public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type) {
	if (slot == 2) {
		return yourmodid + ":textures/models/armor/emerald_layer_2.png";
	} else {
		return yourmodid + ":textures/models/armor/emerald_layer_1.png";
	}
}
}

 

 

To the main code:

	public static ArmorMaterial ArmorMaterial_EMERALD = EnumHelper.addArmorMaterial("EMERALD", "emerald", 44, new int[] {4, 10, 8, 4}, 15);

 

 

[/size]When you register;

 

	emeraldHelmet = new EmeraldArmor("emeraldhelmet", 4, 0);

	emeraldChestplate = new EmeraldArmor("emeraldchestplate",  4, 1);

	emeraldLeggings = new EmeraldArmor("emeraldleggings", 4, 2);

	emeraldBoots = new EmeraldArmor("emeraldboots", 4, 3);

 

 

Put your emerald models to;

\src\main\resources\assets\your modid\textures\models\armor

 

 

 

You need to register item textures with modelregistry.

Posted

1. You can't super() if the method you're using isn't the constructor, and that would be the incorrect constructor parameters.

2. Where is

getArmorTexture

ran? Does the game run it itself, like an init method? Or do I need to call it myself?

3: What should an armor .json file look like?

Sup bruh.

Posted

I'm a bit new to all of this, so I may butcher exact language pretty badly here.  (I appreciate being corrected by knowers.)  Thus I go!

 

1.  I believe the super() method you're referring to is defining the constructor used in the extended ItemArmor java.  This is why you're required to define it in your custom Armor class perhaps exactly like xwerswoodx has done.  If you're using Eclipse, you can hold Ctrl, mouse over super and click Open Implementation.  It will show you why this needs to be defined in your custom Armor.

 

2.  The getArmorTexture is a process (or function if you will) that is provided in the ItemArmor java as well.  If you're using Eclipse, you can hold Ctrl, mouse over getArmorTexture and click Open Super Implementation.  It will open the ItemArmor java file and direct you straight to this function- this is why we're able to utilize it in your custom class.  You will deal with your Armor items in your Mod's Item's class perhaps entirely like this...

 

public class YourModItems
{
public static Item mithril_helmet;
public static Item mithril_chestplate;
public static Item mithril_boots;
public static Item mithril_leggings;

public static final ItemArmor.ArmorMaterial mithrilArmorMaterial = EnumHelper.addArmorMaterial("mithirlArmorMaterial", "mithrilArmorMaterial", 3000, new int[]{4,10,7,5}, 30);

public static void init()
{
	mithril_helmet = new ItemMithrilArmor(mithrilArmorMaterial, 0, 0).setUnlocalizedName("mithril_helmet").setCreativeTab(SupercraftMod.tabSupercraft);
	mithril_chestplate = new ItemMithrilArmor(mithrilArmorMaterial, 0, 1).setUnlocalizedName("mithril_chestplate").setCreativeTab(SupercraftMod.tabSupercraft);
	mithril_leggings = new ItemMithrilArmor(mithrilArmorMaterial, 0, 2).setUnlocalizedName("mithril_leggings").setCreativeTab(SupercraftMod.tabSupercraft);
	mithril_boots =	new ItemMithrilArmor(mithrilArmorMaterial, 0, 3).setUnlocalizedName("mithril_boots").setCreativeTab(SupercraftMod.tabSupercraft);
}

public static void register()
{
	GameRegistry.registerItem(mithril_helmet, mithril_helmet.getUnlocalizedName().substring(5));
	GameRegistry.registerItem(mithril_chestplate, mithril_chestplate.getUnlocalizedName().substring(5));
	GameRegistry.registerItem(mithril_leggings, mithril_leggings.getUnlocalizedName().substring(5));
	GameRegistry.registerItem(mithril_boots, mithril_boots.getUnlocalizedName().substring(5));
}

public static void registerRenders()
{
	registerRender(mithril_helmet);
	registerRender(mithril_chestplate);
	registerRender(mithril_leggings);
	registerRender(mithril_boots);
}

public static void registerRender(Item item)
{
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Reference.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory"));
}
}

 

3.  Tip: Get into the habit of scouring the code yourself because easy questions like this can put some people out.  The trick is, of course, knowing when something is simple and when it might require some help ;).  For example, what a typical json file looks like is easy to discover by opening your forge minecraft assets folder.  My directory is: forgeSrc-yourVersion/assets/minecraft/models/item/ this would be the directory you would look to find json files for typical items like armor.  Json files are stored in the forgeSrc-yourVersion/assets/minecraft/models directory.  In the item folder, open material_helmet.json, copy that code into a new text file, and save it appropriately.

 

If this is still confusing for you, search on YouTube for Mr. Crayfish's 1.7 modding series- episode 12 deals with armor and he steps you through things.

 

Hope this resolves your issues.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.