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

I'll try write it in pseudo-code:

void floodFill(coordinates c, int depth){
  if depth > 50 then return;

  for each neighbour{
    if neighbour is blockIron{
      floodFill(neighbour's coords, depth+1);
    }
  }

  // iron block processing
  replace block at my coordinates (param c)
}

and this method would be called with coordinates of the first iron block (in real implementation you'll probably need more parameters to do the replacement, like passing an instance of World) and zero depth.

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

  • Author

Edit: That was much simpler when you explained it in pseudo code :D

 

Here is my current code: (how would I expand this to the 3D(y coordinate) plane?

 

public static void floodFill(World w, int x, int y, int z, EntityPlayer p, int depth)//depth starts at 0
{

	  if(depth > 50) return;

	  if(w.getBlockMaterial(x + 1, y, z) == Material.wood)//east + 1
	  {
		  doEntityDropAndDestroyBlock(p, w, x + 1, y, z);
		  w.setBlock(x + 1, y, z, 0);
		  floodFill(w,x + 1,y,z,p,depth + 1);
	  }
	  if(w.getBlockMaterial(x - 1, y, z) == Material.wood) //south - 1
	  {
		  doEntityDropAndDestroyBlock(p, w, x - 1, y, z);
		  w.setBlock(x - 1, y, z, 0);
		  floodFill(w,x-1,y,z,p,depth + 1);
	  }
	  if(w.getBlockMaterial(x, y, z + 1) == Material.wood)//North + 1
	  {
		  doEntityDropAndDestroyBlock(p, w, x, y, z + 1);
		  w.setBlock(x, y, z + 1, 0);
		  floodFill(w,x,y,z+1,p,depth + 1);
	  }
	  if(w.getBlockMaterial(x, y, z - 1) == Material.wood) //north - 1
	  {
		  doEntityDropAndDestroyBlock(p, w, x, y, z - 1);
		  w.setBlock(x, y, z - 1, 0);
		  floodFill(w,x,y,z-1,p,depth + 1);
	  }
}

 

Edit: I tried the following code but it didn't full work


public static void floodFill(World w, int x, int y, int z, EntityPlayer p, int depth)//depth starts at 0
{

	  if(depth > 900) return;

	  if(w.getBlockMaterial(x + 1, y, z) == Material.wood)//east + 1
	  {
		  doEntityDropAndDestroyBlock(p, w, x + 1, y, z);
		  w.setBlock(x + 1, y, z, 0);
		  if(w.getBlockMaterial(x + 1, y + 1, z) == Material.wood)//east + 1
		  {
			  doEntityDropAndDestroyBlock(p, w, x, y + 1, z);
			  w.setBlock(x + 1, y + 1, z, 0);
			  floodFill(w, x + 1, y + 1, z, p,depth + 1);
		  }
		  if(w.getBlockMaterial(x + 1, y - 1, z) == Material.wood)//east + 1
		  {
			  doEntityDropAndDestroyBlock(p, w, x, y - 1, z);
			  w.setBlock(x + 1, y - 1, z, 0);
			  floodFill(w, x + 1, y - 1, z, p,depth + 1);
		  }
		  floodFill(w,x + 1,y,z,p,depth + 1);
	  }
	  if(w.getBlockMaterial(x - 1, y, z) == Material.wood) //south - 1
	  {
		  doEntityDropAndDestroyBlock(p, w, x - 1, y, z);
		  w.setBlock(x - 1, y, z, 0);
		  if(w.getBlockMaterial(x - 1, y + 1, z) == Material.wood)//east + 1
		  {
			  doEntityDropAndDestroyBlock(p, w, x - 1, y + 1, z);
			  w.setBlock(x - 1, y + 1, z, 0);
			  floodFill(w, x - 1, y + 1, z, p,depth + 1);
		  }
		  if(w.getBlockMaterial(x - 1, y - 1, z) == Material.wood)//east + 1
		  {
			  doEntityDropAndDestroyBlock(p, w, x, y - 1, z);
			  w.setBlock(x, y - 1, z, 0);
			  floodFill(w, x, y - 1, z, p,depth + 1);
		  }
		  floodFill(w,x-1,y,z,p,depth + 1);
	  }
	  if(w.getBlockMaterial(x, y, z + 1) == Material.wood)//North + 1
	  {
		  doEntityDropAndDestroyBlock(p, w, x, y, z + 1);
		  w.setBlock(x, y, z + 1, 0);
		  if(w.getBlockMaterial(x, y + 1, z) == Material.wood)//east + 1
		  {
			  doEntityDropAndDestroyBlock(p, w, x, y + 1, z + 1);
			  w.setBlock(x, y + 1, z + 1, 0);
			  floodFill(w, x, y + 1, z + 1, p,depth + 1);
		  }
		  if(w.getBlockMaterial(x, y - 1, z) == Material.wood)//east + 1
		  {
			  doEntityDropAndDestroyBlock(p, w, x, y - 1, z + 1);
			  w.setBlock(x, y - 1, z + 1, 0);
			  floodFill(w, x, y - 1, z + 1, p,depth + 1);
		  }
		  floodFill(w,x,y,z+1,p,depth + 1);
	  }
	  if(w.getBlockMaterial(x, y, z - 1) == Material.wood) //north - 1
	  {
		  doEntityDropAndDestroyBlock(p, w, x, y, z - 1);
		  w.setBlock(x, y, z - 1, 0);
		  if(w.getBlockMaterial(x, y + 1, z) == Material.wood)//east + 1
		  {
			  doEntityDropAndDestroyBlock(p, w, x, y + 1, z - 1);
			  w.setBlock(x, y + 1, z - 1, 0);
			  floodFill(w, x, y + 1, z - 1, p,depth + 1);
		  }
		  if(w.getBlockMaterial(x, y - 1, z) == Material.wood)//east + 1
		  {
			  doEntityDropAndDestroyBlock(p, w, x, y - 1, z - 1);
			  w.setBlock(x, y - 1, z - 1, 0);
			  floodFill(w, x, y - 1, z - 1, p,depth + 1);
		  }
		  floodFill(w,x,y,z-1,p,depth + 1);
	  }
}

you ended up with weirdly much code :D, try using loops.

maybe something like this?:

floodFill(World w, int x, int y, int z, EntityPlayer p, int depth){ //
if(depth > 50) return;
for(int sx=-1;sx<=1;sx++){
  for(int sy=-1;sy<=1;sy++){
    for(int sz=-1;sz<=1;sz++){
      int nx=x+sx, ny=y+sy, nz=z+sz;
      if(w.getBlockMaterial(nx, ny, nz) == Material.wood){
        doEntityDropAndDestroyBlock(p, w, nx, ny, nz);
        w.setBlock(nx, ny, nz, 0);
        floodFill(w,nx, ny, nz,p,depth + 1);
      }
    }
  }
}
} //

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

  • Author

you ended up with weirdly much code :D, try using loops.

maybe something like this?:

 

Thanks it worked perfectly :D

 

not to self: dont set depth to 10000 and go on a flatworld thats made of the material bad things happen :P

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.