22w06a
This commit is contained in:
1 parent
695b569977
commit
212814f46d
27 files changed
+264
-144
No files matched your search
@@ -12,11 +12,17 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.data.worldgen.ProcessorLists;
|
||||
import net.minecraft.data.worldgen.StructureFeatures;
|
||||
import net.minecraft.data.worldgen.placement.PlacementUtils;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
@@ -34,10 +40,11 @@ import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
|
||||
import net.minecraft.world.level.levelgen.feature.Feature;
|
||||
import net.minecraft.world.level.levelgen.feature.StructureFeature;
|
||||
//import net.minecraft.world.level.levelgen.feature.configurations.StructureFeatureConfiguration;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.JigsawConfiguration;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.SimpleRandomFeatureConfiguration;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.StructureFeatureConfiguration;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration;
|
||||
import net.minecraft.world.level.levelgen.feature.featuresize.TwoLayersFeatureSize;
|
||||
import net.minecraft.world.level.levelgen.feature.foliageplacers.BlobFoliagePlacer;
|
||||
@@ -51,6 +58,8 @@ import net.minecraft.world.level.levelgen.feature.trunkplacers.StraightTrunkPlac
|
||||
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||
import net.minecraft.world.level.levelgen.structure.StructureCheckResult;
|
||||
import net.minecraft.world.level.levelgen.structure.StructureStart;
|
||||
import net.minecraft.world.level.levelgen.structure.placement.ConcentricRingsStructurePlacement;
|
||||
import net.minecraft.world.level.levelgen.structure.placement.StructurePlacement;
|
||||
|
||||
public class FeatureGenerator
|
||||
{
|
||||
@@ -129,7 +138,7 @@ public class FeatureGenerator
|
||||
{
|
||||
return ((StructureFeatureInterface)structureFeature.feature).plopAnywhere(
|
||||
world, pos, world.getChunkSource().getGenerator(),
|
||||
true, net.minecraft.data.worldgen.biome.Biomes.PLAINS, structureFeature.config);
|
||||
true, world.getServer().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).get(net.minecraft.world.level.biome.Biomes.PLAINS), structureFeature.config);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
@@ -137,7 +146,7 @@ public class FeatureGenerator
|
||||
{
|
||||
Boolean plop(ServerLevel world, BlockPos pos);
|
||||
}
|
||||
private static Thing simplePlop(ConfiguredFeature feature)
|
||||
private static Thing simplePlop(ConfiguredFeature<?,?> feature)
|
||||
{
|
||||
return (w, p) -> {
|
||||
CarpetSettings.skipGenerationChecks.set(true);
|
||||
@@ -152,10 +161,20 @@ public class FeatureGenerator
|
||||
};
|
||||
}
|
||||
|
||||
private static <FC extends FeatureConfiguration, F extends Feature<FC>> Thing simplePlop(F feature, FC config)
|
||||
{
|
||||
return simplePlop(new ConfiguredFeature<>(feature, config));
|
||||
}
|
||||
|
||||
private static Thing simplePlop(Holder<PlacedFeature> hpf)
|
||||
{
|
||||
return simplePlop(hpf.value().feature().value());
|
||||
}
|
||||
|
||||
private static Thing simpleTree(TreeConfiguration config)
|
||||
{
|
||||
//config.ignoreFluidCheck();
|
||||
return simplePlop(Feature.TREE.configured(config));
|
||||
return simplePlop(new ConfiguredFeature(Feature.TREE, config));
|
||||
}
|
||||
|
||||
private static Thing spawnCustomStructure(StructureFeature structure, FeatureConfiguration conf, ResourceKey<Biome> biome)
|
||||
@@ -177,11 +196,14 @@ public class FeatureGenerator
|
||||
private static ConfiguredStructureFeature<?, ?> getDefaultFeature(StructureFeature<?> structure, ServerLevel world, BlockPos pos, boolean tryHard)
|
||||
{
|
||||
var definedStructures = world.getChunkSource().getGenerator().getSettings().structures(structure);
|
||||
var optinalBiome = world.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getResourceKey(world.getBiome(pos));
|
||||
var optinalBiome = world.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getResourceKey(world.getBiome(pos).value());
|
||||
if (optinalBiome.isPresent())
|
||||
for (var configureStructure: definedStructures.inverse().get(optinalBiome.get()))
|
||||
for (ResourceKey<ConfiguredStructureFeature<?, ?>> configureStructureKey: definedStructures.inverse().get(optinalBiome.get()))
|
||||
{
|
||||
var configureStructure = world.registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY).get(configureStructureKey);
|
||||
if (configureStructure.feature == structure)
|
||||
return configureStructure;
|
||||
}
|
||||
if (!tryHard) return null;
|
||||
return world.registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY).entrySet().stream().
|
||||
filter(cS -> cS.getValue().feature == structure).
|
||||
@@ -190,41 +212,45 @@ public class FeatureGenerator
|
||||
|
||||
private static ConfiguredFeature<?, ?> getDefaultFeature(Feature<?> feature, ServerLevel world, BlockPos pos, boolean tryHard)
|
||||
{
|
||||
List<List<Supplier<PlacedFeature>>> configuredStepFeatures = world.getBiome(pos).getGenerationSettings().features();
|
||||
for (List<Supplier<PlacedFeature>> step: configuredStepFeatures)
|
||||
for (Supplier<PlacedFeature> provider: step)
|
||||
List<HolderSet<PlacedFeature>> configuredStepFeatures = world.getBiome(pos).value().getGenerationSettings().features();
|
||||
for (HolderSet<PlacedFeature> step: configuredStepFeatures)
|
||||
for (Holder<PlacedFeature> provider: step)
|
||||
{
|
||||
ConfiguredFeature<?, ?> configuredFeature = ((PlacedFeatureInterface)provider.get()).getRawFeature();
|
||||
if (configuredFeature.feature == feature)
|
||||
return configuredFeature;
|
||||
if (provider.value().feature().value().feature() == feature)
|
||||
return provider.value().feature().value();
|
||||
}
|
||||
if (!tryHard) return null;
|
||||
return world.registryAccess().registryOrThrow(Registry.CONFIGURED_FEATURE_REGISTRY).entrySet().stream().
|
||||
filter(cS -> cS.getValue().feature == feature).
|
||||
filter(cS -> cS.getValue().feature() == feature).
|
||||
findFirst().map(Map.Entry::getValue).orElse(null);
|
||||
}
|
||||
|
||||
public static <T extends FeatureConfiguration> StructureStart shouldStructureStartAt(ServerLevel world, BlockPos pos, StructureFeature<T> structure, boolean computeBox)
|
||||
{
|
||||
if (structure == StructureFeature.STRONGHOLD)
|
||||
return shouldStrongholdStartAt(world, pos, computeBox);
|
||||
//if (structure == StructureFeature.STRONGHOLD)
|
||||
// return shouldStrongholdStartAt(world, pos, computeBox);
|
||||
long seed = world.getSeed();
|
||||
ChunkGenerator generator = world.getChunkSource().getGenerator();
|
||||
StructureSettings settings = generator.getSettings();
|
||||
StructureFeatureConfiguration structureConfig = settings.getConfig(structure);
|
||||
StructurePlacement structureConfig = settings.getConfig(structure);
|
||||
if (structureConfig instanceof ConcentricRingsStructurePlacement rings)
|
||||
{
|
||||
return shouldStrongholdStartAt(generator, rings, world, pos, computeBox);
|
||||
}
|
||||
var structures = settings.structures(structure);
|
||||
if (structureConfig == null || structures.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
ChunkPos chunkPos = new ChunkPos(pos);
|
||||
Biome biome = world.getBiome(pos);
|
||||
var biomeRegistry = world.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY);
|
||||
if (structures.values().stream().noneMatch(biomeKey -> biomeRegistry.get(biomeKey) == biome))
|
||||
Holder<Biome> biome = world.getBiome(pos);
|
||||
Registry<Biome> biomeRegistry = world.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY);
|
||||
if (structures.values().stream().noneMatch(biomeKey -> biomeRegistry.getHolderOrThrow(biomeKey) == biome))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
ChunkPos chunkPos1 = structure.getPotentialFeatureChunk(structureConfig, seed, chunkPos.x, chunkPos.z);
|
||||
if (!chunkPos1.equals(chunkPos))
|
||||
if (!structureConfig.isFeatureChunk(generator, chunkPos.x, chunkPos.z))
|
||||
//ChunkPos chunkPos1 = structure.getPotentialFeatureChunk(structureConfig, seed, chunkPos.x, chunkPos.z);
|
||||
//if (!chunkPos1.equals(chunkPos))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -242,25 +268,27 @@ public class FeatureGenerator
|
||||
if (!computeBox) return StructureStart.INVALID_START;
|
||||
ConfiguredStructureFeature<?, ?> configuredFeature = getDefaultFeature(structure, world, pos, false);
|
||||
if (configuredFeature == null || configuredFeature.config == null) return null;
|
||||
var biomeConfig = structures.get(configuredFeature);
|
||||
|
||||
var biomeConfig = structures.get(ResourceKey.create(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY, world.registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY).getKey(configuredFeature)));
|
||||
StructureStart<?> filledStructure = configuredFeature.generate(world.registryAccess(), generator, generator.getBiomeSource(),
|
||||
world.getStructureManager(), seed, chunkPos, 0, structureConfig, world, (b) -> biomeRegistry.getResourceKey(b).filter(biomeConfig::contains).isPresent());
|
||||
world.getStructureManager(), seed, chunkPos, 0, world, b -> biomeRegistry.getResourceKey(b.value()).filter(biomeConfig::contains).isPresent());
|
||||
if (filledStructure != null && filledStructure.isValid())
|
||||
return filledStructure;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static StructureStart<?> shouldStrongholdStartAt(ServerLevel world, BlockPos pos, boolean computeBox)
|
||||
public static StructureStart<?> shouldStrongholdStartAt(ChunkGenerator generator, ConcentricRingsStructurePlacement rings, ServerLevel world, BlockPos pos, boolean computeBox)
|
||||
{
|
||||
ChunkGenerator generator = world.getChunkSource().getGenerator();
|
||||
if (world.dimension() != Level.OVERWORLD || !generator.hasStronghold(new ChunkPos(pos))) return null;
|
||||
final List<ChunkPos> positions = generator.getRingPositionsFor(rings);
|
||||
if (world.dimension() != Level.OVERWORLD || !positions.contains(new ChunkPos(pos))) return null;
|
||||
if (!computeBox) return StructureStart.INVALID_START;
|
||||
StructureSettings settings = generator.getSettings();
|
||||
StructureFeatureConfiguration structureConfig = settings.getConfig(StructureFeature.STRONGHOLD);
|
||||
StructurePlacement structureConfig = settings.getConfig(StructureFeature.STRONGHOLD);
|
||||
if (structureConfig != null) {
|
||||
StructureStart<?> filledStructure = StructureFeatures.STRONGHOLD.generate(world.registryAccess(), generator, generator.getBiomeSource(),
|
||||
world.getStructureManager(), world.getSeed(), new ChunkPos(pos), 0,
|
||||
structureConfig, world, ((ChunkGeneratorInterface)generator)::canPlaceStrongholdInBiomeCM
|
||||
final Predicate<ResourceKey<Biome>> biomeCheck = settings.structures(StructureFeature.STRONGHOLD).values().stream().collect(Collectors.toUnmodifiableSet())::contains;
|
||||
final Predicate<Holder<Biome>> holderCheck = b -> b.is(biomeCheck);
|
||||
StructureStart<?> filledStructure = StructureFeature.STRONGHOLD.generate(world.registryAccess(), generator, generator.getBiomeSource(),
|
||||
world.getStructureManager(), world.getSeed(), new ChunkPos(pos), 0, NoneFeatureConfiguration.INSTANCE, world, holderCheck
|
||||
);
|
||||
if (filledStructure != null && filledStructure.isValid())
|
||||
return filledStructure;
|
||||
@@ -278,60 +306,62 @@ public class FeatureGenerator
|
||||
put("fancy_oak_bees", simpleTree( (new TreeConfiguration.TreeConfigurationBuilder(BlockStateProvider.simple(Blocks.OAK_LOG), new FancyTrunkPlacer(3, 11, 0), BlockStateProvider.simple(Blocks.OAK_LEAVES), new FancyFoliagePlacer(ConstantInt.of(2), ConstantInt.of(4), 4), new TwoLayersFeatureSize(0, 0, 0, OptionalInt.of(4)))).ignoreVines().decorators(List.of(new BeehiveDecorator(1.00F))).build()));
|
||||
put("birch_bees", simpleTree( createTree(Blocks.BIRCH_LOG, Blocks.BIRCH_LEAVES, 5, 2, 0, 2).ignoreVines().decorators(List.of(new BeehiveDecorator(1.00F))).build()));
|
||||
|
||||
put("coral_tree", simplePlop(Feature.CORAL_TREE.configured(FeatureConfiguration.NONE)));
|
||||
put("coral_claw", simplePlop(Feature.CORAL_CLAW.configured(FeatureConfiguration.NONE)));
|
||||
put("coral_mushroom", simplePlop(Feature.CORAL_MUSHROOM.configured(FeatureConfiguration.NONE)));
|
||||
put("coral", simplePlop(Feature.SIMPLE_RANDOM_SELECTOR.configured(new SimpleRandomFeatureConfiguration(List.of(
|
||||
() -> Feature.CORAL_TREE.configured(FeatureConfiguration.NONE).placed(),
|
||||
() -> Feature.CORAL_CLAW.configured(FeatureConfiguration.NONE).placed(),
|
||||
() -> Feature.CORAL_MUSHROOM.configured(FeatureConfiguration.NONE).placed()
|
||||
)))));
|
||||
//put("coral_tree", simplePlop(Feature.CORAL_TREE.configured(FeatureConfiguration.NONE)));
|
||||
put("coral_tree", simplePlop(Feature.CORAL_TREE, FeatureConfiguration.NONE));
|
||||
|
||||
put("coral_claw", simplePlop(Feature.CORAL_CLAW, FeatureConfiguration.NONE));
|
||||
put("coral_mushroom", simplePlop(Feature.CORAL_MUSHROOM, FeatureConfiguration.NONE));
|
||||
put("coral", simplePlop(Feature.SIMPLE_RANDOM_SELECTOR, new SimpleRandomFeatureConfiguration(HolderSet.direct(
|
||||
PlacementUtils.inlinePlaced(Feature.CORAL_TREE, FeatureConfiguration.NONE),
|
||||
PlacementUtils.inlinePlaced(Feature.CORAL_CLAW, FeatureConfiguration.NONE),
|
||||
PlacementUtils.inlinePlaced(Feature.CORAL_MUSHROOM, FeatureConfiguration.NONE)
|
||||
))));
|
||||
put("bastion_remnant_units", spawnCustomStructure(
|
||||
StructureFeature.BASTION_REMNANT,
|
||||
new JigsawConfiguration(() -> new StructureTemplatePool(
|
||||
new JigsawConfiguration(Holder.direct(new StructureTemplatePool(
|
||||
new ResourceLocation("bastion/starts"),
|
||||
new ResourceLocation("empty"),
|
||||
List.of(
|
||||
Pair.of(StructurePoolElement.single("bastion/units/air_base", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
|
||||
),
|
||||
StructureTemplatePool.Projection.RIGID
|
||||
), 6),
|
||||
)), 6),
|
||||
Biomes.NETHER_WASTES
|
||||
));
|
||||
put("bastion_remnant_hoglin_stable", spawnCustomStructure(
|
||||
StructureFeature.BASTION_REMNANT,
|
||||
new JigsawConfiguration(() -> new StructureTemplatePool(
|
||||
new JigsawConfiguration(Holder.direct(new StructureTemplatePool(
|
||||
new ResourceLocation("bastion/starts"),
|
||||
new ResourceLocation("empty"),
|
||||
List.of(
|
||||
Pair.of(StructurePoolElement.single("bastion/hoglin_stable/air_base", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
|
||||
),
|
||||
StructureTemplatePool.Projection.RIGID
|
||||
), 6),
|
||||
)), 6),
|
||||
Biomes.NETHER_WASTES
|
||||
));
|
||||
put("bastion_remnant_treasure", spawnCustomStructure(
|
||||
StructureFeature.BASTION_REMNANT,
|
||||
new JigsawConfiguration(() -> new StructureTemplatePool(
|
||||
new JigsawConfiguration(Holder.direct(new StructureTemplatePool(
|
||||
new ResourceLocation("bastion/starts"),
|
||||
new ResourceLocation("empty"),
|
||||
List.of(
|
||||
Pair.of(StructurePoolElement.single("bastion/treasure/big_air_full", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
|
||||
),
|
||||
StructureTemplatePool.Projection.RIGID
|
||||
), 6),
|
||||
)), 6),
|
||||
Biomes.NETHER_WASTES
|
||||
));
|
||||
put("bastion_remnant_bridge", spawnCustomStructure(
|
||||
StructureFeature.BASTION_REMNANT,
|
||||
new JigsawConfiguration(() -> new StructureTemplatePool(
|
||||
new JigsawConfiguration(Holder.direct(new StructureTemplatePool(
|
||||
new ResourceLocation("bastion/starts"),
|
||||
new ResourceLocation("empty"),
|
||||
List.of(
|
||||
Pair.of(StructurePoolElement.single("bastion/bridge/starting_pieces/entrance_base", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
|
||||
),
|
||||
StructureTemplatePool.Projection.RIGID
|
||||
), 6),
|
||||
)), 6),
|
||||
Biomes.NETHER_WASTES
|
||||
));
|
||||
}};
|
||||
|
||||
Reference in new issue
Block a user