mangrove now generating moss
This commit is contained in:
parent
9557d06203
commit
94c5794556
|
@ -60,7 +60,6 @@ public class WBWorldGeneration {
|
|||
}
|
||||
|
||||
// Mangrove Swamp
|
||||
//TODO: fix mangroves not generating moss
|
||||
|
||||
public static final Holder<ConfiguredFeature<RootedTreeConfig, ?>> MANGROVE = config("mangrove", WBFeatures.TREE.get(), new RootedTreeConfig.Builder(
|
||||
BlockStateProvider.simple(WBBlocks.MANGROVE_LOG.get()),
|
||||
|
|
|
@ -77,8 +77,8 @@ public class RootedTreeFeature extends Feature<RootedTreeConfig> {
|
|||
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<RootedTreeConfig> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean place(FeaturePlaceContext<RootedTreeConfig> context) {
|
||||
public final boolean place(FeaturePlaceContext<RootedTreeConfig> context) {
|
||||
WorldGenLevel level = context.level();
|
||||
Random random = context.random();
|
||||
BlockPos pos = context.origin();
|
||||
|
@ -172,51 +172,5 @@ public class RootedTreeFeature extends Feature<RootedTreeConfig> {
|
|||
}
|
||||
}
|
||||
return shape;
|
||||
|
||||
// ArrayList<Set<BlockPos>> 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<BlockPos> trunkPos = positions.get(tries - 1);
|
||||
// Set<BlockPos> 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;
|
||||
}
|
||||
}
|
|
@ -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<BlockPos, BlockState> replacer, Random random, BlockPos pos, BlockPos origin, RootedTreeConfig config) {
|
||||
List<BlockPos> positions = Lists.newArrayList();
|
||||
ArrayList<BlockPos> 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<BlockPos> offshootPositions = Lists.newArrayList();
|
||||
ArrayList<BlockPos> 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<BlockPos> 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<BlockPos> potentialRootPositions(BlockPos pos, Direction direction, Random random, BlockPos origin) {
|
||||
protected List<BlockPos> getOffshootPositions(BlockPos pos, Direction direction, Random random, BlockPos origin) {
|
||||
BlockPos below = pos.below();
|
||||
BlockPos offset = pos.relative(direction);
|
||||
int distance = pos.distManhattan(origin);
|
||||
|
|
|
@ -37,7 +37,7 @@ public abstract class RootPlacer {
|
|||
}));
|
||||
}
|
||||
|
||||
protected RootPlacer(IntProvider trunkOffsetY, BlockStateProvider rootProvider, Optional<LayerRootDecorator> aboveRootPlacement) {
|
||||
public RootPlacer(IntProvider trunkOffsetY, BlockStateProvider rootProvider, Optional<LayerRootDecorator> 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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue