From 94c57945561068569c2767508813294a6b5fc849 Mon Sep 17 00:00:00 2001 From: ItsBlackGear Date: Mon, 18 Jul 2022 17:07:45 -0400 Subject: [PATCH] mangrove now generating moss --- .../registry/worldgen/WBWorldGeneration.java | 1 - .../worldgen/features/RootedTreeFeature.java | 52 ++----------------- .../worldgen/placers/MangroveRootPlacer.java | 10 ++-- .../common/worldgen/placers/RootPlacer.java | 6 +-- 4 files changed, 11 insertions(+), 58 deletions(-) diff --git a/common/src/main/java/com/cursedcauldron/wildbackport/common/registry/worldgen/WBWorldGeneration.java b/common/src/main/java/com/cursedcauldron/wildbackport/common/registry/worldgen/WBWorldGeneration.java index f44a52e..e11c58c 100644 --- a/common/src/main/java/com/cursedcauldron/wildbackport/common/registry/worldgen/WBWorldGeneration.java +++ b/common/src/main/java/com/cursedcauldron/wildbackport/common/registry/worldgen/WBWorldGeneration.java @@ -60,7 +60,6 @@ public class WBWorldGeneration { } // Mangrove Swamp - //TODO: fix mangroves not generating moss public static final Holder> MANGROVE = config("mangrove", WBFeatures.TREE.get(), new RootedTreeConfig.Builder( BlockStateProvider.simple(WBBlocks.MANGROVE_LOG.get()), diff --git a/common/src/main/java/com/cursedcauldron/wildbackport/common/worldgen/features/RootedTreeFeature.java b/common/src/main/java/com/cursedcauldron/wildbackport/common/worldgen/features/RootedTreeFeature.java index fa56b5a..fa2503b 100644 --- a/common/src/main/java/com/cursedcauldron/wildbackport/common/worldgen/features/RootedTreeFeature.java +++ b/common/src/main/java/com/cursedcauldron/wildbackport/common/worldgen/features/RootedTreeFeature.java @@ -77,8 +77,8 @@ public class RootedTreeFeature extends Feature { for (int x = -size; x <= size; ++x) { for (int z = -size; z <= size; ++z) { mutable.setWithOffset(pos, x, y, z); - boolean isValid = (TreeFeature.validTreePos(level, pos) || level.isStateAtPosition(pos, state -> state.is(BlockTags.LOGS))) || (config.trunkPlacer instanceof UpwardBranchingTrunk placer && level.isStateAtPosition(pos, state -> state.is(placer.canGrowThrough))); - if (!isValid || !config.ignoreVines && TreeFeatureAccessor.isVine(level, mutable)) return y - 2; + boolean isValid = TreeFeature.validTreePos(level, pos) || level.isStateAtPosition(pos, state -> state.is(BlockTags.LOGS)) || (config.trunkPlacer instanceof UpwardBranchingTrunk trunk && level.isStateAtPosition(pos, state -> state.is(trunk.canGrowThrough))); + if (!isValid || (!config.ignoreVines && TreeFeatureAccessor.isVine(level, mutable))) return y - 2; } } } @@ -87,7 +87,7 @@ public class RootedTreeFeature extends Feature { } @Override - public boolean place(FeaturePlaceContext context) { + public final boolean place(FeaturePlaceContext context) { WorldGenLevel level = context.level(); Random random = context.random(); BlockPos pos = context.origin(); @@ -172,51 +172,5 @@ public class RootedTreeFeature extends Feature { } } return shape; - -// ArrayList> positions = Lists.newArrayList(); -// BitSetDiscreteVoxelShape shape = new BitSetDiscreteVoxelShape(box.getXSpan(), box.getYSpan(), box.getZSpan()); -// -// for (int tries = 0; tries < 6; ++tries) positions.add(Sets.newHashSet()); -// -// BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos(); -// for (BlockPos pos : Lists.newArrayList(decoratorPositions)) if (box.isInside(pos)) shape.fill(pos.getX() - box.minX(), pos.getY() - box.minY(), pos.getZ() - box.minZ()); -// -// for (BlockPos pos : Lists.newArrayList(trunkPositions)) { -// if (box.isInside(pos)) shape.fill(pos.getX() - box.minX(), pos.getY() - box.minY(), pos.getZ() - box.minZ()); -// -// for (Direction direction : Direction.values()) { -// mutable.setWithOffset(pos, direction); -// if (trunkPositions.contains(mutable)) { -// BlockState state = level.getBlockState(mutable); -// if (state.hasProperty(BlockStateProperties.DISTANCE)) { -// positions.get(0).add(mutable.immutable()); -// TreeFeatureAccessor.setBlockKnownShape(level, mutable, state.setValue(BlockStateProperties.DISTANCE, 1)); -// if (box.isInside(mutable)) shape.fill(mutable.getX() - box.minX(), mutable.getY() - box.minY(), mutable.getZ() - box.minZ()); -// } -// } -// } -// } -// -// for (int tries = 1; tries < 6; ++tries) { -// Set trunkPos = positions.get(tries - 1); -// Set foliagePos = positions.get(tries); -// for (BlockPos pos : trunkPos) { -// if (box.isInside(pos)) shape.fill(pos.getX() - box.minX(), pos.getY() - box.minY(), pos.getZ() - box.minZ()); -// -// for (Direction direction : Direction.values()) { -// mutable.setWithOffset(pos, direction); -// if (!trunkPos.contains(mutable) && !foliagePos.contains(mutable)) { -// BlockState state = level.getBlockState(mutable); -// if (state.hasProperty(BlockStateProperties.DISTANCE) && state.getValue(BlockStateProperties.DISTANCE) > tries + 1) { -// BlockState foliage = state.setValue(BlockStateProperties.DISTANCE, tries + 1); -// TreeFeatureAccessor.setBlockKnownShape(level, mutable, foliage); -// if (box.isInside(mutable)) (shape).fill(mutable.getX() - box.minX(), mutable.getY() - box.minY(), mutable.getZ() - box.minZ()); -// foliagePos.add(mutable.immutable()); -// } -// } -// } -// } -// } -// return shape; } } \ No newline at end of file diff --git a/common/src/main/java/com/cursedcauldron/wildbackport/common/worldgen/placers/MangroveRootPlacer.java b/common/src/main/java/com/cursedcauldron/wildbackport/common/worldgen/placers/MangroveRootPlacer.java index 6420101..4f977eb 100644 --- a/common/src/main/java/com/cursedcauldron/wildbackport/common/worldgen/placers/MangroveRootPlacer.java +++ b/common/src/main/java/com/cursedcauldron/wildbackport/common/worldgen/placers/MangroveRootPlacer.java @@ -14,6 +14,7 @@ import net.minecraft.world.level.LevelSimulatedReader; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider; +import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.Random; @@ -34,7 +35,7 @@ public class MangroveRootPlacer extends RootPlacer { @Override public boolean generate(LevelSimulatedReader level, BiConsumer replacer, Random random, BlockPos pos, BlockPos origin, RootedTreeConfig config) { - List positions = Lists.newArrayList(); + ArrayList positions = Lists.newArrayList(); BlockPos.MutableBlockPos mutable = pos.mutable(); while(mutable.getY() < origin.getY()) { @@ -44,10 +45,9 @@ public class MangroveRootPlacer extends RootPlacer { } positions.add(origin.below()); - for(Direction direction : Direction.Plane.HORIZONTAL) { BlockPos position = origin.relative(direction); - List offshootPositions = Lists.newArrayList(); + ArrayList offshootPositions = Lists.newArrayList(); if (!this.canGrow(level, random, position, direction, origin, offshootPositions, 0)) return false; positions.addAll(offshootPositions); @@ -62,7 +62,7 @@ public class MangroveRootPlacer extends RootPlacer { private boolean canGrow(LevelSimulatedReader level, Random random, BlockPos pos, Direction direction, BlockPos origin, List offshootPositions, int rootLength) { int length = this.mangroveRootPlacement.maxRootLength(); if (rootLength != length && offshootPositions.size() <= length) { - for(BlockPos position : this.potentialRootPositions(pos, direction, random, origin)) { + for(BlockPos position : this.getOffshootPositions(pos, direction, random, origin)) { if (this.canGrowThrough(level, position)) { offshootPositions.add(position); if (!this.canGrow(level, random, position, direction, origin, offshootPositions, rootLength + 1)) return false; @@ -75,7 +75,7 @@ public class MangroveRootPlacer extends RootPlacer { } } - protected List potentialRootPositions(BlockPos pos, Direction direction, Random random, BlockPos origin) { + protected List getOffshootPositions(BlockPos pos, Direction direction, Random random, BlockPos origin) { BlockPos below = pos.below(); BlockPos offset = pos.relative(direction); int distance = pos.distManhattan(origin); diff --git a/common/src/main/java/com/cursedcauldron/wildbackport/common/worldgen/placers/RootPlacer.java b/common/src/main/java/com/cursedcauldron/wildbackport/common/worldgen/placers/RootPlacer.java index c36e52d..926c356 100644 --- a/common/src/main/java/com/cursedcauldron/wildbackport/common/worldgen/placers/RootPlacer.java +++ b/common/src/main/java/com/cursedcauldron/wildbackport/common/worldgen/placers/RootPlacer.java @@ -37,7 +37,7 @@ public abstract class RootPlacer { })); } - protected RootPlacer(IntProvider trunkOffsetY, BlockStateProvider rootProvider, Optional aboveRootPlacement) { + public RootPlacer(IntProvider trunkOffsetY, BlockStateProvider rootProvider, Optional aboveRootPlacement) { this.trunkOffsetY = trunkOffsetY; this.rootProvider = rootProvider; this.aboveRootPlacement = aboveRootPlacement; @@ -56,8 +56,8 @@ public abstract class RootPlacer { replacer.accept(pos, this.applyWaterlogging(level, pos, this.rootProvider.getState(random, pos))); if (this.aboveRootPlacement.isPresent()) { LayerRootDecorator decorator = this.aboveRootPlacement.get(); - BlockPos aboveRoot = pos.above(); - if (random.nextFloat() < decorator.aboveRootPlacementChance() && level.isStateAtPosition(pos, BlockBehaviour.BlockStateBase::isAir)) replacer.accept(aboveRoot, this.applyWaterlogging(level, aboveRoot, decorator.aboveRootProvider().getState(random, aboveRoot))); + BlockPos above = pos.above(); + if (random.nextFloat() < decorator.aboveRootPlacementChance() && level.isStateAtPosition(above, BlockBehaviour.BlockStateBase::isAir)) replacer.accept(above, this.applyWaterlogging(level, above, decorator.aboveRootProvider().getState(random, above))); } } }