From bf5424becc9abd621d15d9b408bc26b308cf0b32 Mon Sep 17 00:00:00 2001 From: Adubbz Date: Fri, 21 Apr 2017 18:39:02 +1000 Subject: [PATCH] Vines now generate correctly in the Undergarden --- .../common/biome/nether/BiomeUndergarden.java | 4 +- .../world/generator/GeneratorVines.java | 72 ++++++++++++------- 2 files changed, 49 insertions(+), 27 deletions(-) diff --git a/src/main/java/biomesoplenty/common/biome/nether/BiomeUndergarden.java b/src/main/java/biomesoplenty/common/biome/nether/BiomeUndergarden.java index f96f62624..73c2d12ed 100644 --- a/src/main/java/biomesoplenty/common/biome/nether/BiomeUndergarden.java +++ b/src/main/java/biomesoplenty/common/biome/nether/BiomeUndergarden.java @@ -44,8 +44,8 @@ public class BiomeUndergarden extends BOPHellBiome 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()); - IBlockPosQuery suitableNetherrackPosition = BlockQuery.buildAnd().withAltitudeBetween(80, 130).blocks(Blocks.NETHERRACK).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()); + 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()).minHeight(8).maxHeight(20).create()); // flowers GeneratorWeighted flowerGenerator = new GeneratorWeighted(1.0F); diff --git a/src/main/java/biomesoplenty/common/world/generator/GeneratorVines.java b/src/main/java/biomesoplenty/common/world/generator/GeneratorVines.java index 51146f351..59fd8f4f1 100644 --- a/src/main/java/biomesoplenty/common/world/generator/GeneratorVines.java +++ b/src/main/java/biomesoplenty/common/world/generator/GeneratorVines.java @@ -8,23 +8,29 @@ package biomesoplenty.common.world.generator; +import java.util.List; import java.util.Random; +import java.util.Set; import biomesoplenty.api.block.BlockQueries; import biomesoplenty.api.block.IBlockPosQuery; import biomesoplenty.api.config.IConfigObj; import biomesoplenty.common.util.biome.GeneratorUtils; import biomesoplenty.common.util.biome.GeneratorUtils.ScatterYMethod; +import biomesoplenty.common.util.block.BlockQuery; 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.state.IBlockState; import net.minecraft.init.Blocks; +import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class GeneratorVines extends GeneratorReplacing { - public static class Builder extends GeneratorReplacing.InnerBuilder implements IGeneratorBuilder { protected int minHeight; @@ -40,9 +46,9 @@ public class GeneratorVines extends GeneratorReplacing // defaults this.amountPerChunk = 1.0F; this.placeOn = new BlockQueryMaterial(Material.GROUND, Material.GRASS); - this.replace = BlockQueries.airOrLeaves; - this.with = Blocks.COBBLESTONE.getDefaultState(); - this.scatterYMethod = ScatterYMethod.AT_SURFACE; + this.replace = BlockQueries.air; + this.with = Blocks.VINE.getDefaultState(); + this.scatterYMethod = ScatterYMethod.NETHER_ROOF; this.minHeight = 2; this.maxHeight = 4; this.generationAttempts = 12; @@ -58,7 +64,6 @@ public class GeneratorVines extends GeneratorReplacing protected int minHeight; protected int maxHeight; protected int generationAttempts; - protected boolean randomDirection; 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 public boolean generate(World world, Random rand, BlockPos pos) { + boolean ret = true; + 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)); - - // see if we can place the column - if (this.placeOn.matches(world, genPos.up()) && this.replace.matches(world, genPos)) + if (!this.replace.matches(world, genPos) || !this.placeOn.matches(world, genPos.up())) continue; + + IBlockState vineState = this.with; + + // make sure there is an adjacent block for the vine to attach to + List 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 - int targetHeight = GeneratorUtils.nextIntBetween(rand, this.minHeight, this.maxHeight); - - // keep placing blocks upwards (if there's room) - for (int height = 0; height <= targetHeight && replace.matches(world, genPos); height++) + EnumFacing direction = validDirections.get(rand.nextInt(validDirections.size())); + vineState = this.with.withProperty(BlockVine.getPropertyFor(direction), Boolean.valueOf(true)); + } + + // 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(genPos, this.with); - genPos = genPos.down(); - } - else - { - return false; - } + world.setBlockState(offsetPos, vineState); + } + else + { + ret = false; + break; } } } - return true; + return ret; } @Override @@ -110,6 +134,4 @@ public class GeneratorVines extends GeneratorReplacing this.generationAttempts = conf.getInt("generationAttempts", this.generationAttempts); this.placeOn = conf.getBlockPosQuery("placeOn", this.placeOn); } - - } \ No newline at end of file