Jump to content

[SOLVED(sort of)] Enchantments not appearing for custom weapons


hotrods20

Recommended Posts

I am currently developing a mod that adds some custom weapons.  I am not entirely sure on what is wrong so I'll post code.

 

public static EnumToolMaterial obsidian = EnumHelper.addToolMaterial("OBSIDIAN", 3, -1, 6.0F, 2, 14);
public static Item oSword = new ItemSword(3500, OTMain.obsidian).setCreativeTab(tabObsidianTools).setUnlocalizedName("oSword");
public static Item oAxe = new ItemAxe(3501, OTMain.obsidian).setCreativeTab(tabObsidianTools).setUnlocalizedName("oAxe");
public static Item oHoe = new ItemHoe(3502, OTMain.obsidian).setCreativeTab(tabObsidianTools).setUnlocalizedName("oHoe");
public static Item oPickaxe = new ItemPickaxe(3503, OTMain.obsidian).setCreativeTab(tabObsidianTools).setUnlocalizedName("oPickaxe");
public static Item oSpade = new ItemSpade(3504, OTMain.obsidian).setCreativeTab(tabObsidianTools).setUnlocalizedName("oSpade");

 

The problem I am having is when I place the items in the enchantment table, no enchantments show up.  I can do /enchant and I can place them in Anvils and enchant them.  Any suggestions or anyone know how to get enchantments to appear for these items?

 

Solution:

So, if a tool material has 0 or lower amount of uses, then it won't be able to be enchanted in a enchantment table.  Solution is to modify the tool in its own class to not take any damage from anything.

 

That means if you want to have items that don't suffer from durability loss, you need to have:

@Override
public boolean hitEntity(ItemStack par1ItemStack, EntityLiving par2EntityLiving, EntityLiving par3EntityLiving)
{
	par1ItemStack.damageItem(0, par3EntityLiving);
	return true;
}

@Override
public boolean onBlockDestroyed(ItemStack par1ItemStack, World par2World, int par3, int par4, int par5, int par6, EntityLiving par7EntityLiving)
    {
	par1ItemStack.damageItem(0, par7EntityLiving);
	return true;
    }

 

In each items class file or in a main tools file they all read file.

width=320 height=64http://www.slothygaming.com/img/ota.png[/img]

If your grammar is shit and you blatantly don't know what you're doing, I will not help you.

Link to comment
Share on other sites

I just use the ItemSword.java which is a vanilla class.  By using that and using my custom tool material, it should work.

 

The code from ItemSword.java:

public int getItemEnchantability()
    {
        return this.toolMaterial.getEnchantability();
    }[/Code]

This should work because it gets the ability to be enchanted from the material.

 

My material:

[Code]public static EnumToolMaterial obsidian = EnumHelper.addToolMaterial("OBSIDIAN", 3, -1, 6.0F, 2, 14);[/Code]

The last number in my code is the ability for the item to be enchanted's factor.  That one is equal to iron.  Gold having the highest of course.

width=320 height=64http://www.slothygaming.com/img/ota.png[/img]

If your grammar is shit and you blatantly don't know what you're doing, I will not help you.

Link to comment
Share on other sites

^works too, but it's easier with the code i supplied. Basically, yes this can be enchanted. what can be enchanted onto it is already determined by the item type. either weapon or tool etc. Your doing work minecraft already does. (code supplied is tested)

 

public int getItemEnchantability()

    {

        return 1;

    }

 

in case you missed it from my spam

Never understood why textures were so complicated.

Link to comment
Share on other sites

i'd recommend not using a custom item material for now, and let it be treated as gold iron diamond etc. I honestly don't know how to add enchanting compatibility to custom blocks, it's probably something within the material file.

Never understood why textures were so complicated.

Link to comment
Share on other sites

I've come to the conclusion that when the ItemSword class is looking for a material, it will only accept materials that have been declared in EnumToolMaterial because I had my Obsidian material just copy the EnumToolMaterial.IRON and it let my tool be enchanted.  Is it possibly how the material is added to the game?

width=320 height=64http://www.slothygaming.com/img/ota.png[/img]

If your grammar is shit and you blatantly don't know what you're doing, I will not help you.

Link to comment
Share on other sites

	public static EnumToolMaterial obsidian = EnumHelper.addToolMaterial("OBSIDIAN", 3, -1, 6.0F, 2, 12);
public static Item oSword = new ItemSword(3500, obsidian).setCreativeTab(tabObsidianTools).setUnlocalizedName("oSword");
public static Item oAxe = new ItemAxe(3501, obsidian).setCreativeTab(tabObsidianTools).setUnlocalizedName("oAxe");
public static Item oHoe = new ItemHoe(3502, obsidian).setCreativeTab(tabObsidianTools).setUnlocalizedName("oHoe");
public static Item oPickaxe = new ItemPickaxe(3503, obsidian).setCreativeTab(tabObsidianTools).setUnlocalizedName("oPickaxe");
public static Item oSpade = new ItemSpade(3504, obsidian).setCreativeTab(tabObsidianTools).setUnlocalizedName("oSpade");

That is all the code that I have created in the sense of creating the items.  I have already registered the items and all that.  The sword code can be found in ItemSword in net.minecraft.item.

width=320 height=64http://www.slothygaming.com/img/ota.png[/img]

If your grammar is shit and you blatantly don't know what you're doing, I will not help you.

Link to comment
Share on other sites

I did try adding classes for each item I am adding but it still didn't help.  It seems like the enchantment table just doesn't get the value for my item.  Has any mods made items that can be enchanted via enchantment table?

width=320 height=64http://www.slothygaming.com/img/ota.png[/img]

If your grammar is shit and you blatantly don't know what you're doing, I will not help you.

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
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.