mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-08-27 12:41:43 +00:00
d
This commit is contained in:
@@ -53,6 +53,10 @@ public final class ModdedMixinAudit {
|
||||
new ExpectedMixin("MobAwarenessMixin", "entity",
|
||||
"net.minecraft.world.entity.Mob", "iris$tickUnawareMob",
|
||||
false, ModdedMixinFlags::mobAwarenessRan),
|
||||
new ExpectedMixin("StructureTemplatePaletteConcurrencyMixin", "common",
|
||||
"net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate$Palette",
|
||||
"iris$installConcurrentBlockCache",
|
||||
false, ModdedMixinFlags::structureTemplatePaletteRan),
|
||||
new ExpectedMixin("IrisWorldOpenFlowsMixin", "client",
|
||||
"net.minecraft.client.gui.screens.worldselection.WorldOpenFlows",
|
||||
"iris$openWorldCheckWorldStemCompatibility",
|
||||
@@ -103,7 +107,7 @@ public final class ModdedMixinAudit {
|
||||
LOGGER.error(" missing: {}", entry);
|
||||
}
|
||||
LOGGER.error("The mixin config was not registered for this loader (fabric.mod.json mixins, neoforge.mods.toml [[mixins]], forge MixinConfigs manifest attribute).");
|
||||
LOGGER.error("Entity persistence, custom mob loot and Iris world-type labels are disabled until this is fixed.");
|
||||
LOGGER.error("Entity persistence, custom mob loot, parallel structure safety, or Iris world-type labels are disabled until this is fixed.");
|
||||
LOGGER.error("===============================================================");
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ public final class ModdedMixinFlags {
|
||||
private static volatile boolean entityPersistenceRan;
|
||||
private static volatile boolean livingEntityLootRan;
|
||||
private static volatile boolean mobAwarenessRan;
|
||||
private static volatile boolean structureTemplatePaletteRan;
|
||||
private static volatile boolean worldOpenFlowsRan;
|
||||
private static volatile boolean worldTypeEntryRan;
|
||||
|
||||
@@ -58,6 +59,12 @@ public final class ModdedMixinFlags {
|
||||
}
|
||||
}
|
||||
|
||||
public static void markStructureTemplatePalette() {
|
||||
if (!structureTemplatePaletteRan) {
|
||||
structureTemplatePaletteRan = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void markWorldOpenFlows() {
|
||||
if (!worldOpenFlowsRan) {
|
||||
worldOpenFlowsRan = true;
|
||||
@@ -82,6 +89,10 @@ public final class ModdedMixinFlags {
|
||||
return mobAwarenessRan;
|
||||
}
|
||||
|
||||
public static boolean structureTemplatePaletteRan() {
|
||||
return structureTemplatePaletteRan;
|
||||
}
|
||||
|
||||
public static boolean worldOpenFlowsRan() {
|
||||
return worldOpenFlowsRan;
|
||||
}
|
||||
@@ -94,6 +105,7 @@ public final class ModdedMixinFlags {
|
||||
entityPersistenceRan = false;
|
||||
livingEntityLootRan = false;
|
||||
mobAwarenessRan = false;
|
||||
structureTemplatePaletteRan = false;
|
||||
worldOpenFlowsRan = false;
|
||||
worldTypeEntryRan = false;
|
||||
}
|
||||
|
||||
+27
-3
@@ -50,10 +50,12 @@ import net.minecraft.core.SectionPos;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.ai.village.poi.PoiTypes;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.LevelHeightAccessor;
|
||||
import net.minecraft.world.level.StructureManager;
|
||||
import net.minecraft.world.level.WorldGenLevel;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.biome.BiomeSource;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
@@ -73,6 +75,7 @@ import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.IntBinaryOperator;
|
||||
|
||||
/**
|
||||
@@ -346,6 +349,11 @@ final class ModdedNativeStructureStage {
|
||||
index++;
|
||||
}
|
||||
}
|
||||
if (!placementGroups.isEmpty()) {
|
||||
ServerLevel level = world.getLevel();
|
||||
visitExistingPois(chunk, (position, state) -> level.updatePOIOnBlockStateChange(
|
||||
position, Blocks.AIR.defaultBlockState(), state));
|
||||
}
|
||||
try {
|
||||
int runtimeMinY = world.getMinY();
|
||||
WorldgenTerrainHeightmaps.primeStructurePlacement(
|
||||
@@ -405,6 +413,10 @@ final class ModdedNativeStructureStage {
|
||||
}
|
||||
}
|
||||
|
||||
static void visitExistingPois(ChunkAccess chunk, BiConsumer<BlockPos, BlockState> visitor) {
|
||||
chunk.findBlocks(PoiTypes::hasPoi, visitor);
|
||||
}
|
||||
|
||||
private static String nativeStructureBatchContext(List<NativePlacementGroup> placementGroups) {
|
||||
if (placementGroups.isEmpty()) {
|
||||
return "<no resolved native structures>";
|
||||
@@ -423,9 +435,21 @@ final class ModdedNativeStructureStage {
|
||||
WorldgenRandom random, BoundingBox area, ChunkPos chunkPos,
|
||||
String structureId, StructureStart start,
|
||||
IrisNativeStructureDecision decision) {
|
||||
NativeStructurePostProcessor.place(world, structureManager, generator, random, area, chunkPos,
|
||||
structureId, start, decision, this::resolvePaletteBlock,
|
||||
(x, z) -> generator.engine().getHeight(x, z, true) + generator.engine().getMinHeight());
|
||||
Engine current = generator.engine();
|
||||
int runtimeMinY = world.getMinY();
|
||||
WorldGenLevel boundedWorld = ModdedNativeStructureWorldgenAccess.create(
|
||||
world, chunkPos,
|
||||
worldgenSurfaceHeight(current, runtimeMinY),
|
||||
worldgenFloorHeight(current, runtimeMinY));
|
||||
world.setCurrentlyGenerating(() -> "Iris native structure " + structureId);
|
||||
try {
|
||||
NativeStructurePostProcessor.place(
|
||||
boundedWorld, structureManager, generator, random, area, chunkPos,
|
||||
structureId, start, decision, this::resolvePaletteBlock,
|
||||
(x, z) -> current.getHeight(x, z, true) + current.getMinHeight());
|
||||
} finally {
|
||||
world.setCurrentlyGenerating(null);
|
||||
}
|
||||
}
|
||||
|
||||
private List<List<Structure>> structuresByStep(Registry<Structure> registry) {
|
||||
|
||||
+558
@@ -0,0 +1,558 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.iris.nativegen.WorldgenTerrainHeightmaps;
|
||||
import it.unimi.dsi.fastutil.longs.Long2LongOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.QuartPos;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.particles.ParticleOptions;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.DifficultyInstance;
|
||||
import net.minecraft.world.attribute.EnvironmentAttributeReader;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.flag.FeatureFlagSet;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.LightLayer;
|
||||
import net.minecraft.world.level.WorldGenLevel;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeManager;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.border.WorldBorder;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.ChunkSource;
|
||||
import net.minecraft.world.level.chunk.EmptyLevelChunk;
|
||||
import net.minecraft.world.level.chunk.status.ChunkStatus;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.entity.EntityTypeTest;
|
||||
import net.minecraft.world.level.gameevent.GameEvent;
|
||||
import net.minecraft.world.level.levelgen.Heightmap;
|
||||
import net.minecraft.world.level.lighting.LevelLightEngine;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.storage.LevelData;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.world.ticks.LevelTickAccess;
|
||||
import net.minecraft.world.ticks.ScheduledTick;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.IntBinaryOperator;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
final class ModdedNativeStructureWorldgenAccess implements WorldGenLevel {
|
||||
private static final int WRITE_RADIUS = 1;
|
||||
|
||||
private final WorldGenLevel delegate;
|
||||
private final ChunkPos generationCenter;
|
||||
private final IntBinaryOperator surfaceFirstFreeY;
|
||||
private final IntBinaryOperator floorFirstFreeY;
|
||||
private final Holder<Biome> fallbackBiome;
|
||||
private final BiomeManager biomeManager;
|
||||
private final AABB generationBounds;
|
||||
private final LevelTickAccess<Block> blockTicks;
|
||||
private final LevelTickAccess<Fluid> fluidTicks;
|
||||
private final Long2LongOpenHashMap terrainHeights;
|
||||
private final Long2ObjectOpenHashMap<ChunkAccess> outsideChunks;
|
||||
|
||||
private ModdedNativeStructureWorldgenAccess(WorldGenLevel delegate, Boundary boundary) {
|
||||
this.delegate = Objects.requireNonNull(delegate, "Native structure world access requires a delegate");
|
||||
this.generationCenter = Objects.requireNonNull(
|
||||
boundary.generationCenter(), "Native structure world access requires a generation center");
|
||||
this.surfaceFirstFreeY = Objects.requireNonNull(
|
||||
boundary.surfaceFirstFreeY(), "Native structure world access requires a surface resolver");
|
||||
this.floorFirstFreeY = Objects.requireNonNull(
|
||||
boundary.floorFirstFreeY(), "Native structure world access requires an ocean-floor resolver");
|
||||
BlockPos biomeSample = generationCenter.getMiddleBlockPosition(delegate.getSeaLevel());
|
||||
this.fallbackBiome = delegate.getBiome(biomeSample);
|
||||
this.biomeManager = delegate.getBiomeManager().withDifferentSource(this);
|
||||
this.generationBounds = new AABB(
|
||||
generationCenter.getMinBlockX() - 16,
|
||||
delegate.getMinY(),
|
||||
generationCenter.getMinBlockZ() - 16,
|
||||
generationCenter.getMaxBlockX() + 17,
|
||||
delegate.getMinY() + delegate.getHeight(),
|
||||
generationCenter.getMaxBlockZ() + 17);
|
||||
this.blockTicks = new BoundedTickAccess<>(delegate.getBlockTicks(), this::isWritable);
|
||||
this.fluidTicks = new BoundedTickAccess<>(delegate.getFluidTicks(), this::isWritable);
|
||||
this.terrainHeights = new Long2LongOpenHashMap();
|
||||
this.terrainHeights.defaultReturnValue(Long.MIN_VALUE);
|
||||
this.outsideChunks = new Long2ObjectOpenHashMap<>();
|
||||
}
|
||||
|
||||
static ModdedNativeStructureWorldgenAccess create(WorldGenLevel delegate, ChunkPos generationCenter,
|
||||
IntBinaryOperator surfaceFirstFreeY,
|
||||
IntBinaryOperator floorFirstFreeY) {
|
||||
return new ModdedNativeStructureWorldgenAccess(delegate, new Boundary(
|
||||
generationCenter, surfaceFirstFreeY, floorFirstFreeY));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSeed() {
|
||||
return delegate.getSeed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ensureCanWrite(BlockPos position) {
|
||||
return isWritable(position) && delegate.ensureCanWrite(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentlyGenerating(Supplier<String> description) {
|
||||
delegate.setCurrentlyGenerating(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerLevel getLevel() {
|
||||
return delegate.getLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DifficultyInstance getCurrentDifficultyAt(BlockPos position) {
|
||||
if (isReadable(position)) {
|
||||
return delegate.getCurrentDifficultyAt(position);
|
||||
}
|
||||
return delegate.getCurrentDifficultyAt(generationCenter.getMiddleBlockPosition(
|
||||
Mth.clamp(position.getY(), getMinY(), getMaxY() - 1)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long nextSubTickCount() {
|
||||
return delegate.nextSubTickCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LevelTickAccess<Block> getBlockTicks() {
|
||||
return blockTicks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LevelTickAccess<Fluid> getFluidTicks() {
|
||||
return fluidTicks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LevelData getLevelData() {
|
||||
return delegate.getLevelData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MinecraftServer getServer() {
|
||||
return delegate.getServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkSource getChunkSource() {
|
||||
return delegate.getChunkSource();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RandomSource getRandom() {
|
||||
return delegate.getRandom();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateNeighborsAt(BlockPos position, Block block) {
|
||||
if (isWritableNeighbourhood(position)) {
|
||||
delegate.updateNeighborsAt(position, block);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void neighborShapeChanged(Direction direction, BlockPos position,
|
||||
BlockPos neighbourPosition, BlockState neighbourState,
|
||||
int updateFlags, int updateLimit) {
|
||||
if (isWritable(position) && isWritable(neighbourPosition)) {
|
||||
delegate.neighborShapeChanged(
|
||||
direction, position, neighbourPosition, neighbourState, updateFlags, updateLimit);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(Entity source, BlockPos position, SoundEvent sound,
|
||||
SoundSource soundSource, float volume, float pitch) {
|
||||
if (isWritable(position)) {
|
||||
delegate.playSound(source, position, sound, soundSource, volume, pitch);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addParticle(ParticleOptions particle, double x, double y, double z,
|
||||
double velocityX, double velocityY, double velocityZ) {
|
||||
if (isWritable(BlockPos.containing(x, y, z))) {
|
||||
delegate.addParticle(particle, x, y, z, velocityX, velocityY, velocityZ);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void levelEvent(Entity source, int eventId, BlockPos position, int data) {
|
||||
if (isWritable(position)) {
|
||||
delegate.levelEvent(source, eventId, position, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gameEvent(Holder<GameEvent> event, Vec3 position, GameEvent.Context context) {
|
||||
if (isWritable(BlockPos.containing(position))) {
|
||||
delegate.gameEvent(event, position, context);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkAccess getChunk(int chunkX, int chunkZ) {
|
||||
if (isInsideGenerationRegion(chunkX, chunkZ)) {
|
||||
return delegate.getChunk(chunkX, chunkZ);
|
||||
}
|
||||
return outsideChunk(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkAccess getChunk(int chunkX, int chunkZ, ChunkStatus status, boolean create) {
|
||||
if (isInsideGenerationRegion(chunkX, chunkZ)) {
|
||||
return delegate.getChunk(chunkX, chunkZ, status, create);
|
||||
}
|
||||
return create ? outsideChunk(chunkX, chunkZ) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasChunk(int chunkX, int chunkZ) {
|
||||
return isInsideGenerationRegion(chunkX, chunkZ) && delegate.hasChunk(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight(Heightmap.Types type, int x, int z) {
|
||||
if (isInsideGenerationRegion(x >> 4, z >> 4)) {
|
||||
return delegate.getHeight(type, x, z);
|
||||
}
|
||||
return height(type, x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSkyDarken() {
|
||||
return delegate.getSkyDarken();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeManager getBiomeManager() {
|
||||
return biomeManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Holder<Biome> getNoiseBiome(int quartX, int quartY, int quartZ) {
|
||||
return getUncachedNoiseBiome(quartX, quartY, quartZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Holder<Biome> getUncachedNoiseBiome(int quartX, int quartY, int quartZ) {
|
||||
if (isInsideGenerationRegion(QuartPos.toSection(quartX), QuartPos.toSection(quartZ))) {
|
||||
return delegate.getUncachedNoiseBiome(quartX, quartY, quartZ);
|
||||
}
|
||||
return fallbackBiome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClientSide() {
|
||||
return delegate.isClientSide();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSeaLevel() {
|
||||
return delegate.getSeaLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DimensionType dimensionType() {
|
||||
return delegate.dimensionType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinY() {
|
||||
return delegate.getMinY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return delegate.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegistryAccess registryAccess() {
|
||||
return delegate.registryAccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureFlagSet enabledFeatures() {
|
||||
return delegate.enabledFeatures();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnvironmentAttributeReader environmentAttributes() {
|
||||
return delegate.environmentAttributes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LevelLightEngine getLightEngine() {
|
||||
return delegate.getLightEngine();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBrightness(LightLayer layer, BlockPos position) {
|
||||
if (isReadable(position)) {
|
||||
return delegate.getBrightness(layer, position);
|
||||
}
|
||||
return layer == LightLayer.SKY && canSeeSky(position) ? 15 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRawBrightness(BlockPos position, int ambientDarkening) {
|
||||
if (isReadable(position)) {
|
||||
return delegate.getRawBrightness(position, ambientDarkening);
|
||||
}
|
||||
return Math.max(0, getBrightness(LightLayer.SKY, position) - ambientDarkening);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSeeSky(BlockPos position) {
|
||||
if (isReadable(position)) {
|
||||
return delegate.canSeeSky(position);
|
||||
}
|
||||
return position.getY() >= height(Heightmap.Types.WORLD_SURFACE_WG, position.getX(), position.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldBorder getWorldBorder() {
|
||||
return delegate.getWorldBorder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockGetter getChunkForCollisions(int chunkX, int chunkZ) {
|
||||
if (isInsideGenerationRegion(chunkX, chunkZ)) {
|
||||
return delegate.getChunkForCollisions(chunkX, chunkZ);
|
||||
}
|
||||
return outsideChunk(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntity getBlockEntity(BlockPos position) {
|
||||
return isReadable(position) ? delegate.getBlockEntity(position) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends BlockEntity> Optional<T> getBlockEntity(
|
||||
BlockPos position, BlockEntityType<T> type) {
|
||||
return isReadable(position) ? delegate.getBlockEntity(position, type) : Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlockState(BlockPos position) {
|
||||
return isReadable(position) ? delegate.getBlockState(position) : terrainState(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidState getFluidState(BlockPos position) {
|
||||
return isReadable(position) ? delegate.getFluidState(position) : terrainState(position).getFluidState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Entity> getEntities(Entity source, AABB area, Predicate<? super Entity> predicate) {
|
||||
AABB boundedArea = boundedArea(area);
|
||||
return boundedArea == null ? List.of() : delegate.getEntities(source, boundedArea, predicate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Entity> List<T> getEntities(
|
||||
EntityTypeTest<Entity, T> type,
|
||||
AABB area, Predicate<? super T> predicate) {
|
||||
AABB boundedArea = boundedArea(area);
|
||||
return boundedArea == null ? List.of() : delegate.getEntities(type, boundedArea, predicate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Player> players() {
|
||||
return delegate.players();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStateAtPosition(BlockPos position, Predicate<BlockState> predicate) {
|
||||
return predicate.test(getBlockState(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFluidAtPosition(BlockPos position, Predicate<FluidState> predicate) {
|
||||
return predicate.test(getFluidState(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getHeightmapPos(Heightmap.Types type, BlockPos position) {
|
||||
return position.atY(getHeight(type, position.getX(), position.getZ()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(BlockPos position, BlockState state, int updateFlags, int updateLimit) {
|
||||
return isWritable(position) && delegate.setBlock(position, state, updateFlags, updateLimit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeBlock(BlockPos position, boolean move) {
|
||||
return isWritable(position) && delegate.removeBlock(position, move);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean destroyBlock(BlockPos position, boolean drop, Entity source, int updateLimit) {
|
||||
return isWritable(position) && delegate.destroyBlock(position, drop, source, updateLimit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addFreshEntity(Entity entity) {
|
||||
return isWritable(entity.blockPosition()) && delegate.addFreshEntity(entity);
|
||||
}
|
||||
|
||||
|
||||
private boolean isReadable(BlockPos position) {
|
||||
return isInsideGenerationRegion(position.getX() >> 4, position.getZ() >> 4)
|
||||
&& !isOutsideBuildHeight(position);
|
||||
}
|
||||
|
||||
private boolean isWritable(BlockPos position) {
|
||||
return isReadable(position);
|
||||
}
|
||||
|
||||
private boolean isWritableNeighbourhood(BlockPos position) {
|
||||
return isWritable(position)
|
||||
&& isWritable(position.north())
|
||||
&& isWritable(position.south())
|
||||
&& isWritable(position.east())
|
||||
&& isWritable(position.west())
|
||||
&& isWritable(position.above())
|
||||
&& isWritable(position.below());
|
||||
}
|
||||
|
||||
private AABB boundedArea(AABB area) {
|
||||
double minX = Math.max(area.minX, generationBounds.minX);
|
||||
double minY = Math.max(area.minY, generationBounds.minY);
|
||||
double minZ = Math.max(area.minZ, generationBounds.minZ);
|
||||
double maxX = Math.min(area.maxX, generationBounds.maxX);
|
||||
double maxY = Math.min(area.maxY, generationBounds.maxY);
|
||||
double maxZ = Math.min(area.maxZ, generationBounds.maxZ);
|
||||
if (minX >= maxX || minY >= maxY || minZ >= maxZ) {
|
||||
return null;
|
||||
}
|
||||
if (minX == area.minX && minY == area.minY && minZ == area.minZ
|
||||
&& maxX == area.maxX && maxY == area.maxY && maxZ == area.maxZ) {
|
||||
return area;
|
||||
}
|
||||
return new AABB(minX, minY, minZ, maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
boolean isInsideGenerationRegion(int chunkX, int chunkZ) {
|
||||
return Math.abs(chunkX - generationCenter.x()) <= WRITE_RADIUS
|
||||
&& Math.abs(chunkZ - generationCenter.z()) <= WRITE_RADIUS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOutsideBuildHeight(BlockPos position) {
|
||||
return position.getY() < getMinY() || position.getY() >= getMaxY();
|
||||
}
|
||||
|
||||
private BlockState terrainState(BlockPos position) {
|
||||
if (isOutsideBuildHeight(position)) {
|
||||
return Blocks.VOID_AIR.defaultBlockState();
|
||||
}
|
||||
long heights = heights(position.getX(), position.getZ());
|
||||
int surface = (int) (heights >> 32);
|
||||
int floor = (int) heights;
|
||||
if (position.getY() < floor) {
|
||||
return Blocks.STONE.defaultBlockState();
|
||||
}
|
||||
if (position.getY() < surface) {
|
||||
return Blocks.WATER.defaultBlockState();
|
||||
}
|
||||
return Blocks.AIR.defaultBlockState();
|
||||
}
|
||||
|
||||
private int height(Heightmap.Types type, int x, int z) {
|
||||
long heights = heights(x, z);
|
||||
if (type == Heightmap.Types.OCEAN_FLOOR || type == Heightmap.Types.OCEAN_FLOOR_WG) {
|
||||
return (int) heights;
|
||||
}
|
||||
return (int) (heights >> 32);
|
||||
}
|
||||
|
||||
private long heights(int x, int z) {
|
||||
long key = ((long) x << 32) ^ (z & 0xffffffffL);
|
||||
long cached = terrainHeights.get(key);
|
||||
if (cached != Long.MIN_VALUE) {
|
||||
return cached;
|
||||
}
|
||||
int floor = Mth.clamp(floorFirstFreeY.applyAsInt(x, z), getMinY(), getMaxY());
|
||||
int surface = Mth.clamp(surfaceFirstFreeY.applyAsInt(x, z), floor, getMaxY());
|
||||
long heights = ((long) surface << 32) | (floor & 0xffffffffL);
|
||||
terrainHeights.put(key, heights);
|
||||
return heights;
|
||||
}
|
||||
|
||||
private ChunkAccess outsideChunk(int chunkX, int chunkZ) {
|
||||
long key = ChunkPos.pack(chunkX, chunkZ);
|
||||
ChunkAccess cached = outsideChunks.get(key);
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
EmptyLevelChunk chunk = new EmptyLevelChunk(getLevel(), new ChunkPos(chunkX, chunkZ), fallbackBiome);
|
||||
WorldgenTerrainHeightmaps.primeTerrain(chunk, surfaceFirstFreeY, floorFirstFreeY);
|
||||
outsideChunks.put(key, chunk);
|
||||
return chunk;
|
||||
}
|
||||
|
||||
private record Boundary(ChunkPos generationCenter,
|
||||
IntBinaryOperator surfaceFirstFreeY,
|
||||
IntBinaryOperator floorFirstFreeY) {
|
||||
}
|
||||
|
||||
private static final class BoundedTickAccess<T> implements LevelTickAccess<T> {
|
||||
private final LevelTickAccess<T> delegate;
|
||||
private final Predicate<BlockPos> writable;
|
||||
|
||||
private BoundedTickAccess(LevelTickAccess<T> delegate, Predicate<BlockPos> writable) {
|
||||
this.delegate = delegate;
|
||||
this.writable = writable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void schedule(ScheduledTick<T> tick) {
|
||||
if (writable.test(tick.pos())) {
|
||||
delegate.schedule(tick);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasScheduledTick(BlockPos position, T type) {
|
||||
return writable.test(position) && delegate.hasScheduledTick(position, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count() {
|
||||
return delegate.count();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean willTickThisTick(BlockPos position, T type) {
|
||||
return writable.test(position) && delegate.willTickThisTick(position, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-7
@@ -344,7 +344,7 @@ public final class IrisModdedCommands {
|
||||
|
||||
execution = new PackDownloadExecution(
|
||||
lease,
|
||||
cancellation -> executeDownload(source, request, target, downloadSource, scheduler, cancellation)
|
||||
cancellation -> executeDownload(source, request, target, downloadSource, cancellation)
|
||||
);
|
||||
PackDownloadExecution trackedExecution = execution;
|
||||
execution.onCompletion(() -> clearActiveDownload(trackedExecution));
|
||||
@@ -384,7 +384,6 @@ public final class IrisModdedCommands {
|
||||
DownloadRequest request,
|
||||
String target,
|
||||
String downloadSource,
|
||||
ModdedScheduler scheduler,
|
||||
PackDownloader.DownloadCancellation cancellation
|
||||
) throws PackDownloader.PackDownloadCancelledException {
|
||||
File packs = ModdedPackCommands.packsRoot();
|
||||
@@ -394,37 +393,41 @@ public final class IrisModdedCommands {
|
||||
packs,
|
||||
request.url(),
|
||||
false,
|
||||
(String message) -> scheduler.global(() -> ok(source, message)),
|
||||
(String message) -> dispatchDownloadFeedback(source, () -> ok(source, message)),
|
||||
cancellation
|
||||
)
|
||||
: PackDownloader.downloadBuiltIn(
|
||||
packs,
|
||||
request.pack(),
|
||||
false,
|
||||
(String message) -> scheduler.global(() -> ok(source, message)),
|
||||
(String message) -> dispatchDownloadFeedback(source, () -> ok(source, message)),
|
||||
cancellation
|
||||
);
|
||||
String completionMessage = downloadCompletionMessage(result);
|
||||
if (result != null) {
|
||||
if (completionMessage != null) {
|
||||
scheduler.global(() -> ok(source, completionMessage));
|
||||
dispatchDownloadFeedback(source, () -> ok(source, completionMessage));
|
||||
}
|
||||
return;
|
||||
}
|
||||
} catch (PackDownloader.PackDownloadCancelledException error) {
|
||||
throw error;
|
||||
} catch (PackDownloader.PackDownloadBusyException error) {
|
||||
scheduler.global(() -> fail(source, error.getMessage()));
|
||||
dispatchDownloadFeedback(source, () -> fail(source, error.getMessage()));
|
||||
return;
|
||||
} catch (IOException | RuntimeException error) {
|
||||
LOGGER.error("Iris pack download failed for {}", target, error);
|
||||
}
|
||||
scheduler.global(() -> fail(source, IrisLanguage.plain(
|
||||
dispatchDownloadFeedback(source, () -> fail(source, IrisLanguage.plain(
|
||||
ModdedCommandMessages.IRIS_MODDED_COMMANDS_PACK_DOWNLOAD_FAILED_SEE_CONSOLE,
|
||||
MessageArgument.untrusted("pack", target),
|
||||
MessageArgument.untrusted("downloadSource", downloadSource))));
|
||||
}
|
||||
|
||||
private static void dispatchDownloadFeedback(CommandSourceStack source, Runnable feedback) {
|
||||
source.getServer().execute(feedback);
|
||||
}
|
||||
|
||||
static String downloadBusyMessage(LifecycleOperationCoordinator.ActiveOperation operation) {
|
||||
if (operation.domain() == LifecycleOperationCoordinator.Domain.PACK_MUTATION
|
||||
&& operation.kind() == LifecycleOperationCoordinator.OperationKind.PACK_DOWNLOAD) {
|
||||
|
||||
+8
-1
@@ -51,7 +51,14 @@ final class ModdedPregenCommands {
|
||||
return 0;
|
||||
}
|
||||
boolean showGui = gui && ModdedGuiHost.isGuiLaunchable();
|
||||
if (!ModdedPregenJob.start(source.getServer(), level, engine, radius, centerX, centerZ, showGui, sync, !nocache)) {
|
||||
boolean started;
|
||||
try {
|
||||
started = ModdedPregenJob.start(source.getServer(), level, engine, radius, centerX, centerZ, showGui, sync, !nocache);
|
||||
} catch (IllegalArgumentException failure) {
|
||||
IrisModdedCommands.fail(source, failure.getMessage());
|
||||
return 0;
|
||||
}
|
||||
if (!started) {
|
||||
IrisModdedCommands.fail(source, IrisLanguage.plain(ModdedCommandMessages.IRIS_MODDED_COMMANDS_PREGENERATION_TASK_IS_ALREADY_RUNNING_STOP_IT_FIRST_WITH_IRIS));
|
||||
return 0;
|
||||
}
|
||||
|
||||
+1
-1
@@ -55,13 +55,13 @@ public final class ModdedPregenJob {
|
||||
return false;
|
||||
}
|
||||
|
||||
PregenPerformanceProfile.apply(engine);
|
||||
PregenTask task = PregenTask.builder()
|
||||
.gui(gui)
|
||||
.center(new Position2(centerBlockX, centerBlockZ))
|
||||
.radiusX(radiusBlocks)
|
||||
.radiusZ(radiusBlocks)
|
||||
.build();
|
||||
PregenPerformanceProfile.apply(engine);
|
||||
ModdedPregenMethod moddedMethod = new ModdedPregenMethod(level, engine, sync);
|
||||
PregeneratorMethod method = moddedMethod;
|
||||
if (cached) {
|
||||
|
||||
+12
-2
@@ -73,6 +73,7 @@ public final class ModdedPregenMethod implements PregeneratorMethod {
|
||||
private final AtomicBoolean finalSaveCompleted = new AtomicBoolean(false);
|
||||
private final AtomicReference<FinalSaveRequest> queuedFinalSave = new AtomicReference<>();
|
||||
private final AtomicBoolean stallHintLogged = new AtomicBoolean(false);
|
||||
private final AtomicBoolean failureDetailLogged = new AtomicBoolean(false);
|
||||
private final int timeoutSeconds;
|
||||
private final PregenMantleBackpressure backpressure;
|
||||
private final PauseWhenEmptyGuard pauseGuard;
|
||||
@@ -350,7 +351,7 @@ public final class ModdedPregenMethod implements PregeneratorMethod {
|
||||
if (e instanceof TimeoutException) {
|
||||
noteStallHint();
|
||||
}
|
||||
LOGGER.warn("Iris pregen chunk {},{} failed: {}", x, z, e.toString());
|
||||
logChunkFailure(x, z, e);
|
||||
listener.onChunkFailed(x, z);
|
||||
} finally {
|
||||
markFinished();
|
||||
@@ -395,7 +396,7 @@ public final class ModdedPregenMethod implements PregeneratorMethod {
|
||||
if (unwrap(error) instanceof TimeoutException) {
|
||||
onTimeout();
|
||||
}
|
||||
LOGGER.warn("Iris pregen chunk {},{} failed: {}", x, z, error.toString());
|
||||
logChunkFailure(x, z, error);
|
||||
listener.onChunkFailed(x, z);
|
||||
return;
|
||||
}
|
||||
@@ -421,6 +422,15 @@ public final class ModdedPregenMethod implements PregeneratorMethod {
|
||||
inFlightPeak.accumulateAndGet(current, Math::max);
|
||||
}
|
||||
|
||||
private void logChunkFailure(int x, int z, Throwable failure) {
|
||||
Throwable cause = unwrap(failure);
|
||||
if (failureDetailLogged.compareAndSet(false, true)) {
|
||||
LOGGER.warn("Iris pregen chunk {},{} failed; first failure follows", x, z, cause);
|
||||
return;
|
||||
}
|
||||
LOGGER.warn("Iris pregen chunk {},{} failed: {}", x, z, cause.toString());
|
||||
}
|
||||
|
||||
private void markFinished() {
|
||||
inFlight.decrementAndGet();
|
||||
if (sync) {
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package art.arcane.iris.modded.mixin;
|
||||
|
||||
import art.arcane.iris.modded.ModdedMixinFlags;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Mutable;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Mixin(StructureTemplate.Palette.class)
|
||||
public abstract class StructureTemplatePaletteConcurrencyMixin {
|
||||
@Shadow
|
||||
@Final
|
||||
@Mutable
|
||||
private Map<Block, List<StructureTemplate.StructureBlockInfo>> cache;
|
||||
|
||||
@Inject(method = "<init>(Ljava/util/List;)V", at = @At("RETURN"))
|
||||
private void iris$installConcurrentBlockCache(List<StructureTemplate.StructureBlockInfo> blocks,
|
||||
CallbackInfo info) {
|
||||
cache = new ConcurrentHashMap<>();
|
||||
ModdedMixinFlags.markStructureTemplatePalette();
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,8 @@
|
||||
"mixins": [
|
||||
"EntityPersistenceMixin",
|
||||
"LivingEntityLootMixin",
|
||||
"MobAwarenessMixin"
|
||||
"MobAwarenessMixin",
|
||||
"StructureTemplatePaletteConcurrencyMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
||||
+33
@@ -102,7 +102,12 @@ public class ModdedGenerationLeaseContractTest {
|
||||
String execution = method(source, "private static void executeDownload(");
|
||||
assertTrue(execution.contains("PackDownloader.DownloadCancellation cancellation"));
|
||||
assertTrue(execution.contains("catch (PackDownloader.PackDownloadCancelledException error)"));
|
||||
assertTrue(execution.contains("dispatchDownloadFeedback(source,"));
|
||||
assertFalse(execution.contains("scheduler.global("));
|
||||
assertFalse(execution.contains("lease.close();"));
|
||||
|
||||
String feedback = method(source, "private static void dispatchDownloadFeedback(");
|
||||
assertTrue(feedback.contains("source.getServer().execute(feedback);"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -170,6 +175,34 @@ public class ModdedGenerationLeaseContractTest {
|
||||
assertTrue(pending.contains("queuedFinalSave.get() != null"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void firstPregenChunkFailureRetainsItsFullCause() throws IOException {
|
||||
String methodSource = source("art/arcane/iris/modded/command/ModdedPregenMethod.java");
|
||||
String logFailure = method(methodSource, "private void logChunkFailure(");
|
||||
|
||||
assertTrue(methodSource.contains("AtomicBoolean failureDetailLogged"));
|
||||
assertTrue(logFailure.contains("unwrap(failure)"));
|
||||
assertTrue(logFailure.contains("failureDetailLogged.compareAndSet(false, true)"));
|
||||
assertTrue(logFailure.contains("x, z, cause);"));
|
||||
assertTrue(logFailure.contains("cause.toString()"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidPregenBoundsFailBeforeRuntimeMutation() throws IOException {
|
||||
String jobSource = source("art/arcane/iris/modded/command/ModdedPregenJob.java");
|
||||
String start = method(jobSource, "public static boolean start(");
|
||||
int taskConstruction = start.indexOf("PregenTask task = PregenTask.builder()");
|
||||
int profileMutation = start.indexOf("PregenPerformanceProfile.apply(engine);");
|
||||
|
||||
assertTrue(taskConstruction >= 0);
|
||||
assertTrue(profileMutation > taskConstruction);
|
||||
|
||||
String commandSource = source("art/arcane/iris/modded/command/ModdedPregenCommands.java");
|
||||
String command = method(commandSource, "static int pregenStart(");
|
||||
assertTrue(command.contains("catch (IllegalArgumentException failure)"));
|
||||
assertTrue(command.contains("IrisModdedCommands.fail(source, failure.getMessage())"));
|
||||
}
|
||||
|
||||
private static String source(String relativePath) throws IOException {
|
||||
String root = System.getProperty(SOURCE_ROOT_PROPERTY);
|
||||
assertTrue("Missing system property " + SOURCE_ROOT_PROPERTY, root != null && !root.isBlank());
|
||||
|
||||
+169
@@ -0,0 +1,169 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.IdMapper;
|
||||
import net.minecraft.server.Bootstrap;
|
||||
import net.minecraft.world.entity.ai.village.poi.PoiSection;
|
||||
import net.minecraft.world.entity.ai.village.poi.PoiType;
|
||||
import net.minecraft.world.entity.ai.village.poi.PoiTypes;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.LevelHeightAccessor;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeGenerationSettings;
|
||||
import net.minecraft.world.level.biome.BiomeSpecialEffects;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.PalettedContainer;
|
||||
import net.minecraft.world.level.chunk.PalettedContainerFactory;
|
||||
import net.minecraft.world.level.chunk.PalettedContainerRO;
|
||||
import net.minecraft.world.level.chunk.ProtoChunk;
|
||||
import net.minecraft.world.level.chunk.Strategy;
|
||||
import net.minecraft.world.level.chunk.UpgradeData;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ModdedNativeStructurePoiRegistrationTest {
|
||||
@BeforeClass
|
||||
public static void bootstrapMinecraftRegistries() {
|
||||
SharedConstants.tryDetectVersion();
|
||||
Bootstrap.bootStrap();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void visitsOnlyExistingPoiBlocksBeforeNativePlacement() {
|
||||
ProtoChunk chunk = newChunk();
|
||||
BlockPos poiPosition = new BlockPos(3, 70, 5);
|
||||
BlockPos ordinaryPosition = new BlockPos(4, 70, 5);
|
||||
BlockState poiState = Blocks.BARREL.defaultBlockState();
|
||||
chunk.setBlockState(poiPosition, poiState, 0);
|
||||
chunk.setBlockState(ordinaryPosition, Blocks.STONE.defaultBlockState(), 0);
|
||||
Map<BlockPos, BlockState> visited = new LinkedHashMap<>();
|
||||
|
||||
ModdedNativeStructureStage.visitExistingPois(
|
||||
chunk, (position, state) -> visited.put(position.immutable(), state));
|
||||
|
||||
assertEquals(poiState, visited.get(poiPosition));
|
||||
assertFalse(visited.containsKey(ordinaryPosition));
|
||||
assertEquals(1, visited.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void duplicatePrimingIsIdempotentForAnAlreadyRegisteredPoi() {
|
||||
BlockPos position = new BlockPos(3, 70, 5);
|
||||
Holder<PoiType> type = PoiTypes.forState(
|
||||
Blocks.BARREL.defaultBlockState()).orElseThrow();
|
||||
PoiSection section = new PoiSection(() -> { });
|
||||
|
||||
assertNotNull(section.add(position, type));
|
||||
assertNull(section.add(position, type));
|
||||
assertEquals(type, section.getType(position).orElseThrow());
|
||||
|
||||
section.remove(position);
|
||||
|
||||
assertTrue(section.getType(position).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void worldgenPrimingQueuesBeforeTheLaterVanillaRemoval() {
|
||||
ProtoChunk chunk = newChunk();
|
||||
BlockPos position = new BlockPos(3, 70, 5);
|
||||
BlockState poiState = Blocks.BARREL.defaultBlockState();
|
||||
chunk.setBlockState(position, poiState, 0);
|
||||
PoiSection section = new PoiSection(() -> { });
|
||||
Deque<Runnable> serverQueue = new ArrayDeque<>();
|
||||
AtomicInteger missingRemovals = new AtomicInteger();
|
||||
|
||||
ModdedNativeStructureStage.visitExistingPois(chunk,
|
||||
(poiPosition, state) -> queuePoiTransition(
|
||||
serverQueue, section, poiPosition,
|
||||
Blocks.AIR.defaultBlockState(), state, missingRemovals));
|
||||
assertTrue(section.getType(position).isEmpty());
|
||||
queuePoiTransition(serverQueue, section, position,
|
||||
poiState, Blocks.AIR.defaultBlockState(), missingRemovals);
|
||||
|
||||
while (!serverQueue.isEmpty()) {
|
||||
serverQueue.removeFirst().run();
|
||||
}
|
||||
|
||||
assertEquals(0, missingRemovals.get());
|
||||
assertTrue(section.getType(position).isEmpty());
|
||||
}
|
||||
|
||||
private static void queuePoiTransition(Deque<Runnable> serverQueue,
|
||||
PoiSection section,
|
||||
BlockPos position,
|
||||
BlockState oldState,
|
||||
BlockState newState,
|
||||
AtomicInteger missingRemovals) {
|
||||
Optional<Holder<PoiType>> oldType = PoiTypes.forState(oldState);
|
||||
Optional<Holder<PoiType>> newType = PoiTypes.forState(newState);
|
||||
if (Objects.equals(oldType, newType)) {
|
||||
return;
|
||||
}
|
||||
BlockPos immutablePosition = position.immutable();
|
||||
oldType.ifPresent(type -> serverQueue.addLast(() -> {
|
||||
if (section.getType(immutablePosition).isEmpty()) {
|
||||
missingRemovals.incrementAndGet();
|
||||
return;
|
||||
}
|
||||
section.remove(immutablePosition);
|
||||
}));
|
||||
newType.ifPresent(type -> serverQueue.addLast(
|
||||
() -> section.add(immutablePosition, type)));
|
||||
}
|
||||
|
||||
private static ProtoChunk newChunk() {
|
||||
return new ProtoChunk(
|
||||
new ChunkPos(0, 0),
|
||||
UpgradeData.EMPTY,
|
||||
LevelHeightAccessor.create(-64, 384),
|
||||
palettedContainerFactory(),
|
||||
null);
|
||||
}
|
||||
|
||||
private static PalettedContainerFactory palettedContainerFactory() {
|
||||
Strategy<BlockState> blockStrategy = Strategy.createForBlockStates(Block.BLOCK_STATE_REGISTRY);
|
||||
Codec<PalettedContainer<BlockState>> blockCodec = PalettedContainer.codecRW(
|
||||
BlockState.CODEC, blockStrategy, Blocks.AIR.defaultBlockState());
|
||||
Biome biome = new Biome.BiomeBuilder()
|
||||
.hasPrecipitation(false)
|
||||
.temperature(0.8F)
|
||||
.downfall(0.4F)
|
||||
.specialEffects(new BiomeSpecialEffects.Builder().waterColor(0x3F76E4).build())
|
||||
.mobSpawnSettings(MobSpawnSettings.EMPTY)
|
||||
.generationSettings(BiomeGenerationSettings.EMPTY)
|
||||
.build();
|
||||
Holder<Biome> biomeHolder = Holder.direct(biome);
|
||||
IdMapper<Holder<Biome>> biomeIds = new IdMapper<>(1);
|
||||
biomeIds.add(biomeHolder);
|
||||
Strategy<Holder<Biome>> biomeStrategy = Strategy.createForBiomes(biomeIds);
|
||||
Codec<PalettedContainerRO<Holder<Biome>>> biomeCodec = PalettedContainer.codecRO(
|
||||
Biome.CODEC, biomeStrategy, biomeHolder);
|
||||
return new PalettedContainerFactory(
|
||||
blockStrategy,
|
||||
Blocks.AIR.defaultBlockState(),
|
||||
blockCodec,
|
||||
biomeStrategy,
|
||||
biomeHolder,
|
||||
biomeCodec);
|
||||
}
|
||||
}
|
||||
+323
@@ -0,0 +1,323 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.server.Bootstrap;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.WorldGenLevel;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeManager;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.status.ChunkStatus;
|
||||
import net.minecraft.world.level.entity.EntityTypeTest;
|
||||
import net.minecraft.world.level.levelgen.Heightmap;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.world.ticks.LevelTickAccess;
|
||||
import net.minecraft.world.ticks.ScheduledTick;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ModdedNativeStructureWorldgenAccessTest {
|
||||
private static final int GENERATION_CENTER_X = 60;
|
||||
private static final int GENERATION_CENTER_Z = 15;
|
||||
private static final int SURFACE_FIRST_FREE_Y = 80;
|
||||
private static final int FLOOR_FIRST_FREE_Y = 70;
|
||||
|
||||
@BeforeClass
|
||||
public static void bootstrapMinecraftRegistries() {
|
||||
SharedConstants.tryDetectVersion();
|
||||
Bootstrap.bootStrap();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceTwoTerrainReadsNeverReachTheDelegate() {
|
||||
RecordingDelegate recording = new RecordingDelegate();
|
||||
ModdedNativeStructureWorldgenAccess access = access(recording);
|
||||
ChunkPos generationCenter = generationCenter();
|
||||
int x = generationCenter.getMiddleBlockX();
|
||||
int z = (generationCenter.z() + 2) << 4;
|
||||
|
||||
assertSame(Blocks.STONE, access.getBlockState(new BlockPos(x, FLOOR_FIRST_FREE_Y - 1, z)).getBlock());
|
||||
assertSame(Blocks.WATER, access.getBlockState(new BlockPos(x, FLOOR_FIRST_FREE_Y, z)).getBlock());
|
||||
assertSame(Blocks.AIR, access.getBlockState(new BlockPos(x, SURFACE_FIRST_FREE_Y, z)).getBlock());
|
||||
assertSame(Blocks.WATER.defaultBlockState().getFluidState(),
|
||||
access.getFluidState(new BlockPos(x, FLOOR_FIRST_FREE_Y, z)));
|
||||
assertEquals(SURFACE_FIRST_FREE_Y, access.getHeight(Heightmap.Types.WORLD_SURFACE_WG, x, z));
|
||||
assertEquals(FLOOR_FIRST_FREE_Y, access.getHeight(Heightmap.Types.OCEAN_FLOOR_WG, x, z));
|
||||
assertNull(access.getChunk(generationCenter.x(), generationCenter.z() + 2, ChunkStatus.FEATURES, false));
|
||||
List<BlockState> loadedOnly = access.getBlockStatesIfLoaded(new AABB(
|
||||
x, FLOOR_FIRST_FREE_Y, z, x, FLOOR_FIRST_FREE_Y, z)).toList();
|
||||
List<BlockState> streamed = access.getBlockStates(new AABB(
|
||||
x, FLOOR_FIRST_FREE_Y, z, x, FLOOR_FIRST_FREE_Y, z)).toList();
|
||||
|
||||
assertTrue(loadedOnly.isEmpty());
|
||||
assertEquals(1, streamed.size());
|
||||
assertSame(Blocks.WATER, streamed.getFirst().getBlock());
|
||||
assertEquals(0, recording.terrainReads);
|
||||
assertEquals(0, recording.heightReads);
|
||||
assertEquals(0, recording.chunkReads);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceTwoMutationsAndSideEffectsNeverReachTheDelegate() {
|
||||
RecordingDelegate recording = new RecordingDelegate();
|
||||
ModdedNativeStructureWorldgenAccess access = access(recording);
|
||||
ChunkPos generationCenter = generationCenter();
|
||||
BlockPos position = new BlockPos(
|
||||
generationCenter.getMiddleBlockX(),
|
||||
FLOOR_FIRST_FREE_Y,
|
||||
(generationCenter.z() + 2) << 4);
|
||||
|
||||
assertFalse(access.ensureCanWrite(position));
|
||||
assertFalse(access.setBlock(position, Blocks.DIRT.defaultBlockState(), 2));
|
||||
assertFalse(access.removeBlock(position, false));
|
||||
assertFalse(access.destroyBlock(position, false));
|
||||
access.updateNeighborsAt(position, Blocks.DIRT);
|
||||
access.neighborShapeChanged(
|
||||
Direction.NORTH, position, position.north(),
|
||||
Blocks.DIRT.defaultBlockState(), 2, 512);
|
||||
access.levelEvent(null, 2001, position, 0);
|
||||
access.gameEvent(null, Vec3.atCenterOf(position), null);
|
||||
access.addParticle(null, position.getX(), position.getY(), position.getZ(), 0, 0, 0);
|
||||
access.getBlockTicks().schedule(new ScheduledTick<>(
|
||||
Blocks.DIRT, position, 1L, 0L));
|
||||
|
||||
assertEquals(0, recording.mutations);
|
||||
assertEquals(0, recording.events);
|
||||
assertEquals(0, recording.blockTicks.count());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void radiusOneReadsWritesAndTicksRemainUnchanged() {
|
||||
RecordingDelegate recording = new RecordingDelegate();
|
||||
ModdedNativeStructureWorldgenAccess access = access(recording);
|
||||
ChunkPos generationCenter = generationCenter();
|
||||
BlockPos position = new BlockPos(
|
||||
(generationCenter.x() + 1) << 4,
|
||||
FLOOR_FIRST_FREE_Y,
|
||||
(generationCenter.z() - 1) << 4);
|
||||
|
||||
assertTrue(access.isInsideGenerationRegion(
|
||||
generationCenter.x() + 1, generationCenter.z() - 1));
|
||||
assertSame(Blocks.DIRT, access.getBlockState(position).getBlock());
|
||||
assertEquals(91, access.getHeight(
|
||||
Heightmap.Types.WORLD_SURFACE_WG, position.getX(), position.getZ()));
|
||||
assertTrue(access.ensureCanWrite(position));
|
||||
assertTrue(access.setBlock(position, Blocks.STONE.defaultBlockState(), 2));
|
||||
assertTrue(access.removeBlock(position, false));
|
||||
assertTrue(access.destroyBlock(position, false));
|
||||
access.getBlockTicks().schedule(new ScheduledTick<>(
|
||||
Blocks.DIRT, position, 1L, 0L));
|
||||
|
||||
assertEquals(1, recording.terrainReads);
|
||||
assertEquals(1, recording.heightReads);
|
||||
assertEquals(4, recording.mutations);
|
||||
assertEquals(1, recording.blockTicks.count());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statuslessChunkReadsPreserveWorldgenDelegateSemantics() {
|
||||
RecordingDelegate recording = new RecordingDelegate();
|
||||
ModdedNativeStructureWorldgenAccess access = access(recording);
|
||||
ChunkPos generationCenter = generationCenter();
|
||||
|
||||
assertNull(access.getChunk(generationCenter.getWorldPosition()));
|
||||
|
||||
assertEquals(1, recording.statuslessChunkReads);
|
||||
assertEquals(0, recording.statusChunkReads);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void entityQueriesRejectDisjointAreasAndClampOverlaps() {
|
||||
RecordingDelegate recording = new RecordingDelegate();
|
||||
ModdedNativeStructureWorldgenAccess access = access(recording);
|
||||
ChunkPos generationCenter = generationCenter();
|
||||
int safeMaxX = generationCenter.getMaxBlockX() + 17;
|
||||
int safeMinZ = generationCenter.getMinBlockZ() - 16;
|
||||
int safeMaxZ = generationCenter.getMaxBlockZ() + 17;
|
||||
AABB disjoint = new AABB(
|
||||
safeMaxX, -64, safeMinZ,
|
||||
safeMaxX + 16, 320, safeMaxZ);
|
||||
AABB overlap = new AABB(
|
||||
safeMaxX - 8, -128, safeMinZ - 8,
|
||||
safeMaxX + 16, 400, safeMaxZ + 8);
|
||||
EntityTypeTest<Entity, Entity> type = EntityTypeTest.forClass(Entity.class);
|
||||
|
||||
assertTrue(access.getEntities((Entity) null, disjoint, entity -> true).isEmpty());
|
||||
assertTrue(access.getEntities(type, disjoint, entity -> true).isEmpty());
|
||||
access.getEntities((Entity) null, overlap, entity -> true);
|
||||
access.getEntities(type, overlap, entity -> true);
|
||||
|
||||
assertEquals(2, recording.entityAreas.size());
|
||||
for (AABB delegatedArea : recording.entityAreas) {
|
||||
assertEquals(safeMaxX - 8, delegatedArea.minX, 0D);
|
||||
assertEquals(-64, delegatedArea.minY, 0D);
|
||||
assertEquals(safeMinZ, delegatedArea.minZ, 0D);
|
||||
assertEquals(safeMaxX, delegatedArea.maxX, 0D);
|
||||
assertEquals(320, delegatedArea.maxY, 0D);
|
||||
assertEquals(safeMaxZ, delegatedArea.maxZ, 0D);
|
||||
}
|
||||
}
|
||||
|
||||
private static ModdedNativeStructureWorldgenAccess access(RecordingDelegate recording) {
|
||||
return ModdedNativeStructureWorldgenAccess.create(
|
||||
recording.world(), generationCenter(),
|
||||
(x, z) -> SURFACE_FIRST_FREE_Y,
|
||||
(x, z) -> FLOOR_FIRST_FREE_Y);
|
||||
}
|
||||
|
||||
private static ChunkPos generationCenter() {
|
||||
return new ChunkPos(GENERATION_CENTER_X, GENERATION_CENTER_Z);
|
||||
}
|
||||
|
||||
private static final class RecordingDelegate implements InvocationHandler {
|
||||
private final Holder<Biome> biome;
|
||||
private final BiomeManager biomeManager;
|
||||
private final RecordingTicks<Block> blockTicks;
|
||||
private final RecordingTicks<Fluid> fluidTicks;
|
||||
private final List<AABB> entityAreas;
|
||||
private int terrainReads;
|
||||
private int heightReads;
|
||||
private int chunkReads;
|
||||
private int statuslessChunkReads;
|
||||
private int statusChunkReads;
|
||||
private int mutations;
|
||||
private int events;
|
||||
|
||||
private RecordingDelegate() {
|
||||
this.biome = Holder.direct((Biome) null);
|
||||
this.biomeManager = new BiomeManager((x, y, z) -> biome, 13L);
|
||||
this.blockTicks = new RecordingTicks<>();
|
||||
this.fluidTicks = new RecordingTicks<>();
|
||||
this.entityAreas = new ArrayList<>();
|
||||
}
|
||||
|
||||
private WorldGenLevel world() {
|
||||
return (WorldGenLevel) Proxy.newProxyInstance(
|
||||
WorldGenLevel.class.getClassLoader(),
|
||||
new Class<?>[]{WorldGenLevel.class}, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object invoke(Object proxy, Method method, Object[] arguments) {
|
||||
String name = method.getName();
|
||||
if (name.equals("getSeaLevel")) {
|
||||
return 63;
|
||||
}
|
||||
if (name.equals("getBiome")) {
|
||||
return biome;
|
||||
}
|
||||
if (name.equals("getBiomeManager")) {
|
||||
return biomeManager;
|
||||
}
|
||||
if (name.equals("getBlockTicks")) {
|
||||
return blockTicks;
|
||||
}
|
||||
if (name.equals("getFluidTicks")) {
|
||||
return fluidTicks;
|
||||
}
|
||||
if (name.equals("getMinY")) {
|
||||
return -64;
|
||||
}
|
||||
if (name.equals("getHeight") && arguments == null) {
|
||||
return 384;
|
||||
}
|
||||
if (name.equals("getHeight")) {
|
||||
heightReads++;
|
||||
return 91;
|
||||
}
|
||||
if (name.equals("getBlockState")) {
|
||||
terrainReads++;
|
||||
return Blocks.DIRT.defaultBlockState();
|
||||
}
|
||||
if (name.equals("getFluidState")) {
|
||||
terrainReads++;
|
||||
return Blocks.WATER.defaultBlockState().getFluidState();
|
||||
}
|
||||
if (name.equals("getChunk")) {
|
||||
chunkReads++;
|
||||
if (arguments.length == 2) {
|
||||
statuslessChunkReads++;
|
||||
} else {
|
||||
statusChunkReads++;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (name.equals("getChunkIfLoadedImmediately")) {
|
||||
chunkReads++;
|
||||
return null;
|
||||
}
|
||||
if (name.equals("getEntities")) {
|
||||
entityAreas.add((AABB) arguments[1]);
|
||||
return List.of();
|
||||
}
|
||||
if (name.equals("ensureCanWrite") || name.equals("setBlock")
|
||||
|| name.equals("removeBlock") || name.equals("destroyBlock")) {
|
||||
mutations++;
|
||||
return true;
|
||||
}
|
||||
if (name.equals("updateNeighborsAt") || name.equals("neighborShapeChanged")) {
|
||||
mutations++;
|
||||
return null;
|
||||
}
|
||||
if (name.equals("levelEvent") || name.equals("gameEvent") || name.equals("addParticle")) {
|
||||
events++;
|
||||
return null;
|
||||
}
|
||||
if (name.equals("hashCode")) {
|
||||
return System.identityHashCode(proxy);
|
||||
}
|
||||
if (name.equals("equals")) {
|
||||
return proxy == arguments[0];
|
||||
}
|
||||
if (name.equals("toString")) {
|
||||
return "native-structure-worldgen-test-delegate";
|
||||
}
|
||||
throw new UnsupportedOperationException(method.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private static final class RecordingTicks<T> implements LevelTickAccess<T> {
|
||||
private int count;
|
||||
|
||||
@Override
|
||||
public void schedule(ScheduledTick<T> tick) {
|
||||
count++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasScheduledTick(BlockPos position, T type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count() {
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean willTickThisTick(BlockPos position, T type) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ModdedStructureTemplateCacheTest {
|
||||
@Test
|
||||
public void concurrentCacheOwnsDistinctAndSharedMappingsExactlyOnce() throws Exception {
|
||||
ConcurrentHashMap<String, Integer> cache = new ConcurrentHashMap<>();
|
||||
ExecutorService executor = Executors.newFixedThreadPool(32);
|
||||
CountDownLatch start = new CountDownLatch(1);
|
||||
AtomicInteger mappingCalls = new AtomicInteger();
|
||||
List<Future<Integer>> futures = new ArrayList<>();
|
||||
try {
|
||||
for (int task = 0; task < 256; task++) {
|
||||
int value = task;
|
||||
String key = task % 2 == 0 ? "shared" : "distinct-" + task;
|
||||
futures.add(executor.submit(() -> {
|
||||
start.await();
|
||||
return cache.computeIfAbsent(key, ignored -> {
|
||||
mappingCalls.incrementAndGet();
|
||||
Thread.yield();
|
||||
return value;
|
||||
});
|
||||
}));
|
||||
}
|
||||
start.countDown();
|
||||
for (Future<Integer> future : futures) {
|
||||
assertNotNull(future.get(10, TimeUnit.SECONDS));
|
||||
}
|
||||
} finally {
|
||||
executor.shutdownNow();
|
||||
assertTrue(executor.awaitTermination(10, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
assertEquals(129, cache.size());
|
||||
assertEquals(129, mappingCalls.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requiredCommonMixinConfigRegistersPaletteConcurrencyFix() throws Exception {
|
||||
InputStream resource = ModdedStructureTemplateCacheTest.class.getClassLoader()
|
||||
.getResourceAsStream("irisworldgen.entity.mixins.json");
|
||||
assertNotNull(resource);
|
||||
String config;
|
||||
try (InputStream input = resource) {
|
||||
config = new String(input.readAllBytes(), StandardCharsets.UTF_8);
|
||||
}
|
||||
assertTrue(config.contains("\"StructureTemplatePaletteConcurrencyMixin\""));
|
||||
|
||||
Path source = Path.of(System.getProperty("iris.moddedCommonSources"))
|
||||
.resolve("art/arcane/iris/modded/mixin/StructureTemplatePaletteConcurrencyMixin.java");
|
||||
String mixin = Files.readString(source);
|
||||
assertTrue(mixin.contains("@Mixin(StructureTemplate.Palette.class)"));
|
||||
assertTrue(mixin.contains("@Shadow\n @Final\n @Mutable"));
|
||||
assertTrue(mixin.contains("private Map<Block, List<StructureTemplate.StructureBlockInfo>> cache;"));
|
||||
assertTrue(mixin.contains("@Inject(method = \"<init>(Ljava/util/List;)V\", at = @At(\"RETURN\"))"));
|
||||
assertTrue(mixin.contains("cache = new ConcurrentHashMap<>();"));
|
||||
}
|
||||
}
|
||||
+18
@@ -67,6 +67,11 @@ public class NativeStructureFailureContractTest {
|
||||
assertTrue(placement.contains("\"terrain preparation\""));
|
||||
assertTrue(placement.contains("\"foundation repair\""));
|
||||
assertFalse(placement.contains("\"terrain carving\""));
|
||||
assertTrue(placement.contains("visitExistingPois(chunk"));
|
||||
assertTrue(placement.contains("level.updatePOIOnBlockStateChange("));
|
||||
assertTrue(placement.contains("Blocks.AIR.defaultBlockState(), state"));
|
||||
assertTrue(placement.indexOf("visitExistingPois(chunk")
|
||||
< placement.indexOf("WorldgenTerrainHeightmaps.primeStructurePlacement("));
|
||||
assertTrue(placement.contains("prepareSurfaceStructures"));
|
||||
assertTrue(placement.contains("clearIntersectingVegetation"));
|
||||
assertTrue(placement.indexOf("clearIntersectingVegetation")
|
||||
@@ -95,6 +100,19 @@ public class NativeStructureFailureContractTest {
|
||||
assertTrue(source.contains("int minY = chunk.getMinY() + 1;"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nativeStructurePostProcessingUsesBoundedWorldgenAccess() throws IOException {
|
||||
String source = moddedSource("ModdedNativeStructureStage.java");
|
||||
int placementStart = source.indexOf("private void placeVanillaStructure");
|
||||
int placementEnd = source.indexOf("private List<List<Structure>> structuresByStep", placementStart);
|
||||
String placement = source.substring(placementStart, placementEnd);
|
||||
|
||||
assertTrue(placement.contains("ModdedNativeStructureWorldgenAccess.create("));
|
||||
assertTrue(placement.contains("NativeStructurePostProcessor.place(\n boundedWorld"));
|
||||
assertFalse(placement.contains("NativeStructurePostProcessor.place(world,"));
|
||||
assertTrue(placement.contains("world.setCurrentlyGenerating(null);"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void structureFailurePreservesPhaseIdentityChunkAndCause() {
|
||||
IllegalArgumentException cause = new IllegalArgumentException("broken placement");
|
||||
|
||||
Reference in New Issue
Block a user