Jump to content

Recommended Posts

Posted

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.

Posted

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);
	  }
}

Posted

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.

Posted

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

×   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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I tried do download the essential mod to my mod pack but i didnt work. I paly on 1.21 and it should work. I use neoforge for my modding. The weird things is my friend somehow added the mod to his modpack and many others that I somehow can´t. Is there anything i can do? 
    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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