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.

Featured Replies

Posted

I'm new to forging, and trying out block breaking.  Naturally, I want to break blocks the "right" way (meaning, I want to break blocks as though a player had broken them with the right tool without enchantment.).

 

I've gotten blocks to break with this method, which tree-capitator seems to use:

 

    public void breakBlock(World w, Block b, int x,int y,int z){
    	ArrayList<ItemStack> drops=b.getDrops(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
    	b.dropBlockAsItem(w, x, y, z, world.getBlockMetadata(x, y, z), 0);
    	world.removeTileEntity(x, y, z);
    	world.setBlockToAir(x, y, z);
    }

 

But it seems like I should break blocks this way:

 

    public void breakBlock(World w, Block b, int x,int y,int z){
    	int fortune = 0;
    	boolean silkTouch=false;
    	int metadata = w.getBlockMetadata(x, y, z);
    	ArrayList<ItemStack> drops = b.getDrops(w, x, y, z, metadata, fortune);
    	ForgeEventFactory.fireBlockHarvesting(drops, w, b, x, y, z, metadata, fortune, 1, false, null);
    }

 

However, the latter doesn't work.

 

I know there's more than one way to solve a problem, but if one adheres to convention, I'd rather use that way.  Anyone know how the player does it?

I think that you have to call this in the end of your method: super.breakBlock(world, x, y, z, block, meta);

 

To break your block with a specific tool you can use "harvestBlock", then player.getHeldItem().getItem().

 

I hope this will help. :)

  • Author

Thanks for the advice ;), but it didn't work (assuming that the superclass in your response was Block.)

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.