Changed how Features step works for mod compat with CaveBiomesApi

This commit is contained in:
tom lee
2022-02-05 19:11:40 +08:00
parent ac12e61a2d
commit 767452338a
2 changed files with 16 additions and 34 deletions
@@ -5,7 +5,6 @@ import java.util.stream.Stream;
import org.jetbrains.annotations.Nullable;
import com.seibel.lod.common.wrappers.worldGeneration.BatchGenerationEnvironment;
import com.seibel.lod.common.wrappers.worldGeneration.BatchGenerationEnvironment.EmptyChunkGenerator;
import com.seibel.lod.core.api.ClientApi;
import com.seibel.lod.core.enums.config.LightGenerationMode;
@@ -42,6 +41,17 @@ public class LightedWorldGenRegion extends WorldGenRegion {
private final List<ChunkAccess> cache;
private final StructureFeatureManager structFeat;
Long2ObjectOpenHashMap<ChunkAccess> chunkMap = new Long2ObjectOpenHashMap<ChunkAccess>();
private ChunkPos overrideCenterPos = null;
public void setOverrideCenter(ChunkPos pos) {overrideCenterPos = pos;}
@Override
public int getCenterX() {
return overrideCenterPos==null ? super.getCenterX() : overrideCenterPos.x;
}
@Override
public int getCenterZ() {
return overrideCenterPos==null ? super.getCenterZ() : overrideCenterPos.z;
}
public LightedWorldGenRegion(ServerLevel serverLevel, WorldGenLevelLightEngine lightEngine,
StructureFeatureManager structFeat, List<ChunkAccess> list, ChunkStatus chunkStatus, int i,
@@ -3,20 +3,14 @@ package com.seibel.lod.common.wrappers.worldGeneration.step;
import java.util.ArrayList;
import com.seibel.lod.common.wrappers.worldGeneration.ThreadedParameters;
import com.seibel.lod.common.wrappers.worldGeneration.mimicObject.LightedWorldGenRegion;
import com.seibel.lod.common.wrappers.worldGeneration.BatchGenerationEnvironment;
import com.seibel.lod.core.util.GridList;
import net.minecraft.CrashReport;
import net.minecraft.ReportedException;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.WorldGenRegion;
import net.minecraft.world.level.StructureFeatureManager;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.chunk.ChunkStatus;
import net.minecraft.world.level.chunk.ProtoChunk;
import net.minecraft.world.level.levelgen.WorldgenRandom;
public final class StepFeatures {
/**
@@ -33,31 +27,7 @@ public final class StepFeatures {
public final ChunkStatus STATUS = ChunkStatus.FEATURES;
public void applyBiomeDecoration(ChunkGenerator generator, WorldGenRegion worldGenRegion,
StructureFeatureManager structureFeatureManager, ChunkAccess chunk) {
int i = chunk.getPos().x;
int j = chunk.getPos().z;
int k = i * 16;
int l = j * 16;
BlockPos blockPos = new BlockPos(k, 0, l);
Biome biome = generator.biomeSource.getNoiseBiome((i << 2) + 2, 2, (j << 2) + 2);
WorldgenRandom worldgenRandom = new WorldgenRandom();
long m = worldgenRandom.setDecorationSeed(worldGenRegion.getSeed(), k, l);
try {
synchronized (generator) {
biome.generate(structureFeatureManager, generator, worldGenRegion, m, worldgenRandom, blockPos);
}
} catch (Exception exception) {
CrashReport crashReport = CrashReport.forThrowable(exception, "Biome decoration");
crashReport.addCategory("Generation")
.setDetail("CenterX", Integer.valueOf(i)).setDetail("CenterZ", Integer.valueOf(j))
.setDetail("Seed", Long.valueOf(m)).setDetail("Biome", biome);
throw new ReportedException(crashReport);
}
}
public void generateGroup(ThreadedParameters tParams, WorldGenRegion worldGenRegion, GridList<ChunkAccess> chunks) {
public void generateGroup(ThreadedParameters tParams, LightedWorldGenRegion worldGenRegion, GridList<ChunkAccess> chunks) {
ArrayList<ChunkAccess> chunksToDo = new ArrayList<ChunkAccess>();
for (ChunkAccess chunk : chunks) {
@@ -69,10 +39,12 @@ public final class StepFeatures {
for (ChunkAccess chunk : chunksToDo) {
try {
applyBiomeDecoration(envionment.params.generator, worldGenRegion, tParams.structFeat, chunk);
worldGenRegion.setOverrideCenter(chunk.getPos());
envionment.params.generator.applyBiomeDecoration(worldGenRegion, tParams.structFeat);
} catch (ReportedException e) {
e.printStackTrace();
}
}
worldGenRegion.setOverrideCenter(null);
}
}