mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-08-28 13:00: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
|
||||
|
||||
Reference in New Issue
Block a user