From 7bc7707d5cdcddc0c991ed6fd47bffa5ea6d0ba2 Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Tue, 17 Sep 2024 10:10:02 -0400 Subject: [PATCH] Clone chunk biome container --- .../world/ChunkBiomeContainerExtended.java | 11 ++++++++ .../world/cloned/ClonedChunkSection.java | 3 ++- .../world/chunk/ChunkBiomeContainerMixin.java | 25 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/main/java/me/jellysquid/mods/sodium/client/world/ChunkBiomeContainerExtended.java create mode 100644 src/main/java/me/jellysquid/mods/sodium/mixin/core/world/chunk/ChunkBiomeContainerMixin.java diff --git a/src/main/java/me/jellysquid/mods/sodium/client/world/ChunkBiomeContainerExtended.java b/src/main/java/me/jellysquid/mods/sodium/client/world/ChunkBiomeContainerExtended.java new file mode 100644 index 000000000..03009b1bb --- /dev/null +++ b/src/main/java/me/jellysquid/mods/sodium/client/world/ChunkBiomeContainerExtended.java @@ -0,0 +1,11 @@ +package me.jellysquid.mods.sodium.client.world; + +import net.minecraft.world.level.chunk.ChunkBiomeContainer; + +public interface ChunkBiomeContainerExtended { + static ChunkBiomeContainer clone(ChunkBiomeContainer container) { + return container != null ? ((ChunkBiomeContainerExtended)container).embeddium$copy() : null; + } + + ChunkBiomeContainer embeddium$copy(); +} diff --git a/src/main/java/me/jellysquid/mods/sodium/client/world/cloned/ClonedChunkSection.java b/src/main/java/me/jellysquid/mods/sodium/client/world/cloned/ClonedChunkSection.java index dab3a8af6..b8d6b6095 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/world/cloned/ClonedChunkSection.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/world/cloned/ClonedChunkSection.java @@ -3,6 +3,7 @@ import it.unimi.dsi.fastutil.ints.Int2ReferenceMap; import it.unimi.dsi.fastutil.ints.Int2ReferenceMaps; import it.unimi.dsi.fastutil.ints.Int2ReferenceOpenHashMap; +import me.jellysquid.mods.sodium.client.world.ChunkBiomeContainerExtended; import me.jellysquid.mods.sodium.client.world.ReadableContainerExtended; import me.jellysquid.mods.sodium.client.world.WorldSlice; import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachmentBlockEntity; @@ -86,7 +87,7 @@ public ClonedChunkSection(Level world, LevelChunk chunk, @Nullable LevelChunkSec } } - biomeData = chunk.getBiomes(); + biomeData = ChunkBiomeContainerExtended.clone(chunk.getBiomes()); this.blockData = blockData; this.biomeData = biomeData; diff --git a/src/main/java/me/jellysquid/mods/sodium/mixin/core/world/chunk/ChunkBiomeContainerMixin.java b/src/main/java/me/jellysquid/mods/sodium/mixin/core/world/chunk/ChunkBiomeContainerMixin.java new file mode 100644 index 000000000..2f9eef52d --- /dev/null +++ b/src/main/java/me/jellysquid/mods/sodium/mixin/core/world/chunk/ChunkBiomeContainerMixin.java @@ -0,0 +1,25 @@ +package me.jellysquid.mods.sodium.mixin.core.world.chunk; + +import me.jellysquid.mods.sodium.client.world.ChunkBiomeContainerExtended; +import net.minecraft.core.IdMap; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.chunk.ChunkBiomeContainer; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(ChunkBiomeContainer.class) +public class ChunkBiomeContainerMixin implements ChunkBiomeContainerExtended { + @Shadow + @Final + private IdMap biomeRegistry; + + @Shadow + @Final + private Biome[] biomes; + + @Override + public ChunkBiomeContainer embeddium$copy() { + return new ChunkBiomeContainer(this.biomeRegistry, this.biomes.clone()); + } +}