Fix optimize_surface_rules breaking mods that provide custom BiomeManagers
This commit is contained in:
parent
7fbfcf1a92
commit
292a6aeab3
|
|
@ -37,11 +37,18 @@ public class SurfaceSystemMixin {
|
|||
@Local(ordinal = 0, argsOnly = true) BiomeManager manager,
|
||||
@Local(ordinal = 0, argsOnly = true) ChunkAccess chunk,
|
||||
@Share("chunkBiomeLookup") LocalRef<ChunkBiomeLookup> lookupRef) {
|
||||
// If mods use their own BiomeManager subclass, we cannot trust them to use the same blurring as vanilla,
|
||||
// so we cannot apply our optimized path
|
||||
if (manager.getClass() == BiomeManager.class) {
|
||||
var lookup = MFIX_LOOKUP_CACHE.get();
|
||||
BiomeManagerAccessor accessor = (BiomeManagerAccessor)manager;
|
||||
lookup.prepare(accessor.mfix$getBiomeSource(), accessor.mfix$getZoomSeed(), chunk, manager);
|
||||
lookupRef.set(lookup);
|
||||
return lookup;
|
||||
} else {
|
||||
lookupRef.set(null);
|
||||
return biomeGetter;
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "buildSurface", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/levelgen/SurfaceRules$RuleSource;apply(Ljava/lang/Object;)Ljava/lang/Object;", ordinal = 0))
|
||||
|
|
@ -60,7 +67,12 @@ public class SurfaceSystemMixin {
|
|||
|
||||
@Redirect(method = "buildSurface", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/biome/BiomeManager;getBiome(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/core/Holder;"))
|
||||
private Holder<Biome> useFasterLookup(BiomeManager instance, BlockPos pos, @Share("chunkBiomeLookup") LocalRef<ChunkBiomeLookup> lookupRef) {
|
||||
return lookupRef.get().apply(pos);
|
||||
var lookup = lookupRef.get();
|
||||
if (lookup != null) {
|
||||
return lookup.apply(pos);
|
||||
} else {
|
||||
return instance.getBiome(pos);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "buildSurface", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/levelgen/SurfaceRules$Context;<init>(Lnet/minecraft/world/level/levelgen/SurfaceSystem;Lnet/minecraft/world/level/levelgen/RandomState;Lnet/minecraft/world/level/chunk/ChunkAccess;Lnet/minecraft/world/level/levelgen/NoiseChunk;Ljava/util/function/Function;Lnet/minecraft/core/Registry;Lnet/minecraft/world/level/levelgen/WorldGenerationContext;)V"))
|
||||
|
|
|
|||
|
|
@ -97,6 +97,9 @@ public class ChunkBiomeLookup implements Function<BlockPos, Holder<Biome>> {
|
|||
}
|
||||
|
||||
public void dispose() {
|
||||
if (this.fallbackManager == null) {
|
||||
return;
|
||||
}
|
||||
// Make sure we do not retain strong references to the biome holders
|
||||
Arrays.fill(biomes, null);
|
||||
this.fallbackManager = null;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user