More feature placement options

This commit is contained in:
Frank 2022-05-31 19:27:23 +02:00
parent 3512f82775
commit e05801277e
3 changed files with 32 additions and 5 deletions

View file

@ -21,13 +21,14 @@ public class TemplateFeature<FC extends TemplateFeatureConfig> extends Feature<F
new TemplateFeature(
TemplateFeatureConfig.CODEC));
public static <T extends TemplateFeatureConfig> BCLFeature createAndRegister(ResourceLocation location,
public static <T extends TemplateFeatureConfig> BCLFeature createAndRegisterRare(ResourceLocation location,
TemplateFeatureConfig configuration,
int onveEveryChunk) {
int onceEveryChunk) {
return BCLFeatureBuilder
.start(location, INSTANCE)
.decoration(GenerationStep.Decoration.SURFACE_STRUCTURES)
.oncePerChunks(onveEveryChunk)
.squarePlacement()
.distanceToTopAndBottom10()
.modifier(EnvironmentScanPlacement.scanningFor(Direction.DOWN,
@ -37,6 +38,22 @@ public class TemplateFeature<FC extends TemplateFeatureConfig> extends Feature<F
Blocks.LAVA),
12))
.modifier(BiomeFilter.biome())
.oncePerChunks(onceEveryChunk)
.buildAndRegister(configuration);
}
public static <T extends TemplateFeatureConfig> BCLFeature createAndRegister(ResourceLocation location,
TemplateFeatureConfig configuration,
int count) {
return BCLFeatureBuilder
.start(location, INSTANCE)
.decoration(GenerationStep.Decoration.SURFACE_STRUCTURES)
.count(count)
.squarePlacement()
.distanceToTopAndBottom10()
.onlyInBiome()
.buildAndRegister(configuration);
}

View file

@ -5,7 +5,7 @@ import net.minecraft.util.StringRepresentable;
import com.mojang.serialization.Codec;
public enum StructurePlacementType implements StringRepresentable {
FLOOR, WALL, CEIL, LAVA, UNDER;
FLOOR, WALL, CEIL, LAVA, UNDER, FLOOR_FREE_ABOVE;
public static final Codec<StructurePlacementType> CODEC = StringRepresentable.fromEnum(StructurePlacementType::values);

View file

@ -104,6 +104,8 @@ public class StructureWorldNBT extends StructureNBT {
return canGenerateUnder(level, pos, rotation);
else if (type == StructurePlacementType.CEIL)
return canGenerateCeil(level, pos, rotation);
else if (type == StructurePlacementType.FLOOR_FREE_ABOVE)
return canGenerateFloorFreeAbove(level, pos, rotation);
else
return false;
}
@ -117,6 +119,14 @@ public class StructureWorldNBT extends StructureNBT {
return false;
}
protected boolean canGenerateFloorFreeAbove(LevelAccessor world, BlockPos pos, Rotation rotation) {
if (containsBedrock(world, pos)) return false;
return getAirFractionFoundation(world, pos, rotation) < 0.5
&& world.getBlockState(pos.above(2)).is(Blocks.AIR)
&& world.getBlockState(pos.above(4)).is(Blocks.AIR);
}
protected boolean canGenerateFloor(LevelAccessor world, BlockPos pos, Rotation rotation) {
if (containsBedrock(world, pos)) return false;