Posted July 27, 201510 yr 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); } } } }
July 27, 201510 yr 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.
July 27, 201510 yr 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!
July 28, 201510 yr 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/
July 28, 201510 yr 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.