This commit is contained in:
Brian Neumann-Fopiano
2026-06-10 21:21:18 -04:00
parent c6c02a9040
commit 58d24ca55e
13 changed files with 115 additions and 110 deletions
@@ -60,6 +60,13 @@ public class CustomBiomeSource extends BiomeSource {
}
for (IrisBiome i : engine.getAllBiomes()) {
Holder<Biome> vanillaHolder = NMSBinding.biomeToBiomeBase(registry, i.getVanillaDerivative());
if (vanillaHolder != null) {
biomes.add(vanillaHolder);
} else if (!i.isCustom() && fallback != null) {
biomes.add(fallback);
}
if (i.isCustom()) {
for (IrisBiomeCustom j : i.getCustomDerivitives()) {
Holder<Biome> customHolder = resolveCustomBiomeHolder(customRegistry, engine, j.getId());
@@ -69,13 +76,6 @@ public class CustomBiomeSource extends BiomeSource {
biomes.add(fallback);
}
}
} else {
Holder<Biome> vanillaHolder = NMSBinding.biomeToBiomeBase(registry, i.getVanillaDerivative());
if (vanillaHolder != null) {
biomes.add(vanillaHolder);
} else if (fallback != null) {
biomes.add(fallback);
}
}
}
@@ -219,15 +219,15 @@ public class CustomBiomeSource extends BiomeSource {
return getFallbackBiome();
}
if (resolution.irisBiome.isCustom()) {
return resolveCustomHolder(resolution);
}
Holder<Biome> holder = NMSBinding.biomeToBiomeBase(biomeRegistry, resolution.irisBiome.getVanillaDerivative());
if (holder != null) {
return holder;
}
if (resolution.irisBiome.isCustom()) {
return resolveCustomHolder(resolution);
}
return getFallbackBiome();
}
@@ -58,7 +58,7 @@ public class IrisChunkGenerator extends CustomChunkGenerator {
}
private IrisChunkGenerator(ChunkGenerator delegate, Engine engine, World world, CustomBiomeSource customBiomeSource) {
super(((CraftWorld) world).getHandle(), edit(delegate, customBiomeSource), null);
super(((CraftWorld) world).getHandle(), edit(delegate, customBiomeSource), world.getGenerator());
this.delegate = delegate;
this.engine = engine;
this.customBiomeSource = customBiomeSource;
@@ -105,6 +105,8 @@ public class IrisChunkGenerator extends CustomChunkGenerator {
try {
return delegate.findNearestMapStructure(level, reachable, pos, radius, findUnexplored);
} catch (Throwable e) {
Iris.error("Vanilla structure locate failed near " + pos.getX() + ", " + pos.getZ() + ": " + e);
Iris.reportError(e);
return null;
}
}
@@ -159,7 +161,7 @@ public class IrisChunkGenerator extends CustomChunkGenerator {
if (!importedControl().active()) {
return;
}
delegate.createStructures(registryAccess, structureState, structureManager, access, templateManager, levelKey);
super.createStructures(registryAccess, structureState, structureManager, access, templateManager, levelKey);
}
private IrisImportedStructureControl importedControl() {
@@ -61,6 +61,7 @@ import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.FlatLevelSource;
import net.minecraft.world.level.levelgen.flat.FlatLayerInfo;
import net.minecraft.world.level.levelgen.flat.FlatLevelGeneratorSettings;
import net.minecraft.world.level.levelgen.structure.StructureCheck;
import net.minecraft.world.level.storage.LevelStorageSource;
import org.bukkit.*;
import org.bukkit.block.Biome;
@@ -624,11 +625,28 @@ public class NMSBinding implements INMSBinding {
Iris.error("Loaded world %s with unknown dimension type! expected=%s", world.getName(), expectedDimensionType);
}
IrisChunkGenerator irisGenerator = new IrisChunkGenerator(worldGenContext.generator(), seed, engine, world);
var newContext = new WorldGenContext(
worldGenContext.level(), new IrisChunkGenerator(worldGenContext.generator(), seed, engine, world),
worldGenContext.level(), irisGenerator,
worldGenContext.structureManager(), worldGenContext.lightEngine(), worldGenContext.mainThreadExecutor(), worldGenContext.unsavedListener());
worldGenContextField.set(chunkMap, newContext);
retargetStructureCheck(((CraftWorld) world).getHandle(), irisGenerator);
}
private static void retargetStructureCheck(ServerLevel level, IrisChunkGenerator generator) throws NoSuchFieldException, IllegalAccessException {
Field structureCheckField = getField(level.getClass(), StructureCheck.class);
structureCheckField.setAccessible(true);
Object structureCheck = structureCheckField.get(level);
if (structureCheck == null) {
return;
}
Field generatorField = getField(structureCheck.getClass(), net.minecraft.world.level.chunk.ChunkGenerator.class);
generatorField.setAccessible(true);
generatorField.set(structureCheck, generator);
Field biomeSourceField = getField(structureCheck.getClass(), BiomeSource.class);
biomeSourceField.setAccessible(true);
biomeSourceField.set(structureCheck, generator.getBiomeSource());
}
public Vector3d getBoundingbox(org.bukkit.entity.EntityType entity) {
@@ -60,6 +60,13 @@ public class CustomBiomeSource extends BiomeSource {
}
for (IrisBiome i : engine.getAllBiomes()) {
Holder<Biome> vanillaHolder = NMSBinding.biomeToBiomeBase(registry, i.getVanillaDerivative());
if (vanillaHolder != null) {
biomes.add(vanillaHolder);
} else if (!i.isCustom() && fallback != null) {
biomes.add(fallback);
}
if (i.isCustom()) {
for (IrisBiomeCustom j : i.getCustomDerivitives()) {
Holder<Biome> customHolder = resolveCustomBiomeHolder(customRegistry, engine, j.getId());
@@ -69,13 +76,6 @@ public class CustomBiomeSource extends BiomeSource {
biomes.add(fallback);
}
}
} else {
Holder<Biome> vanillaHolder = NMSBinding.biomeToBiomeBase(registry, i.getVanillaDerivative());
if (vanillaHolder != null) {
biomes.add(vanillaHolder);
} else if (fallback != null) {
biomes.add(fallback);
}
}
}
@@ -219,15 +219,15 @@ public class CustomBiomeSource extends BiomeSource {
return getFallbackBiome();
}
if (resolution.irisBiome.isCustom()) {
return resolveCustomHolder(resolution);
}
Holder<Biome> holder = NMSBinding.biomeToBiomeBase(biomeRegistry, resolution.irisBiome.getVanillaDerivative());
if (holder != null) {
return holder;
}
if (resolution.irisBiome.isCustom()) {
return resolveCustomHolder(resolution);
}
return getFallbackBiome();
}
@@ -58,7 +58,7 @@ public class IrisChunkGenerator extends CustomChunkGenerator {
}
private IrisChunkGenerator(ChunkGenerator delegate, Engine engine, World world, CustomBiomeSource customBiomeSource) {
super(((CraftWorld) world).getHandle(), edit(delegate, customBiomeSource), null);
super(((CraftWorld) world).getHandle(), edit(delegate, customBiomeSource), world.getGenerator());
this.delegate = delegate;
this.engine = engine;
this.customBiomeSource = customBiomeSource;
@@ -105,6 +105,8 @@ public class IrisChunkGenerator extends CustomChunkGenerator {
try {
return delegate.findNearestMapStructure(level, reachable, pos, radius, findUnexplored);
} catch (Throwable e) {
Iris.error("Vanilla structure locate failed near " + pos.getX() + ", " + pos.getZ() + ": " + e);
Iris.reportError(e);
return null;
}
}
@@ -159,7 +161,7 @@ public class IrisChunkGenerator extends CustomChunkGenerator {
if (!importedControl().active()) {
return;
}
delegate.createStructures(registryAccess, structureState, structureManager, access, templateManager, levelKey);
super.createStructures(registryAccess, structureState, structureManager, access, templateManager, levelKey);
}
private IrisImportedStructureControl importedControl() {
@@ -65,6 +65,7 @@ import net.minecraft.world.level.levelgen.FlatLevelSource;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.WorldgenRandom;
import net.minecraft.world.level.levelgen.XoroshiroRandomSource;
import net.minecraft.world.level.levelgen.structure.StructureCheck;
import net.minecraft.world.level.levelgen.feature.AbstractHugeMushroomFeature;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.FallenTreeFeature;
@@ -853,11 +854,28 @@ public class NMSBinding implements INMSBinding {
Iris.error("Loaded world %s with unknown dimension type! expected=%s", world.getName(), expectedDimensionType);
}
IrisChunkGenerator irisGenerator = new IrisChunkGenerator(worldGenContext.generator(), seed, engine, world);
var newContext = new WorldGenContext(
worldGenContext.level(), new IrisChunkGenerator(worldGenContext.generator(), seed, engine, world),
worldGenContext.level(), irisGenerator,
worldGenContext.structureManager(), worldGenContext.lightEngine(), worldGenContext.mainThreadExecutor(), worldGenContext.unsavedListener());
worldGenContextField.set(chunkMap, newContext);
retargetStructureCheck(((CraftWorld) world).getHandle(), irisGenerator);
}
private static void retargetStructureCheck(ServerLevel level, IrisChunkGenerator generator) throws NoSuchFieldException, IllegalAccessException {
Field structureCheckField = getField(level.getClass(), StructureCheck.class);
structureCheckField.setAccessible(true);
Object structureCheck = structureCheckField.get(level);
if (structureCheck == null) {
return;
}
Field generatorField = getField(structureCheck.getClass(), net.minecraft.world.level.chunk.ChunkGenerator.class);
generatorField.setAccessible(true);
generatorField.set(structureCheck, generator);
Field biomeSourceField = getField(structureCheck.getClass(), BiomeSource.class);
biomeSourceField.setAccessible(true);
biomeSourceField.set(structureCheck, generator.getBiomeSource());
}
public Vector3d getBoundingbox(org.bukkit.entity.EntityType entity) {