pass caching provider through all stages

This commit is contained in:
dfsek 2022-06-11 21:11:20 -07:00
parent dbadef5672
commit db61729e11
6 changed files with 134 additions and 68 deletions

View File

@ -136,8 +136,8 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
return CompletableFuture.supplyAsync(() -> { return CompletableFuture.supplyAsync(() -> {
ProtoWorld world = (ProtoWorld) ((StructureAccessorAccessor) structureAccessor).getWorld(); ProtoWorld world = (ProtoWorld) ((StructureAccessorAccessor) structureAccessor).getWorld();
BiomeProvider biomeProvider; BiomeProvider biomeProvider;
if(chunk instanceof net.minecraft.world.chunk.ProtoChunk) { if(chunk instanceof BiomeProviderHolder providerHolder) {
biomeProvider = ((BiomeProviderHolder) chunk).getBiomeProvider(); biomeProvider = providerHolder.getBiomeProvider();
if(biomeProvider == null) { if(biomeProvider == null) {
biomeProvider = pack.getBiomeProvider().caching(world); biomeProvider = pack.getBiomeProvider().caching(world);
} }

View File

@ -0,0 +1,48 @@
package com.dfsek.terra.fabric.mixin.cache;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.api.world.chunk.Chunk;
import com.dfsek.terra.fabric.generation.BiomeProviderHolder;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.ChunkRegion;
import net.minecraft.world.chunk.ChunkStatus;
import net.minecraft.world.chunk.ProtoChunk;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface;
import org.spongepowered.asm.mixin.Mixin;
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;
@Mixin(ChunkRegion.class)
@Implements(@Interface(iface = BiomeProviderHolder.class, prefix = "provider$"))
public class ChunkRegionMixin {
@Shadow
@Final
private net.minecraft.world.chunk.Chunk centerPos;
private BiomeProvider biomeProvider;
@Inject(method = "<init>", at = @At("RETURN"))
public void addProvider(ServerWorld world, List<Chunk> chunks, ChunkStatus status, int placementRadius, CallbackInfo ci) {
if(centerPos instanceof BiomeProviderHolder providerHolder) {
biomeProvider = providerHolder.getBiomeProvider();
}
}
public void provider$setBiomeProvider(BiomeProvider provider) {
if(this.biomeProvider != null) {
throw new IllegalStateException("Already set biome provider for chunk " + this);
}
this.biomeProvider = provider;
}
public BiomeProvider provider$getBiomeProvider() {
return biomeProvider;
}
}

View File

@ -0,0 +1,27 @@
package com.dfsek.terra.fabric.mixin.cache;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.fabric.generation.BiomeProviderHolder;
import net.minecraft.world.chunk.ProtoChunk;
import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface;
import org.spongepowered.asm.mixin.Mixin;
@Mixin(ProtoChunk.class)
@Implements(@Interface(iface = BiomeProviderHolder.class, prefix = "provider$"))
public class ProtoChunkMixin {
private BiomeProvider biomeProvider;
public void provider$setBiomeProvider(BiomeProvider provider) {
if(this.biomeProvider != null) {
throw new IllegalStateException("Already set biome provider for chunk " + this);
}
this.biomeProvider = provider;
}
public BiomeProvider provider$getBiomeProvider() {
return biomeProvider;
}
}

View File

@ -32,10 +32,7 @@ import org.spongepowered.asm.mixin.Shadow;
@Mixin(net.minecraft.world.chunk.ProtoChunk.class) @Mixin(net.minecraft.world.chunk.ProtoChunk.class)
@Implements(value = { @Implements(@Interface(iface = ProtoChunk.class, prefix = "terra$"))
@Interface(iface = ProtoChunk.class, prefix = "terra$"),
@Interface(iface = BiomeProviderHolder.class, prefix = "provider$")
})
public abstract class ProtoChunkMixin { public abstract class ProtoChunkMixin {
@Shadow @Shadow
public abstract net.minecraft.block.BlockState getBlockState(BlockPos pos); public abstract net.minecraft.block.BlockState getBlockState(BlockPos pos);
@ -43,8 +40,6 @@ public abstract class ProtoChunkMixin {
@Shadow @Shadow
public abstract HeightLimitView getHeightLimitView(); public abstract HeightLimitView getHeightLimitView();
private BiomeProvider biomeProvider;
public void terra$setBlock(int x, int y, int z, @NotNull BlockState blockState) { public void terra$setBlock(int x, int y, int z, @NotNull BlockState blockState) {
((net.minecraft.world.chunk.Chunk) (Object) this).setBlockState(new BlockPos(x, y, z), (net.minecraft.block.BlockState) blockState, ((net.minecraft.world.chunk.Chunk) (Object) this).setBlockState(new BlockPos(x, y, z), (net.minecraft.block.BlockState) blockState,
false); false);
@ -57,15 +52,4 @@ public abstract class ProtoChunkMixin {
public int terra$getMaxHeight() { public int terra$getMaxHeight() {
return getHeightLimitView().getTopY(); return getHeightLimitView().getTopY();
} }
public void provider$setBiomeProvider(BiomeProvider provider) {
if(this.biomeProvider != null) {
throw new IllegalStateException("Already set biome provider for chunk " + this);
}
this.biomeProvider = provider;
}
public BiomeProvider provider$getBiomeProvider() {
return biomeProvider;
}
} }

View File

@ -28,6 +28,7 @@ import com.dfsek.terra.api.world.ServerWorld;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider; import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator; import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
import com.dfsek.terra.api.world.chunk.generation.ProtoWorld; import com.dfsek.terra.api.world.chunk.generation.ProtoWorld;
import com.dfsek.terra.fabric.generation.BiomeProviderHolder;
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper; import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
import com.dfsek.terra.fabric.generation.TerraBiomeSource; import com.dfsek.terra.fabric.generation.TerraBiomeSource;
import com.dfsek.terra.fabric.util.FabricUtil; import com.dfsek.terra.fabric.util.FabricUtil;
@ -130,6 +131,10 @@ public abstract class ChunkRegionMixin {
} }
public BiomeProvider terraWorld$getBiomeProvider() { public BiomeProvider terraWorld$getBiomeProvider() {
BiomeProvider provider = ((BiomeProviderHolder) this).getBiomeProvider();
if(provider != null) {
return provider;
}
return caching.value(); return caching.value();
} }

View File

@ -8,6 +8,8 @@
"access.MobSpawnerLogicAccessor", "access.MobSpawnerLogicAccessor",
"access.StateAccessor", "access.StateAccessor",
"access.StructureAccessorAccessor", "access.StructureAccessorAccessor",
"cache.ChunkRegionMixin",
"cache.ProtoChunkMixin",
"compat.GenerationSettingsFloraFeaturesMixin", "compat.GenerationSettingsFloraFeaturesMixin",
"implementations.BiomeMixin", "implementations.BiomeMixin",
"implementations.HandleImplementationMixin", "implementations.HandleImplementationMixin",