Jump to content

Reflection method working in Eclipse, not in universal forged Minecraft!


Frontsalat

Recommended Posts

Hey folks,

 

I'm having this code...

 

    	Method m = ReflectionHelper.findMethod(Material.class, Material.wood, new String[] {"f", "setRequiresTool"});
        try {
                m.invoke(Material.wood);
        } catch (Throwable t) {
                t.printStackTrace();
        }

 

    public void breakSpeed(PlayerEvent.BreakSpeed event) {
            if (event.block.blockMaterial == Material.wood) {
                    if (!ForgeHooks.canToolHarvestBlock(event.block, event.metadata, event.entityPlayer.getCurrentEquippedItem()))
                            event.newSpeed = 0f;
            }
    }

 

...which makes it so that you can't harvest wood without proper tools. This is working perfectly in Eclipse, but does not after reobfuscating and using it on a universal forged Minecraft. I'm aware that "f", "setRequiresTool" gets reobfuscated to something that Minecraft can't read. Anyone has an idea how to transport the source code to something properly reobfuscated and useable in Minecraft?

Link to comment
Share on other sites

Hey folks,

 

I'm having this code...

 

    	Method m = ReflectionHelper.findMethod(Material.class, Material.wood, new String[] {"f", "setRequiresTool"});
        try {
                m.invoke(Material.wood);
        } catch (Throwable t) {
                t.printStackTrace();
        }

 

    public void breakSpeed(PlayerEvent.BreakSpeed event) {
            if (event.block.blockMaterial == Material.wood) {
                    if (!ForgeHooks.canToolHarvestBlock(event.block, event.metadata, event.entityPlayer.getCurrentEquippedItem()))
                            event.newSpeed = 0f;
            }
    }

 

...which makes it so that you can't harvest wood without proper tools. This is working perfectly in Eclipse, but does not after reobfuscating and using it on a universal forged Minecraft. I'm aware that "f", "setRequiresTool" gets reobfuscated to something that Minecraft can't read. Anyone has an idea how to transport the source code to something properly reobfuscated and useable in Minecraft?

 

Replace "f" with "func_76221_f". It's the SRG name of setRequiresTool. You can find it for methods under /mcp/conf/methods.csv and for fields under /mcp/conf/fields.csv

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

Replace "f" with "func_76221_f". It's the SRG name of setRequiresTool. You can find it for methods under /mcp/conf/methods.csv and for fields under /mcp/conf/fields.csv

 

Thank you very much. Works like a charm now. Could you answer another question then?

 

I set up a new copper axe as tool, but when trying to chop wood with it (when including the code that prevents chopping wood with your bare hands only), the axe does not seem to get recognized as tool, but rather as normal weapon, or the wrong tool. Here's the code:

 

Axe Code

 

package MetallurgyRealism;

import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.ItemAxe;

public class ToolAxeCopper extends ItemAxe{

public ToolAxeCopper(int i, EnumToolMaterial enumToolMaterial){
	super(i, enumToolMaterial);
	setMaxStackSize(1);
	setCreativeTab(MetallurgyRealismModBase.MetallurgyRealismTab);
}

@Override
public void registerIcons(IconRegister iconRegister)
{
	itemIcon = iconRegister.registerIcon("MetallurgyRealism:axecopper");
}

}

 

Enum Code

 

public static EnumToolMaterial CopperMaterial = EnumHelper.addToolMaterial("CopperMaterial", 3, 5, 15.0F, 1, 15);

 

Register and ID code

 

public static Item toolAxeCopper;
int toolAxeCopperID = 6029;
toolAxeCopper = new ToolAxeCopper(toolAxeCopperID, CopperMaterial).setUnlocalizedName("axecopper");
GameRegistry.registerItem(toolAxeCopper, "ToolAxeCopper");
LanguageRegistry.addName(toolAxeCopper, "Copper Axe");

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.