fixes for 22w11a

This commit is contained in:
gnembon committed 2022-03-17 20:21:55 +01:00
1 parent 3e419d1557
commit 302a7b4817
39 files changed
+410 -305

No files matched your search

+26 -24
View File
@@ -3,22 +3,22 @@ package carpet.utils;
import carpet.CarpetSettings;
import it.unimi.dsi.fastutil.longs.LongSet;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.core.SectionPos;
import net.minecraft.data.worldgen.StructureFeatures;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.random.WeightedRandomList;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.level.StructureFeatureManager;
import net.minecraft.world.level.StructureManager;
import net.minecraft.world.level.biome.MobSpawnSettings;
import net.minecraft.world.level.chunk.ChunkStatus;
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
import net.minecraft.world.level.levelgen.feature.StructureFeature;
import net.minecraft.world.level.levelgen.structure.BuiltinStructures;
import net.minecraft.world.level.levelgen.structure.Structure;
import net.minecraft.world.level.levelgen.structure.StructureSpawnOverride;
import net.minecraft.world.level.levelgen.structure.StructureStart;
import net.minecraft.world.level.levelgen.structure.StructureType;
import org.apache.commons.lang3.tuple.Pair;
import java.util.ArrayList;
@@ -28,16 +28,16 @@ import java.util.Map;
import java.util.function.BooleanSupplier;
public class SpawnOverrides {
final private static Map<Pair<MobCategory, StructureFeature<?>>, Pair<BooleanSupplier, StructureSpawnOverride>> carpetOverrides = new HashMap<>();
final private static Map<Pair<MobCategory, ResourceKey<Structure>>, Pair<BooleanSupplier, StructureSpawnOverride>> carpetOverrides = new HashMap<>();
static {
addOverride(() -> CarpetSettings.huskSpawningInTemples, MobCategory.MONSTER, StructureFeatures.DESERT_PYRAMID, StructureSpawnOverride.BoundingBoxType.STRUCTURE,
addOverride(() -> CarpetSettings.huskSpawningInTemples, MobCategory.MONSTER, BuiltinStructures.DESERT_PYRAMID, StructureSpawnOverride.BoundingBoxType.STRUCTURE,
WeightedRandomList.create(new MobSpawnSettings.SpawnerData(EntityType.HUSK, 1, 1, 1))
);
addOverride(() -> CarpetSettings.shulkerSpawningInEndCities, MobCategory.MONSTER, StructureFeatures.END_CITY, StructureSpawnOverride.BoundingBoxType.PIECE,
addOverride(() -> CarpetSettings.shulkerSpawningInEndCities, MobCategory.MONSTER, BuiltinStructures.END_CITY, StructureSpawnOverride.BoundingBoxType.PIECE,
WeightedRandomList.create(new MobSpawnSettings.SpawnerData(EntityType.SHULKER, 10, 4, 4))
);
addOverride(() -> CarpetSettings.piglinsSpawningInBastions, MobCategory.MONSTER, StructureFeatures.BASTION_REMNANT, StructureSpawnOverride.BoundingBoxType.PIECE,
addOverride(() -> CarpetSettings.piglinsSpawningInBastions, MobCategory.MONSTER, BuiltinStructures.BASTION_REMNANT, StructureSpawnOverride.BoundingBoxType.PIECE,
WeightedRandomList.create(
new MobSpawnSettings.SpawnerData(EntityType.PIGLIN_BRUTE, 5, 1, 2),
new MobSpawnSettings.SpawnerData(EntityType.PIGLIN, 10, 2, 4),
@@ -47,14 +47,16 @@ public class SpawnOverrides {
}
public static void addOverride(BooleanSupplier when, MobCategory cat, Holder<ConfiguredStructureFeature<?, ?>> poo,
public static void addOverride(BooleanSupplier when, MobCategory cat, ResourceKey<Structure> poo,
StructureSpawnOverride.BoundingBoxType type, WeightedRandomList<MobSpawnSettings.SpawnerData> spawns) {
carpetOverrides.put(Pair.of(cat, poo.value().feature), Pair.of(when, new StructureSpawnOverride(type, spawns)));
carpetOverrides.put(Pair.of(cat, poo), Pair.of(when, new StructureSpawnOverride(type, spawns)));
}
public static WeightedRandomList<MobSpawnSettings.SpawnerData> test(StructureFeatureManager structureFeatureManager, LongSet foo,
MobCategory cat, ConfiguredStructureFeature<?, ?> confExisting, BlockPos where) {
final Pair<BooleanSupplier, StructureSpawnOverride> spawnData = carpetOverrides.get(Pair.of(cat, confExisting.feature));
public static WeightedRandomList<MobSpawnSettings.SpawnerData> test(StructureManager structureFeatureManager, LongSet foo,
MobCategory cat, Structure confExisting, BlockPos where) {
ResourceLocation resource = structureFeatureManager.registryAccess().registryOrThrow(Registry.STRUCTURE_REGISTRY).getKey(confExisting);
ResourceKey<Structure> key = ResourceKey.create(Registry.STRUCTURE_REGISTRY, resource);
final Pair<BooleanSupplier, StructureSpawnOverride> spawnData = carpetOverrides.get(Pair.of(cat, key));
if (spawnData == null || !spawnData.getKey().getAsBoolean()) return null;
StructureSpawnOverride override = spawnData.getRight();
if (override.boundingBox() == StructureSpawnOverride.BoundingBoxType.STRUCTURE) {
@@ -62,7 +64,7 @@ public class SpawnOverrides {
return override.spawns();
} else {
List<StructureStart> starts = new ArrayList<>(1);
structureFeatureManager.fillStartsForFeature(confExisting, foo, starts::add);
structureFeatureManager.fillStartsForStructure(confExisting, foo, starts::add);
for (StructureStart start : starts) {
if (start != null && start.isValid() && structureFeatureManager.structureHasPieceAt(where, start)) {
return override.spawns();
@@ -72,16 +74,16 @@ public class SpawnOverrides {
return null;
}
public static boolean isStructureAtPosition(ServerLevel level, ResourceKey<ConfiguredStructureFeature<?, ?>> structureKey, BlockPos pos)
public static boolean isStructureAtPosition(ServerLevel level, ResourceKey<Structure> structureKey, BlockPos pos)
{
final ConfiguredStructureFeature<?, ?> fortressFeature = level.registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY).get(structureKey);
final Structure fortressFeature = level.registryAccess().registryOrThrow(Registry.STRUCTURE_REGISTRY).get(structureKey);
if (fortressFeature == null) {
return false;
}
return level.structureFeatureManager().getStructureAt(pos, fortressFeature).isValid();
return level.structureManager().getStructureAt(pos, fortressFeature).isValid();
}
public static boolean isStructureAtPosition(ServerLevel level, StructureFeature<?> structure, BlockPos pos)
public static boolean isStructureAtPosition(ServerLevel level, StructureType<?> structure, BlockPos pos)
{
for(StructureStart structureStart : startsForFeature(level, SectionPos.of(pos), structure)) {
if (structureStart.getBoundingBox().isInside(pos) && structureStart.isValid()) {
@@ -91,15 +93,15 @@ public class SpawnOverrides {
return false;
}
public static List<StructureStart> startsForFeature(ServerLevel level, SectionPos sectionPos, StructureFeature<?> structure) {
Map<ConfiguredStructureFeature<?, ?>, LongSet> allrefs = level.getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES).getAllReferences();
public static List<StructureStart> startsForFeature(ServerLevel level, SectionPos sectionPos, StructureType<?> structure) {
Map<Structure, LongSet> allrefs = level.getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES).getAllReferences();
List<StructureStart> result = new ArrayList<>();
for (var entry: allrefs.entrySet())
{
ConfiguredStructureFeature<?, ?> existing = entry.getKey();
if (existing.feature == structure)
Structure existing = entry.getKey();
if (existing.type() == structure)
{
level.structureFeatureManager().fillStartsForFeature(existing, entry.getValue(), result::add);
level.structureManager().fillStartsForStructure(existing, entry.getValue(), result::add);
}
}
return result;