Added a generator for grass
This commit is contained in:
parent
0020ea25f3
commit
b617d62ca4
3 changed files with 72 additions and 4 deletions
|
@ -14,6 +14,7 @@ import biomesoplenty.common.world.feature.GeneratorOreSingle;
|
||||||
import biomesoplenty.common.world.feature.GeneratorWeighted;
|
import biomesoplenty.common.world.feature.GeneratorWeighted;
|
||||||
import biomesoplenty.common.world.feature.tree.GeneratorBasicTree;
|
import biomesoplenty.common.world.feature.tree.GeneratorBasicTree;
|
||||||
import biomesoplenty.common.world.feature.weighted.GeneratorFlora;
|
import biomesoplenty.common.world.feature.weighted.GeneratorFlora;
|
||||||
|
import biomesoplenty.common.world.feature.weighted.GeneratorGrass;
|
||||||
|
|
||||||
public class ModGenerators
|
public class ModGenerators
|
||||||
{
|
{
|
||||||
|
@ -24,5 +25,6 @@ public class ModGenerators
|
||||||
registerGenerator("weighted", GeneratorWeighted.class);
|
registerGenerator("weighted", GeneratorWeighted.class);
|
||||||
registerGenerator("basic_tree", GeneratorBasicTree.class);
|
registerGenerator("basic_tree", GeneratorBasicTree.class);
|
||||||
registerGenerator("flora", GeneratorFlora.class);
|
registerGenerator("flora", GeneratorFlora.class);
|
||||||
|
registerGenerator("grass", GeneratorGrass.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import com.google.gson.JsonDeserializationContext;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonSerializationContext;
|
import com.google.gson.JsonSerializationContext;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.util.BlockPos;
|
import net.minecraft.util.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
@ -53,14 +54,17 @@ public class GeneratorFlora extends CustomizableWeightedGenerator
|
||||||
@Override
|
@Override
|
||||||
public boolean generate(World world, Random random, BlockPos pos, int amountPerChunk)
|
public boolean generate(World world, Random random, BlockPos pos, int amountPerChunk)
|
||||||
{
|
{
|
||||||
|
Block block = this.state.getBlock();
|
||||||
|
|
||||||
for (int i = 0; i < 64; ++i)
|
for (int i = 0; i < 64; ++i)
|
||||||
{
|
{
|
||||||
BlockPos blockpos1 = pos.add(random.nextInt(8) - random.nextInt(8), random.nextInt(4) - random.nextInt(4), random.nextInt(8) - random.nextInt(8));
|
BlockPos genPos = pos.add(random.nextInt(8) - random.nextInt(8), random.nextInt(4) - random.nextInt(4), random.nextInt(8) - random.nextInt(8));
|
||||||
|
|
||||||
if (world.isAirBlock(blockpos1) && (!world.provider.getHasNoSky() || blockpos1.getY() < 255) &&
|
boolean canStay = block instanceof BlockDecoration ? ((BlockDecoration)block).canBlockStay(world, genPos, this.state) : block.canPlaceBlockAt(world, genPos);
|
||||||
(this.state.getBlock() instanceof BlockDecoration ? ((BlockDecoration)this.state.getBlock()).canBlockStay(world, blockpos1, this.state) : this.state.getBlock().canPlaceBlockAt(world, blockpos1)))
|
|
||||||
|
if (world.isAirBlock(genPos) && (!world.provider.getHasNoSky() || genPos.getY() < 255) && canStay)
|
||||||
{
|
{
|
||||||
world.setBlockState(blockpos1, this.state, 2);
|
world.setBlockState(genPos, this.state, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright 2015, the Biomes O' Plenty Team
|
||||||
|
*
|
||||||
|
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
|
||||||
|
*
|
||||||
|
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
package biomesoplenty.common.world.feature.weighted;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.util.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import biomesoplenty.common.block.BlockDecoration;
|
||||||
|
import biomesoplenty.common.util.biome.GeneratorUtils;
|
||||||
|
|
||||||
|
public class GeneratorGrass extends GeneratorFlora
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void scatter(World world, Random random, BlockPos pos, int amountPerChunk)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < amountPerChunk; i++)
|
||||||
|
{
|
||||||
|
int x = random.nextInt(16) + 8;
|
||||||
|
int z = random.nextInt(16) + 8;
|
||||||
|
BlockPos genPos = pos.add(x, 0, z);
|
||||||
|
int y = GeneratorUtils.safeNextInt(random, world.getHeight(genPos).getY() * 2);
|
||||||
|
genPos = genPos.add(0, y, 0);
|
||||||
|
|
||||||
|
generate(world, random, genPos, amountPerChunk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean generate(World world, Random random, BlockPos pos, int amountPerChunk)
|
||||||
|
{
|
||||||
|
Block block;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
block = world.getBlockState(pos).getBlock();
|
||||||
|
if (!block.isAir(world, pos) && !block.isLeaves(world, pos)) break;
|
||||||
|
pos = pos.down();
|
||||||
|
}
|
||||||
|
while (pos.getY() > 0);
|
||||||
|
|
||||||
|
for (int i = 0; i < 128; i++)
|
||||||
|
{
|
||||||
|
BlockPos genPos = pos.add(random.nextInt(8) - random.nextInt(8), random.nextInt(4) - random.nextInt(4), random.nextInt(8) - random.nextInt(8));
|
||||||
|
boolean canStay = block instanceof BlockDecoration ? ((BlockDecoration)block).canBlockStay(world, genPos, this.state) : block.canPlaceBlockAt(world, genPos);
|
||||||
|
|
||||||
|
if (world.isAirBlock(genPos) && canStay)
|
||||||
|
{
|
||||||
|
world.setBlockState(genPos, this.state, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue