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've been wondering for a while. Would it be possible to make a block to detect if a block touching it is broken or set to air. Because I currently have a block that breaks nearby blocks of it's name, but I would like to try to make it cause all blocks of itself that it is touching... I can assume it has to do with NeighborBlockchange, or similar method, but not sure how to do it. I will say, sugarcane and cactus could be a similar comparison, except it needs to not drop items, except for the one destroyed by player.

Member of Aerotech Networks, a Multi-Gaming server.

Also Currently porting the "Rise of the Automatons" minecraft mod

  • Author

hmm, so guessing it's not possible to make a block (when destroyed by player) to break all blocks of itself. Like if you lay a block in an indefinite line and break one of them anywhere in said line it would result in the whole line breaking, and giving the drop at the one broken only?

Member of Aerotech Networks, a Multi-Gaming server.

Also Currently porting the "Rise of the Automatons" minecraft mod

  • Author

Hmm... So going to assume I should use a for loop to simplify the checking of blocks on each side and make each block set themselves to air? But wouldn't this make the blocks break if any neighbor change, like if you break a stone that is next to said block? Also it seems that when I use a code similar to this:

 

    	 for (int i = x-1; i <= x+1; ++i) {
    		 for (int k = y-1; k <= y+1; ++k) {
    			 for (int j = z-1; j <= z+1; ++j) {
        		     if(world.getBlock(i, k, j) == this) 
        	    	    {
        	    	    	world.setBlockToAir(i, k, j);
        	    	    }
    			 }
    		 }
    	 }

 

I don't seem to be able to make a block break in a 3x3x3 cube. What's wrong with it?

 

 

edit--

Ok I have tried to make it check the blocks around it I think, but now it makes it so when I place any block near one of mine it makes the ones it directly touches to disappear. This is the code:

 

public void onNeighborBlockChange(World world, int x, int y, int z, Block block)
{
	if(block != this){
		world.setBlockToAir(x, y, z);
	}
}

 

 

Member of Aerotech Networks, a Multi-Gaming server.

Also Currently porting the "Rise of the Automatons" minecraft mod

  • Author

OK great news, I finally got the code to work, so simple I passed it over, all I had to do was add a Boolean that is set to false at the start of the class, then make it get set to true in the onBlockDestroyedByPlayer method, and then have the Boolean as one of the attributes of the if statement within the onNeighborBlockChange method. Really shrunk my old code. Who needs it to break in a 3x3x3 cube.

Member of Aerotech Networks, a Multi-Gaming server.

Also Currently porting the "Rise of the Automatons" minecraft mod

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.