Jump to content

Recommended Posts

Posted

Hello everyone, I've starting making a mod with a whole bunch of different tools and came to realise that I needed to make them repairable.

 

So, im trying to figure out to make it so that when i place an emerald, it will be repair my emerald tools. Can anyone tell me the code for that? Would I Put it in my main class file? or my tool file (EmeraldPickaxe.java).

 

This is what i used to created my tool material:

"public static EnumToolMaterial EMERALD_PICKAXE = EnumHelper.addToolMaterial("EMERALD_PICKAXE", 1, 0, 4.0F, 3, 5);"

 

and then declared it:

"pickaxeEmerald = new ItemPickaxeEmerald(pickaxeEmeraldID, EMERALD_PICKAXE).setUnlocalizedName("pickaxeEmerald");"

 

I'm fairly new to modding, and some things are difficulty. Thanks in advance!

 

 

Posted

I don't know about doing it in an anvil, I've looked but I can't quite work out how anvils work

 

Regardless, you could do this in two ways

 

One is by using multiple tools. It automatically adds in the repair feature where if you put two tools into a crafting grid it adds the remaining durabilities together up to the a full one

So if you've got two emerald pickaxes at half durability and you put them in the crafting grid, you'll get a single full one out of it

 

Or you could work around the anvil and just create a crafting recipe for it

as in

 

		GameRegistry.addShapelessRecipe(new ItemStack(Yourmod.pickaxeEmerald), new Object[]{
		new ItemStack(Item.emerald), new ItemStack (Yourmod.pickaxeEmerald)
	});

 

you could always do it that way

it'll mean that it doesn't take levels from you (not sure if that's good or bad for you) but you could use it as a temporary measure until you can work out anvils

Posted

Okay, I've got how you do it

 

You're going to need to make a few extra files though (if you haven't already got them)

 

First you need to make a custom EnumToolMaterial file, like so (I've added annotations in the files to show you what to change btw)

 

 

  Reveal hidden contents

 

 

You can use this to keep all your tool materials in as well, which is pretty cool, keeps the main mod file neater

 

After this, make a copy of ItemSword and ItemTool, like so

 

custom ItemTool:

 

  Reveal hidden contents

 

 

and custom ItemSword:

 

  Reveal hidden contents

 

 

Then, you need to go into your Emerald Sword/Pick/Axe/Shovel/Hoe and change "extends ItemTool" to "extends ItemDeadTool" and "extends ItemSword" to "extends ItemDeadSword"

Obviously, change "ItemDeadSword" and "ItemDeadTool" to whatever you named your custom ItemSword and custom ItemTool

 

HOWEVER

If you've set your tools (pick/axe/shovel/hoe but NOT sword) up like this:

 

  Reveal hidden contents

 

 

You need to change it to this:

 

 

  Reveal hidden contents

 

 

I add that in because where I originally got this tutorial from, it used "extends ItemAxe" rather than "ItemTool" and didn't have the "blocksEffectiveAgainst" bit

It NEEDS to extend ItemDeadTool for it to work

Obviously, you need to change it around a bit for each different tool, but that's up to you

 

 

Then, wherever you registered your EnumToolMaterial before this, you need to find and either delete or turn into an annotation

For me, it looked like this:

 

 

  Reveal hidden contents

 

 

I just added the "//" to turn it to an annotation, in case I ever decide to go back to how it was originally

 

Finally, you need to change the registry of the tools

 

It looks something like this:

 

  Reveal hidden contents

 

 

You need to add in your custom EnumToolMaterial to where you define which tool material this tool/sword is

 

So it looks like this

 

 

  Reveal hidden contents

 

 

And that should be it

 

I've tested it with the sword and with the Tut Axe I just added in for it and it definitely works

 

 

There may be an easier way to do this, but I've not found one and I'm not the best java coder in the world, so this might seem a little messy

But it works :D

 

 

I'm not exactly sure how it works for armour, but I imagine it'll be something pretty similar

 

Anyway, I hope this has helped, and wasn't too confusing or anything haha

I've tried to make it as simple as I can

 

(Actually worked this out like 2 hours ago but it wouldn't let me on the forum haha)

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.