Rework rubber tree generation
This commit is contained in:
parent
862db8a4ab
commit
f5d8cd2f53
4 changed files with 84 additions and 37 deletions
|
@ -731,15 +731,12 @@ public class TechRebornConfig {
|
|||
@Config(config = "world", category = "ore", key = "tungstenVeinSize", comment = "Amount of Tungsten Ores per vein.")
|
||||
public static int tungstenVeinSize = 6;
|
||||
|
||||
@Config(config = "world", category = "rubber_tree", key = "RubberTreeChance", comment = "Chance to spawn rubber tree")
|
||||
public static float RubberTreeChance = 0.1F;
|
||||
@Config(config = "world", category = "rubber_tree", key = "rubberTreeChance", comment = "Chance to spawn rubber tree")
|
||||
public static int rubberTreeChance = 50;
|
||||
|
||||
@Config(config = "world", category = "rubber_tree", key = "RubberTreeCount", comment = "Amount of trees to spawn in successful case")
|
||||
public static int RubberTreeCount = 1;
|
||||
@Config(config = "world", category = "rubber_tree", key = "rubberTreeBaseHeight", comment = "Basic height for not-spire part of rubber tree")
|
||||
public static int rubberTreeBaseHeight = 6;
|
||||
|
||||
@Config(config = "world", category = "rubber_tree", key = "RubberTreeBaseHeight", comment = "Basic height for not-spire part of rubber tree")
|
||||
public static int RubberTreeBaseHeight = 6;
|
||||
|
||||
@Config(config = "world", category = "rubber_tree", key = "RubberTreeSpireHeight", comment = "Height of spire of rubber tree")
|
||||
public static int RubberTreeSpireHeight = 3;
|
||||
@Config(config = "world", category = "rubber_tree", key = "rubberTreeSpireHeight", comment = "Height of spire of rubber tree")
|
||||
public static int rubberTreeSpireHeight = 3;
|
||||
}
|
||||
|
|
38
src/main/java/techreborn/world/RubberTreeDecorator.java
Normal file
38
src/main/java/techreborn/world/RubberTreeDecorator.java
Normal file
|
@ -0,0 +1,38 @@
|
|||
package techreborn.world;
|
||||
|
||||
import com.mojang.datafixers.Dynamic;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.gen.chunk.ChunkGeneratorConfig;
|
||||
import net.minecraft.world.gen.decorator.ChanceDecoratorConfig;
|
||||
import net.minecraft.world.gen.decorator.Decorator;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
// Big thanks to SuperCoder7979 for this
|
||||
public class RubberTreeDecorator extends Decorator<ChanceDecoratorConfig> {
|
||||
public RubberTreeDecorator(Function<Dynamic<?>, ? extends ChanceDecoratorConfig> configDeserializer) {
|
||||
super(configDeserializer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<BlockPos> getPositions(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> generator, Random random, ChanceDecoratorConfig config, BlockPos pos) {
|
||||
// Generate tree clusters randomly
|
||||
if (random.nextInt(config.chance) == 0) {
|
||||
// Generate 4 - 8 trees
|
||||
int treeCount = 4 + random.nextInt(5);
|
||||
return IntStream.range(0, treeCount).mapToObj((i) -> {
|
||||
int x = random.nextInt(16) + pos.getX();
|
||||
int z = random.nextInt(16) + pos.getZ();
|
||||
int y = world.getTopY(Heightmap.Type.MOTION_BLOCKING, x, z);
|
||||
return new BlockPos(x, y, z);
|
||||
});
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
}
|
|
@ -26,12 +26,13 @@ package techreborn.world;
|
|||
|
||||
import com.mojang.datafixers.Dynamic;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.util.math.BlockBox;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.ModifiableTestableWorld;
|
||||
import net.minecraft.world.gen.feature.AbstractTreeFeature;
|
||||
|
||||
import net.minecraft.world.gen.feature.TreeFeatureConfig;
|
||||
import net.minecraft.world.gen.foliage.BlobFoliagePlacer;
|
||||
import net.minecraft.world.gen.foliage.FoliagePlacerType;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
import techreborn.init.TRContent;
|
||||
|
||||
|
@ -49,32 +50,41 @@ public class RubberTreeFeature extends AbstractTreeFeature {
|
|||
super(configFactory);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public boolean generate(ModifiableTestableWorld world, Random random, BlockPos blockPos, Set<BlockPos> set, Set<BlockPos> set2, BlockBox blockBox, TreeFeatureConfig branchedTreeFeatureConfig) {
|
||||
// if(super.generate(world, random, blockPos, set, set2, blockBox, branchedTreeFeatureConfig)) {
|
||||
// spawnSpike(world, blockPos);
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
|
||||
|
||||
private void spawnSpike(ModifiableTestableWorld world, BlockPos pos) {
|
||||
final int startScan = pos.getY();
|
||||
BlockPos topPos = null;
|
||||
public static class FoliagePlacer extends BlobFoliagePlacer {
|
||||
|
||||
//Limit the scan to 15 blocks
|
||||
while(topPos == null && pos.getY() - startScan < 15) {
|
||||
pos = pos.up();
|
||||
if(world.testBlockState(pos, BlockState::isAir)) {
|
||||
topPos = pos;
|
||||
public FoliagePlacer(int radius, int randomRadius, int offset, int randomOffset, int height) {
|
||||
super(radius, randomRadius, offset, randomOffset, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generate(ModifiableTestableWorld world, Random random, TreeFeatureConfig config, int trunkHeight, TreeNode treeNode, int foliageHeight, int radius, Set<BlockPos> leaves, int i) {
|
||||
super.generate(world, random, config, trunkHeight, treeNode, foliageHeight, radius, leaves, i);
|
||||
|
||||
spawnSpike(world, treeNode.getCenter());
|
||||
}
|
||||
|
||||
private void spawnSpike(ModifiableTestableWorld world, BlockPos pos) {
|
||||
final int startScan = pos.getY();
|
||||
BlockPos topPos = null;
|
||||
|
||||
//Limit the scan to 15 blocks
|
||||
while(topPos == null && pos.getY() - startScan < 15) {
|
||||
pos = pos.up();
|
||||
if(world.testBlockState(pos, BlockState::isAir)) {
|
||||
topPos = pos;
|
||||
}
|
||||
}
|
||||
|
||||
if(topPos == null) return;
|
||||
|
||||
for (int i = 0; i < TechRebornConfig.rubberTreeSpireHeight; i++) {
|
||||
world.setBlockState(pos.up(i), TRContent.RUBBER_LEAVES.getDefaultState(), 19);
|
||||
}
|
||||
}
|
||||
|
||||
if(topPos == null) return;
|
||||
|
||||
for (int i = 0; i < TechRebornConfig.RubberTreeSpireHeight; i++) {
|
||||
setBlockState(world, pos.up(i), TRContent.RUBBER_LEAVES.getDefaultState());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ import net.minecraft.util.registry.Registry;
|
|||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.Biome.Category;
|
||||
import net.minecraft.world.gen.GenerationStep;
|
||||
import net.minecraft.world.gen.decorator.CountExtraChanceDecoratorConfig;
|
||||
import net.minecraft.world.gen.decorator.ChanceDecoratorConfig;
|
||||
import net.minecraft.world.gen.decorator.Decorator;
|
||||
import net.minecraft.world.gen.decorator.RangeDecoratorConfig;
|
||||
import net.minecraft.world.gen.feature.Feature;
|
||||
|
@ -61,6 +61,7 @@ import java.util.List;
|
|||
public class WorldGenerator {
|
||||
|
||||
public static Feature<TreeFeatureConfig> RUBBER_TREE_FEATURE;
|
||||
public static RubberTreeDecorator RUBBER_TREE_DECORATOR;
|
||||
|
||||
public static TreeFeatureConfig RUBBER_TREE_CONFIG;
|
||||
|
||||
|
@ -79,6 +80,7 @@ public class WorldGenerator {
|
|||
|
||||
private static void setupTrees() {
|
||||
RUBBER_TREE_FEATURE = Registry.register(Registry.FEATURE, new Identifier("techreborn:rubber_tree"), new RubberTreeFeature(TreeFeatureConfig::deserialize));
|
||||
RUBBER_TREE_DECORATOR = Registry.register(Registry.DECORATOR, new Identifier("techreborn:rubber_tree"), new RubberTreeDecorator(ChanceDecoratorConfig::deserialize));
|
||||
|
||||
WeightedBlockStateProvider logProvider = new WeightedBlockStateProvider();
|
||||
logProvider.addState(TRContent.RUBBER_LOG.getDefaultState(), 10);
|
||||
|
@ -94,8 +96,8 @@ public class WorldGenerator {
|
|||
RUBBER_TREE_CONFIG = new TreeFeatureConfig.Builder(
|
||||
logProvider,
|
||||
new SimpleBlockStateProvider(TRContent.RUBBER_LEAVES.getDefaultState()),
|
||||
new BlobFoliagePlacer(2, 0, 0, 0, 3),
|
||||
new StraightTrunkPlacer(TechRebornConfig.RubberTreeBaseHeight, 3, 0),
|
||||
new RubberTreeFeature.FoliagePlacer(2, 0, 0, 0, 3),
|
||||
new StraightTrunkPlacer(TechRebornConfig.rubberTreeBaseHeight, 3, 0),
|
||||
new TwoLayersFeatureSize(1, 0, 1)
|
||||
).build();
|
||||
}
|
||||
|
@ -162,8 +164,8 @@ public class WorldGenerator {
|
|||
if (biome.getCategory() == Category.FOREST || biome.getCategory() == Category.TAIGA || biome.getCategory() == Category.SWAMP) {
|
||||
biome.addFeature(GenerationStep.Feature.VEGETAL_DECORATION,
|
||||
RUBBER_TREE_FEATURE.configure(RUBBER_TREE_CONFIG)
|
||||
.createDecoratedFeature(Decorator.COUNT_EXTRA_HEIGHTMAP
|
||||
.configure(new CountExtraChanceDecoratorConfig(biome.getCategory() == Category.SWAMP ? 1 : 0, TechRebornConfig.RubberTreeChance, TechRebornConfig.RubberTreeCount))
|
||||
.createDecoratedFeature(RUBBER_TREE_DECORATOR
|
||||
.configure(new ChanceDecoratorConfig(biome.getCategory() == Category.SWAMP ? TechRebornConfig.rubberTreeChance / 3 : TechRebornConfig.rubberTreeChance))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue