Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

New tool does not get recognized as tool when using .setRequiresTool on wood

Featured Replies

Posted

Again me,

 

the title basically says it. I'm using a reflection method in my main class to prevent chopping wood with your bare hands, so that you'll need proper tools to actually chop the wood. Works fine so far, but when trying to chop the wood with one of my newly imported copper axe (which I assume is the proper tool), it does not harvest the wooden block. Either it does not get recognized as tool, or it is recognized as weapon. But then, there seems to benothing wrong with 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");

  • Author

I think I found the solution. Of what ever reason the game treated my tool as weapon, so I had to put this code snippet into the axe class...

 

    public boolean canHarvestBlock(Block par1Block)
    {
        return par1Block.blockID == Block.wood.blockID;
    }

 

...I believe that the video tutorial that learned me how to import tools/weapons mixed both items. It's obvious that tools need another method of coding. However, it's working now, plus the code like I imported now, is much easier then the actual tool code needed...:D

I think I found the solution. Of what ever reason the game treated my tool as weapon, so I had to put this code snippet into the axe class...

 

    public boolean canHarvestBlock(Block par1Block)
    {
        return par1Block.blockID == Block.wood.blockID;
    }

 

...I believe that the video tutorial that learned me how to import tools/weapons mixed both items. It's obvious that tools need another method of coding. However, it's working now, plus the code like I imported now, is much easier then the actual tool code needed...:D

 

The problem I see here is that you can only harvest wooden logs with your axe. To let your axe harvest all wooden types, you can check if the block's material is equal to the Material.wood.

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.

  • Author

    public boolean canHarvestBlock(Block par1Block)
    {
        return par1Block.blockID == Block.wood.blockID || par1Block.blockID == Block.chest.blockID || par1Block.blockID == Block.planks.blockID || par1Block.blockID == Block.bookShelf.blockID || par1Block.blockID == Block.stoneDoubleSlab.blockID || par1Block.blockID == Block.stoneSingleSlab.blockID || par1Block.blockID == Block.pumpkin.blockID || par1Block.blockID == Block.pumpkinLantern.blockID;
    }

 

;)

    public boolean canHarvestBlock(Block par1Block)
    {
        return par1Block.blockID == Block.wood.blockID || par1Block.blockID == Block.chest.blockID || par1Block.blockID == Block.planks.blockID || par1Block.blockID == Block.bookShelf.blockID || par1Block.blockID == Block.stoneDoubleSlab.blockID || par1Block.blockID == Block.stoneSingleSlab.blockID || par1Block.blockID == Block.pumpkin.blockID || par1Block.blockID == Block.pumpkinLantern.blockID;
    }

 

;)

I notice "stoneDoubleSlab" and "stoneSingleSlab" in there... mayhap you want to change that to woodDouble/SingleSlab?

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

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...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.