Got chunks to generate on server

This commit is contained in:
s809
2023-07-23 20:34:40 +05:00
parent 3ca9d98c05
commit a546a97e34
3 changed files with 11 additions and 7 deletions
@@ -30,6 +30,7 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.IWrapperFactory;
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.worldGeneration.AbstractBatchGenerationEnvironmentWrapper;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.chunk.ChunkAccess;
@@ -62,7 +63,7 @@ public class WrapperFactory implements IWrapperFactory
}
@Override
public IBiomeWrapper deserializeBiomeWrapper(String str) throws IOException { return BiomeWrapper.deserialize(str); }
public IBiomeWrapper deserializeBiomeWrapper(String str, ILevelWrapper levelWrapper) throws IOException { return BiomeWrapper.deserialize(str, levelWrapper); }
@Override
public IBlockStateWrapper deserializeBlockStateWrapper(String str) throws IOException { return BlockStateWrapper.deserialize(str); }
@@ -26,8 +26,10 @@ import java.util.concurrent.ConcurrentMap;
import com.google.gson.JsonParser;
import com.mojang.serialization.JsonOps;
import com.seibel.distanthorizons.core.level.IDhLevel;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
import net.minecraft.client.Minecraft;
import net.minecraft.core.Holder;
#if POST_MC_1_19_2
@@ -35,6 +37,7 @@ import net.minecraft.data.worldgen.biome.EndBiomes;
import net.minecraft.data.worldgen.biome.NetherBiomes;
#endif
import net.minecraft.resources.RegistryOps;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.Biomes;
@@ -71,9 +74,8 @@ public class BiomeWrapper implements IBiomeWrapper
}
@Override
public String serialize() {
//FIXME: Pass in a level obj
String data = Biome.CODEC.encodeStart(RegistryOps.create(JsonOps.INSTANCE, Minecraft.getInstance().level.registryAccess()),
public String serialize(ILevelWrapper levelWrapper) {
String data = Biome.CODEC.encodeStart(RegistryOps.create(JsonOps.INSTANCE, ((Level)levelWrapper.getWrappedMcObject()).registryAccess()),
biome).get().orThrow().toString();
return data;
}
@@ -91,13 +93,13 @@ public class BiomeWrapper implements IBiomeWrapper
return Objects.hash(biome);
}
public static IBiomeWrapper deserialize(String str) throws IOException
public static IBiomeWrapper deserialize(String str, ILevelWrapper levelWrapper) throws IOException
{
try
{
#if PRE_MC_1_18_2 Biome #else
Holder<Biome> #endif
biome = Biome.CODEC.decode(RegistryOps.create(JsonOps.INSTANCE, Minecraft.getInstance().level.registryAccess()),
biome = Biome.CODEC.decode(RegistryOps.create(JsonOps.INSTANCE, ((Level)levelWrapper.getWrappedMcObject()).registryAccess()),
JsonParser.parseString(str)).get().orThrow().getFirst();
return getBiomeWrapper(biome);
}
@@ -31,6 +31,7 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrappe
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
import net.minecraft.client.multiplayer.ClientChunkCache;
import net.minecraft.client.multiplayer.ClientLevel;
@@ -201,7 +202,7 @@ public class ChunkWrapper implements IChunkWrapper
if (this.chunk instanceof LevelChunk)
{
LevelChunk levelChunk = (LevelChunk) this.chunk;
if (levelChunk.getLevel() instanceof ClientLevel)
if (this.wrappedLevel instanceof IClientLevelWrapper)
{
weakMapLock.readLock().lock();
boolean fixedIsClientLightReady = chunksToUpdateClientLightReady.get(this.chunk);