Jump to content

[1.7.10] Changing vanilla tools properties without editing base code


cw84

Recommended Posts

As the title says... I am looking for a way to change vanilla tools properties without editing the base code.

I tried using reflection, but it appears I've done nothing:

import net.minecraft.item.Item.ToolMaterial;
import cpw.mods.fml.relauncher.ReflectionHelper;

public class ModVanilla
{
public static void changeSettings()
{
	// Adjusting Gold Tools
	ReflectionHelper.setPrivateValue(ToolMaterial.class, ToolMaterial.GOLD, 2, 5);
	ReflectionHelper.setPrivateValue(ToolMaterial.class, ToolMaterial.GOLD, 750, 6);
	ReflectionHelper.setPrivateValue(ToolMaterial.class, ToolMaterial.GOLD, 8.0F, 7);
	ReflectionHelper.setPrivateValue(ToolMaterial.class, ToolMaterial.GOLD, 2.5F, ;
	ReflectionHelper.setPrivateValue(ToolMaterial.class, ToolMaterial.GOLD, 10, 9);

	// Adjusting Diamond Tools
	ReflectionHelper.setPrivateValue(ToolMaterial.class, ToolMaterial.EMERALD, 10.0F, 7);

	// Adjusting Stone Tools
	ReflectionHelper.setPrivateValue(ToolMaterial.class, ToolMaterial.STONE, 14, 9);

	// Adjusting Iron Tools
	ReflectionHelper.setPrivateValue(ToolMaterial.class, ToolMaterial.IRON, 12, 9);
}
}

 

Any help here would be great! Thanks guys...

Link to comment
Share on other sites

Try using the version of

ReflectionHelper.setPrivateVersion()

which accepts a String, instead of a number, so you can just specify the field name instead of the index.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

So technically, this code is correct and should be working? I only ask because while it doesn't appear to crash the game, it also doesn't appear to be changing any values. I feel maybe there is more to the puzzle than this? I am calling this class in my main last (prior to an event listener).

Link to comment
Share on other sites

As the title says... I am looking for a way to change vanilla tools properties without editing the base code.

I tried using reflection, but it appears I've done nothing:

import net.minecraft.item.Item.ToolMaterial;
import cpw.mods.fml.relauncher.ReflectionHelper;

public class ModVanilla
{
public static void changeSettings()
{
	// Adjusting Gold Tools
	ReflectionHelper.setPrivateValue(ToolMaterial.class, ToolMaterial.GOLD, 2, 5);
	ReflectionHelper.setPrivateValue(ToolMaterial.class, ToolMaterial.GOLD, 750, 6);
	ReflectionHelper.setPrivateValue(ToolMaterial.class, ToolMaterial.GOLD, 8.0F, 7);
	ReflectionHelper.setPrivateValue(ToolMaterial.class, ToolMaterial.GOLD, 2.5F, ;
	ReflectionHelper.setPrivateValue(ToolMaterial.class, ToolMaterial.GOLD, 10, 9);

	// Adjusting Diamond Tools
	ReflectionHelper.setPrivateValue(ToolMaterial.class, ToolMaterial.EMERALD, 10.0F, 7);

	// Adjusting Stone Tools
	ReflectionHelper.setPrivateValue(ToolMaterial.class, ToolMaterial.STONE, 14, 9);

	// Adjusting Iron Tools
	ReflectionHelper.setPrivateValue(ToolMaterial.class, ToolMaterial.IRON, 12, 9);
}
}

 

Any help here would be great! Thanks guys...

 

All you need:

    @EventHandler
    public void postInit(FMLPostInitializationEvent event)
    {
     changeSettings()
    }

Link to comment
Share on other sites

I can't seem to get this to work...

I've done what Lewie suggested: added my changeSettings() to FMLPostInitializationEvent.... previously I had it in my FMLInitializationEvent.

- No Luck -

 

I've done what larsgerrits suggested and used the string version... unfortunately I'm not sure I'm using it correctly because when I tried something like:

ReflectionHelper.setPrivateValue(ToolMaterial.class, ToolMaterial.GOLD, 750, "maxUses");

It just simply crashes on loading Minecraft.

 

I found this post: http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/2151027-1-7-x-using-reflection-to-modify-vanilla-values

And this is where I've been basing my changes off of. Though, apparently, I am not doing things correctly.

 

What am I doing wrong here?

Link to comment
Share on other sites

Changing the ToolMaterials values won't get you much, because:

1. they're final, you need some reflection black magic to actually change the value (removing the final modifier of maxUses and set the value)

2. Your mod gets initialized after the vanilla stuff, so even if you edit the value, the max damage of the items was already set using the original value (I've tried it)

 

So if you really need to change the golds max uses, I suggest you go either coremod and change the value of the material before any items get initialized or change the tool materials value as well as all the items max damage values.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

I can't seem to get this to work...

I've done what Lewie suggested: added my changeSettings() to FMLPostInitializationEvent.... previously I had it in my FMLInitializationEvent.

- No Luck -

 

I've done what larsgerrits suggested and used the string version... unfortunately I'm not sure I'm using it correctly because when I tried something like:

ReflectionHelper.setPrivateValue(ToolMaterial.class, ToolMaterial.GOLD, 750, "maxUses");

It just simply crashes on loading Minecraft.

 

I found this post: http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/2151027-1-7-x-using-reflection-to-modify-vanilla-values

And this is where I've been basing my changes off of. Though, apparently, I am not doing things correctly.

 

What am I doing wrong here?

 

I copied your code, put changeSettings() in PostInit and I did a quick test to mine diamond with a gold pick - it worked.

Link to comment
Share on other sites

You're right. The tool harvest level did change. Appears I had to do something like Item.gold_pickaxe.setMaxDamage(int) to change the max uses of the item. I believe this answers why:

2. Your mod gets initialized after the vanilla stuff, so even if you edit the value, the max damage of the items was already set using the original value (I've tried it)

 

So if you really need to change the golds max uses, I suggest you go either coremod and change the value of the material before any items get initialized or change the tool materials value as well as all the items max damage values.

 

Thanks for all the help and insight on this guy's!

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.