Vines now generate correctly in the Undergarden

This commit is contained in:
Adubbz 2017-04-21 18:39:02 +10:00
parent a71c5ec545
commit bf5424becc
2 changed files with 49 additions and 27 deletions

View File

@ -44,8 +44,8 @@ public class BiomeUndergarden extends BOPHellBiome
IBlockState overgrownNetherrack = BOPBlocks.grass.getDefaultState().withProperty(BlockBOPGrass.VARIANT, BlockBOPGrass.BOPGrassType.OVERGROWN_NETHERRACK); IBlockState overgrownNetherrack = BOPBlocks.grass.getDefaultState().withProperty(BlockBOPGrass.VARIANT, BlockBOPGrass.BOPGrassType.OVERGROWN_NETHERRACK);
this.addGenerator("overgrown_netherrack_splatter", GeneratorStage.SAND, (new GeneratorSplatter.Builder()).amountPerChunk(20.0F).generationAttempts(128).scatterYMethod(ScatterYMethod.NETHER_SURFACE).replace(emptyNetherrack).with(overgrownNetherrack).create()); this.addGenerator("overgrown_netherrack_splatter", GeneratorStage.SAND, (new GeneratorSplatter.Builder()).amountPerChunk(20.0F).generationAttempts(128).scatterYMethod(ScatterYMethod.NETHER_SURFACE).replace(emptyNetherrack).with(overgrownNetherrack).create());
IBlockPosQuery suitableNetherrackPosition = BlockQuery.buildAnd().withAltitudeBetween(80, 130).blocks(Blocks.NETHERRACK).create(); IBlockPosQuery suitableNetherrackPosition = BlockQuery.buildAnd().withAltitudeBetween(80, 130).states(Blocks.NETHERRACK.getDefaultState()).create();
this.addGenerator("ivy", GeneratorStage.FLOWERS,(new GeneratorVines.Builder()).amountPerChunk(30.0F).generationAttempts(128).placeOn(suitableNetherrackPosition).with(BOPBlocks.ivy.getDefaultState().withProperty(BlockBOPVine.UP, Boolean.valueOf(true)).withProperty(BlockBOPVine.EAST, Boolean.valueOf(true)).withProperty(BlockBOPVine.WEST, Boolean.valueOf(true)).withProperty(BlockBOPVine.SOUTH, Boolean.valueOf(true)).withProperty(BlockBOPVine.NORTH, Boolean.valueOf(true))).minHeight(8).maxHeight(20).create()); this.addGenerator("ivy", GeneratorStage.FLOWERS,(new GeneratorVines.Builder()).amountPerChunk(30.0F).generationAttempts(128).placeOn(suitableNetherrackPosition).with(BOPBlocks.ivy.getDefaultState()).minHeight(8).maxHeight(20).create());
// flowers // flowers
GeneratorWeighted flowerGenerator = new GeneratorWeighted(1.0F); GeneratorWeighted flowerGenerator = new GeneratorWeighted(1.0F);

View File

@ -8,23 +8,29 @@
package biomesoplenty.common.world.generator; package biomesoplenty.common.world.generator;
import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.Set;
import biomesoplenty.api.block.BlockQueries; import biomesoplenty.api.block.BlockQueries;
import biomesoplenty.api.block.IBlockPosQuery; import biomesoplenty.api.block.IBlockPosQuery;
import biomesoplenty.api.config.IConfigObj; import biomesoplenty.api.config.IConfigObj;
import biomesoplenty.common.util.biome.GeneratorUtils; import biomesoplenty.common.util.biome.GeneratorUtils;
import biomesoplenty.common.util.biome.GeneratorUtils.ScatterYMethod; import biomesoplenty.common.util.biome.GeneratorUtils.ScatterYMethod;
import biomesoplenty.common.util.block.BlockQuery;
import biomesoplenty.common.util.block.BlockQuery.BlockQueryMaterial; import biomesoplenty.common.util.block.BlockQuery.BlockQueryMaterial;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import net.minecraft.block.BlockVine;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
public class GeneratorVines extends GeneratorReplacing public class GeneratorVines extends GeneratorReplacing
{ {
public static class Builder extends GeneratorReplacing.InnerBuilder<Builder, GeneratorVines> implements IGeneratorBuilder<GeneratorVines> public static class Builder extends GeneratorReplacing.InnerBuilder<Builder, GeneratorVines> implements IGeneratorBuilder<GeneratorVines>
{ {
protected int minHeight; protected int minHeight;
@ -40,9 +46,9 @@ public class GeneratorVines extends GeneratorReplacing
// defaults // defaults
this.amountPerChunk = 1.0F; this.amountPerChunk = 1.0F;
this.placeOn = new BlockQueryMaterial(Material.GROUND, Material.GRASS); this.placeOn = new BlockQueryMaterial(Material.GROUND, Material.GRASS);
this.replace = BlockQueries.airOrLeaves; this.replace = BlockQueries.air;
this.with = Blocks.COBBLESTONE.getDefaultState(); this.with = Blocks.VINE.getDefaultState();
this.scatterYMethod = ScatterYMethod.AT_SURFACE; this.scatterYMethod = ScatterYMethod.NETHER_ROOF;
this.minHeight = 2; this.minHeight = 2;
this.maxHeight = 4; this.maxHeight = 4;
this.generationAttempts = 12; this.generationAttempts = 12;
@ -58,7 +64,6 @@ public class GeneratorVines extends GeneratorReplacing
protected int minHeight; protected int minHeight;
protected int maxHeight; protected int maxHeight;
protected int generationAttempts; protected int generationAttempts;
protected boolean randomDirection;
public GeneratorVines(float amountPerChunk, IBlockPosQuery placeOn, IBlockPosQuery replace, IBlockState with, ScatterYMethod scatterYMethod, int minHeight, int maxHeight, int generationAttempts) public GeneratorVines(float amountPerChunk, IBlockPosQuery placeOn, IBlockPosQuery replace, IBlockState with, ScatterYMethod scatterYMethod, int minHeight, int maxHeight, int generationAttempts)
{ {
@ -71,33 +76,52 @@ public class GeneratorVines extends GeneratorReplacing
@Override @Override
public boolean generate(World world, Random rand, BlockPos pos) public boolean generate(World world, Random rand, BlockPos pos)
{ {
boolean ret = true;
for (int i = 0; i < this.generationAttempts; ++i) for (int i = 0; i < this.generationAttempts; ++i)
{ {
BlockPos genPos = pos.add(rand.nextInt(4) - rand.nextInt(4), rand.nextInt(3) - rand.nextInt(3), rand.nextInt(4) - rand.nextInt(4)); BlockPos genPos = pos.add(rand.nextInt(4) - rand.nextInt(4), rand.nextInt(3) - rand.nextInt(3), rand.nextInt(4) - rand.nextInt(4));
// see if we can place the column if (!this.replace.matches(world, genPos) || !this.placeOn.matches(world, genPos.up())) continue;
if (this.placeOn.matches(world, genPos.up()) && this.replace.matches(world, genPos))
IBlockState vineState = this.with;
// make sure there is an adjacent block for the vine to attach to
List<EnumFacing> validDirections = Lists.newArrayList();
for (EnumFacing facing : EnumFacing.values()) {
if (facing == EnumFacing.UP || facing == EnumFacing.DOWN) continue;
if (this.placeOn.matches(world, genPos.offset(facing))) validDirections.add(facing);
}
if (validDirections.isEmpty()) continue;
if (this.with.getBlock() instanceof BlockVine)
{ {
// choose random target height EnumFacing direction = validDirections.get(rand.nextInt(validDirections.size()));
int targetHeight = GeneratorUtils.nextIntBetween(rand, this.minHeight, this.maxHeight); vineState = this.with.withProperty(BlockVine.getPropertyFor(direction), Boolean.valueOf(true));
}
// keep placing blocks upwards (if there's room)
for (int height = 0; height <= targetHeight && replace.matches(world, genPos); height++) // choose random target height
int targetHeight = GeneratorUtils.nextIntBetween(rand, this.minHeight, this.maxHeight);
// keep placing blocks upwards (if there's room)
for (int height = 0; height <= targetHeight; height++)
{
BlockPos offsetPos = genPos.down(height);
if (replace.matches(world, offsetPos) && vineState.getBlock().canPlaceBlockAt(world, offsetPos))
{ {
if (this.with.getBlock().canPlaceBlockAt(world, genPos)) world.setBlockState(offsetPos, vineState);
{ }
world.setBlockState(genPos, this.with); else
genPos = genPos.down(); {
} ret = false;
else break;
{
return false;
}
} }
} }
} }
return true; return ret;
} }
@Override @Override
@ -110,6 +134,4 @@ public class GeneratorVines extends GeneratorReplacing
this.generationAttempts = conf.getInt("generationAttempts", this.generationAttempts); this.generationAttempts = conf.getInt("generationAttempts", this.generationAttempts);
this.placeOn = conf.getBlockPosQuery("placeOn", this.placeOn); this.placeOn = conf.getBlockPosQuery("placeOn", this.placeOn);
} }
} }