Jump to content

Recommended Posts

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

Posted

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

Posted

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

Posted

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

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

Announcements



×
×
  • Create New...

Important Information

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