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

Hi hello,  I would like to do a question.

 

I did a custom axe, but I would like to know if there is a way to tell to my

axe that when the player break the specific block with this tool destroy

all the connected blocks with this id. I'm trying to destroy the trees just

breaking only one block of the tree.

 

I'm looking for a block break event or I don't know if there is a better way

to do.

 

Thanks for the help.

  • Author

I already check it the only that have the sources is Lumberjack I'll try to see.

 

Thanks.

@Override
public boolean onBlockDestroyed(ItemStack par1ItemStack, World par2World, int par3, int x, int y, int z, EntityLivingBase par7EntityLivingBase)
    {
	super.onBlockDestroyed(par1ItemStack, par2World, par3, x, y, z, par7EntityLivingBase);
	if(!par7EntityLivingBase.isSneaking()) //Checks if the entity is not sneaking.  You don't need if you don't want.
	{
		if(world.getBlockId(x, y, z) == Block.wood.blockID)
		{
			this.repeatChop(par2World, x, y, z);
		}
	}
        return true;
    }

public void repeatChop(World world, int x, int y, int z)
{
	for(int i = -1; i <= 1; i++)
	{
		for(int j = -1; j <= 1; j++)
		{
			for(int k = -1; k <= 1; k++)
			{
				if(world.getBlockId(x + i, y + j, z + k) == Block.wood.blockID)
				{
					world.destroyBlock(x + i, y + j, z + k, true);
					this.repeatChop(world, x + i, y + j, z + k);
				}
			}
		}
	}
}

 

This is some personal code that I've worked on for an item in my mod that does the same thing.  You can use it if you wish.  I've removed bits that aren't needed for you.

EDIT: Fixed some code I messed up.  All is good.

width=320 height=64http://www.slothygaming.com/img/ota.png[/img]

If your grammar is shit and you blatantly don't know what you're doing, I will not help you.

@Override
public boolean onBlockDestroyed(ItemStack par1ItemStack, World par2World, int par3, int x, int y, int z, EntityLivingBase par7EntityLivingBase)
    {
	super.onBlockDestroyed(par1ItemStack, par2World, par3, x, y, z, par7EntityLivingBase);
	if(!par7EntityLivingBase.isSneaking()) //Checks if the entity is not sneaking.  You don't need if you don't want.
	{
		if(world.getBlockId(x, y, z) == Block.wood.blockID)
		{
			this.repeatChop(par2World, x, y, z);
		}
	}
        return true;
    }

public void repeatChop(World world, int x, int y, int z)
{
	for(int i = -1; i <= 1; i++)
	{
		for(int j = -1; j <= 1; j++)
		{
			for(int k = -1; k <= 1; k++)
			{
				if(world.getBlockId(x + i, y + j, z + k) == Block.wood.blockID)
				{
					world.destroyBlock(x + i, y + j, z + k, true);
					this.repeatChop(world, x + i, y + j, z + k);
				}
			}
		}
	}
}

 

This is some personal code that I've worked on for an item in my mod that does the same thing.  You can use it if you wish.  I've removed bits that aren't needed for you.

EDIT: Fixed some code I messed up.  All is good.

 

That repeatChop method is highly recursive and is prone to repeatedly check the same nine blocks up to 3 times each. Doing 18 times the amount of work it needs to.

Well yes.  You can change it if you wish but it is needed if you want it to successfully chop down the entire tree.  If I just broke the loop, then it would only chop one log every time.  That would then cause you to barely cut down jungle trees.  The code lets you start your chop from the middle of a tree if needed and then removes everything below and above it that share the blockID of wood.

EDIT: Somewhat misunderstood what you said.  Well, no code is perfect.  If you find a way to optimize it tell me.

width=320 height=64http://www.slothygaming.com/img/ota.png[/img]

If your grammar is shit and you blatantly don't know what you're doing, I will not help you.

  • Author

Omg.Thanks, the code is working, that what I was looking for. Now watching your code I can

understand the process but is something that is I'm doing for myself I can't do because my

creativity is zero. Thanks.

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.