cw84 Posted November 10, 2014 Share Posted November 10, 2014 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... Quote Link to comment Share on other sites More sharing options...
larsgerrits Posted November 11, 2014 Share Posted November 11, 2014 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. Quote 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 More sharing options...
cw84 Posted November 11, 2014 Author Share Posted November 11, 2014 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). Quote Link to comment Share on other sites More sharing options...
Lewie Posted November 12, 2014 Share Posted November 12, 2014 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() } Quote Link to comment Share on other sites More sharing options...
cw84 Posted November 12, 2014 Author Share Posted November 12, 2014 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? Quote Link to comment Share on other sites More sharing options...
SanAndreaP Posted November 12, 2014 Share Posted November 12, 2014 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. Quote 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 More sharing options...
Lewie Posted November 12, 2014 Share Posted November 12, 2014 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. Quote Link to comment Share on other sites More sharing options...
cw84 Posted November 12, 2014 Author Share Posted November 12, 2014 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.