Jump to content

[1.15.2] Is there an easy way to add stripping with axe to my custom log?


deerangle

Recommended Posts

I have a log block in my mod, and I want to make it possible to strip when right-clicked with an axe. Currently, I am using this horrible method with reflection:

private static void addStripping() throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
    Class clazz = Class.forName("net.minecraft.item.AxeItem");
    Field map = clazz.getDeclaredField("BLOCK_STRIPPING_MAP");

    Field modifiersField = Field.class.getDeclaredField("modifiers");
    modifiersField.setAccessible(true);
    modifiersField.setInt(map, map.getModifiers() & ~Modifier.FINAL);

    map.setAccessible(true);
    Map<Block, Block> strip_map = (Map<Block, Block>) map.get(null);
    HashMap<Block, Block> new_map = new HashMap<>(strip_map);
    new_map.put(Registry.BEECH_LOG_BLOCK, Registry.STRIPPED_BEECH_LOG_BLOCK);
    new_map.put(Registry.BEECH_WOOD_BLOCK, Registry.STRIPPED_BEECH_WOOD_BLOCK);
    map.set(null, new_map);
}

Is there any other way to do this?

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.