Jump to content

[1.7.2][UNSOLVED] WorldGen


proalt

Recommended Posts

Hello i need help with world gen, i want my scructure to spawn on surface.

 

This is my current code and structure that i have spawning inside stone, i want to have my structure on surface ( grass ).

 

EDIT: FULL CODE

N/A

import static net.minecraftforge.common.ChestGenHooks.DUNGEON_CHEST;
import java.util.Random;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.WeightedRandomChestContent;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.common.ChestGenHooks;

public class WorldGenNA extends WorldGenerator
{

public boolean generate(World world, Random rand, int x, int y, int z)
{
if(world.getBlock(x, y, z) != Blocks.grass || world.getBlock(x + 5, y + 5, z + 5) != Blocks.grass || world.getBlock(x, y + 5, z + 5) != Blocks.grass|| world.getBlock(x + 5, y, z) != Blocks.grass)
{
return false;
}
world.setBlock(x + 0, y + 0, z + 0, Blocks.bedrock);
world.setBlock(x + 0, y + 0, z + 1, Blocks.bedrock);
world.setBlock(x + 0, y + 0, z + 2, Blocks.bedrock);
world.setBlock(x + 0, y + 0, z + 3, Blocks.bedrock);
world.setBlock(x + 0, y + 0, z + 4, Blocks.bedrock);
world.setBlock(x + 0, y + 1, z + 0, Blocks.bedrock);
world.setBlock(x + 0, y + 1, z + 1, Blocks.bedrock);
world.setBlock(x + 0, y + 1, z + 2, Blocks.bedrock);
world.setBlock(x + 0, y + 1, z + 3, Blocks.bedrock);
world.setBlock(x + 0, y + 1, z + 4, Blocks.bedrock);
world.setBlock(x + 0, y + 2, z + 0, Blocks.bedrock);
world.setBlock(x + 0, y + 2, z + 1, Blocks.bedrock);
world.setBlock(x + 0, y + 2, z + 2, Blocks.bedrock);
world.setBlock(x + 0, y + 2, z + 3, Blocks.bedrock);
world.setBlock(x + 0, y + 2, z + 4, Blocks.bedrock);
world.setBlock(x + 0, y + 3, z + 0, Blocks.bedrock);
world.setBlock(x + 0, y + 3, z + 1, Blocks.bedrock);
world.setBlock(x + 0, y + 3, z + 2, Blocks.bedrock);
world.setBlock(x + 0, y + 3, z + 3, Blocks.bedrock);
world.setBlock(x + 0, y + 3, z + 4, Blocks.bedrock);
world.setBlock(x + 1, y + 0, z + 0, Blocks.bedrock);
world.setBlock(x + 1, y + 0, z + 1, Blocks.bedrock);
world.setBlock(x + 1, y + 0, z + 2, Blocks.bedrock);
world.setBlock(x + 1, y + 0, z + 3, Blocks.bedrock);
world.setBlock(x + 1, y + 0, z + 4, Blocks.bedrock);
world.setBlock(x + 1, y + 1, z + 0, Blocks.bedrock);
world.setBlock(x + 1, y + 1, z + 4, Blocks.bedrock);
world.setBlock(x + 1, y + 2, z + 0, Blocks.bedrock);
world.setBlock(x + 1, y + 2, z + 4, Blocks.bedrock);
world.setBlock(x + 1, y + 3, z + 0, Blocks.bedrock);
world.setBlock(x + 1, y + 3, z + 1, Blocks.bedrock);
world.setBlock(x + 1, y + 3, z + 2, Blocks.bedrock);
world.setBlock(x + 1, y + 3, z + 3, Blocks.bedrock);
world.setBlock(x + 1, y + 3, z + 4, Blocks.bedrock);
world.setBlock(x + 2, y + 0, z + 0, Blocks.bedrock);
world.setBlock(x + 2, y + 0, z + 1, Blocks.bedrock);
world.setBlock(x + 2, y + 0, z + 2, Blocks.bedrock);
world.setBlock(x + 2, y + 0, z + 3, Blocks.bedrock);
world.setBlock(x + 2, y + 0, z + 4, Blocks.bedrock);
world.setBlock(x + 2, y + 1, z + 0, Blocks.bedrock);
world.setBlock(x + 2, y + 1, z + 4, Blocks.bedrock);
world.setBlock(x + 2, y + 2, z + 0, Blocks.bedrock);
world.setBlock(x + 2, y + 2, z + 4, Blocks.bedrock);
world.setBlock(x + 2, y + 3, z + 0, Blocks.bedrock);
world.setBlock(x + 2, y + 3, z + 1, Blocks.bedrock);
world.setBlock(x + 2, y + 3, z + 2, Blocks.bedrock);
world.setBlock(x + 2, y + 3, z + 3, Blocks.bedrock);
world.setBlock(x + 2, y + 3, z + 4, Blocks.bedrock);
return true;
}

 

 

EDIT:

This on top or if anyone knows if i can just make chests spawn around the world with custom items inside.

Or any other blocks to spawn around the world like trees.

Link to comment
Share on other sites

More code please?

 

added full code of the file.

 

Here is a ChunkProvider:

 

// NA
	if(rand.nextInt(15) == 0)
	{
	for(k1 = 0; k1 < 8; ++k1)
	{
	l1 = k + this.rand.nextInt(16) + 8;
	i2 = this.rand.nextInt(256);
	int j2 = l + this.rand.nextInt(16) + 8;
	(new WorldGenNA()).generate(this.worldObj, this.rand, l1, i2, j2);
	}
	}
	//

Link to comment
Share on other sites

You are checking 5 blocks up and 5 blocks down. Imagine that... no minecraft world has grass at those positions. Grass is just the top layer.

 

So how would then that go, X Y Z. isnt "Z" for UP and DOWN ?! da hell, was i looking at google pictures.

 

if(world.getBlock(x, y, z) != Blocks.dirt || world.getBlock(x + 0, y + 0, z + 1) != Blocks.dirt || world.getBlock(x, y + 0, z + 1) != Blocks.dirt|| world.getBlock(x + 0, y, z) != Blocks.dirt)

Like this then ?!

Link to comment
Share on other sites

You are checking 5 blocks up and 5 blocks down. Imagine that... no minecraft world has grass at those positions. Grass is just the top layer.

 

So how would then that go, X Y Z. isnt "Z" for UP and DOWN ?! da hell, was i looking at google pictures.

 

if(world.getBlock(x, y, z) != Blocks.dirt || world.getBlock(x + 0, y + 0, z + 1) != Blocks.dirt || world.getBlock(x, y + 0, z + 1) != Blocks.dirt|| world.getBlock(x + 0, y, z) != Blocks.dirt)

Like this then ?!

In Minecraft, the coordinate system is weird. X is for east/west, Y is for up/down and Z is for north/south.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

You are checking 5 blocks up and 5 blocks down. Imagine that... no minecraft world has grass at those positions. Grass is just the top layer.

 

So how would then that go, X Y Z. isnt "Z" for UP and DOWN ?! da hell, was i looking at google pictures.

 

if(world.getBlock(x, y, z) != Blocks.dirt || world.getBlock(x + 0, y + 0, z + 1) != Blocks.dirt || world.getBlock(x, y + 0, z + 1) != Blocks.dirt|| world.getBlock(x + 0, y, z) != Blocks.dirt)

Like this then ?!

In Minecraft, the coordinate system is weird. X is for east/west, Y is for up/down and Z is for north/south.

 

So if i am not wrong then my code should be like this

5 block left 5 block right + 1 block high

Z - 5, X -5, Y -1

Link to comment
Share on other sites

if(world.getBlock(x, y, z) != Blocks.grass || world.getBlock(x + 1, y + 1, z + 1) != Blocks.grass)

 

This is my code, and it spawns sometimes buts its odd. Is there any other code that checks if there is grass even if its one block and then it spawns building ?!

Link to comment
Share on other sites

1. To get the topmost block during generation, use

world.getTopSolidOrLiquidBlock(x, z)

2. Please use descriptive names for your variables. Stuff like i2 or j1 is just confusing.

3. Ever considered using

for

loops instead of this chunk of repeating setBlock calls you have?

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

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.