Jump to content

[1.8] Checking for blocks (noob question :/ really sorry) [[Solved]]


Recommended Posts

Posted

Well, I'm a noob because I can't work this out. But I want to check a block under the point which I'm going to spawn a tree - I only want it to spawn on grass. But it currently spawns everywhere. So my noob request is how can I check if there is grass under the block I'm going to spawn a tree above.

 

Well, if we don't ask we can't learn!

 

(I understand if ya reply with hate v-v)

 

private void GeneratorOverworld(World world, int i, int j, Random rand) {

addOre(AlkiaBlocks.sodalite_ore, net.minecraft.init.Blocks.stone, rand, world, i, j, 10, 45, 4, 10, 20);

 

ChunkGenRand = new Random();

//bracket number div by 100 = spawn chance (testing will be 1)

ChunkGenRandNum = ChunkGenRand.nextInt(1)+1;

 

if(ChunkGenRandNum == 1){

 

for(int k = 0; k<16; k++)

{

int RandPosX = i + rand.nextInt(16);

int RandPosZ = j + rand.nextInt(16);

int j1 = getHeightValue(world, RandPosX, RandPosZ);

BlockPos blockPos1 = new BlockPos(RandPosX, j1, RandPosZ);

//example

if(block == Blocks.grass){

(new WorldGenTree()).generate(world, rand, blockPos1);

}

 

}

}

}

 

Posted

Use World#getBlockState to get the IBlockState at a BlockPos and IBlockState#getBlock to get the Block from an IBlockState.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

Use something along the lines of

 

if (world.getBlockState(POSITION) == Blocks.grass.getDefaultState()){

 

 

DO STUFF

 

}

 

Where POSITION is the block under your tree.

If I helped, leave a thank you!

Posted

Use something along the lines of

 

if (world.getBlockState(POSITION) == Blocks.grass.getDefaultState()){

 

 

DO STUFF

 

}

 

Where POSITION is the block under your tree.

No, use
world.getBlockState(BlockPos).getBlock() == Blocks.grass

to check the block type.

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/

Posted

Perhaps it doesn't matter here, but I thought it was better to use .equals() for those comparisons instead of ==.

 

In this case given its a static final Item so it probably doesn't matter... 

Long time Bukkit & Forge Programmer

Happy to try and help

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.