Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

How should I break blocks?


Kenkron
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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

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

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.