Jump to content

Recommended Posts

Posted

Not actually a problem, i need a help to figure out how to generate common structures in forests that fits with the forest itself. So the structure is actually generated on the solid ground, not in water, not in air. Right now to do this i got this check in the function that loads my structure

flag = true;
			if(check) {
				for (int i = 0; i < 16; i++) {
					for (int j = 0; j < 16; j++) {
						if (!world.getBlockState(pos.add(i, -1, j)).getBlock().equals(Blocks.GRASS)) {
							flag = false;
							break;
						}
					}
				}
			}


			if (flag) {
//place the structure}

 

So here i'm saying that if an area of 16x16 blocks in the forest is made of grass than spawn the structure. But, as you might guess, in the forest is really hard to have flat plains area, and this results in the structure being pretty rare. So how can i do to make the structure generate in a proper way BUT let it not be too rare?

Don't blame me if i always ask for your help. I just want to learn to be better :)

Posted

I've actually managed to do this, but i guess i'llchange it to check the corners

boolean flag = true;
			HashMap<BlockPos, Integer> nograss = new HashMap<BlockPos, Integer>();

			for (int i = 0; i < template.getSize().getX(); i++) {
				for (int j = 0; j < template.getSize().getZ(); j++) {
					BlockPos down = pos.add(i, -1, j);
					Block b = world.getBlockState(down).getBlock();
					if (!b.equals(Blocks.GRASS)) {
						nograss.put(down, 0);
					}
				}
			}

			if (!nograss.isEmpty()) {
				for(Entry<BlockPos, Integer> entry : nograss.entrySet()) {
					BlockPos top = world.getTopSolidOrLiquidBlock(entry.getKey());
					if(Math.abs(top.getY() - entry.getKey().getY()) > 3) {
						flag = false;
						break;
					}
					else
						entry.setValue(Math.abs(top.getY() - entry.getKey().getY()));
				}
				if(flag) {
					for(Entry<BlockPos, Integer> entry : nograss.entrySet()) {
							for(int i = 0; i < entry.getValue()+1; i++) {
								world.setBlockState(entry.getKey().down(i), Blocks.COBBLESTONE.getDefaultState());
						}
					}

				}
			}

			if (flag) { //do stuff
}

 

So what i do is: check all the blocks, if there are some blocks that don't have grass under them then add it's position to an HashMap. Then, if this HashMap is not empty check if the location of the structure (the blocks that made the base and are in the HashMap) are at most 3 blocks up from the ground. If there is at least one that is up more than 3 blocks then the structure will not generate. Else, every block that has not grass underneath is at most 3 blocks up from the ground, so place 3 blocks of cobblestone down to the ground, so it will looks like the structure has some layers of cobblestone and then the structure itself (mostly like villages sometimes generates)

Don't blame me if i always ask for your help. I just want to learn to be better :)

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.