diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/WrapperFactory.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/WrapperFactory.java index 8992217d1..63b62f07d 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/WrapperFactory.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/WrapperFactory.java @@ -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); } diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/BiomeWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/BiomeWrapper.java index c9ada074e..ed78cf6cc 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/BiomeWrapper.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/BiomeWrapper.java @@ -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 #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); } diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java index 7ad737834..a3828a1ea 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java @@ -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);