From edc97125e2f0b44e528f886ad56de8c28a66f935 Mon Sep 17 00:00:00 2001 From: StewStrong Date: Sat, 11 Nov 2023 23:31:32 -0700 Subject: [PATCH] Fixed chests rendering double with sodium --- .../client/world/MixinClientChunkCache.java | 42 +++++++------------ .../MixinBlockEntityInstanceManager.java | 6 ++- .../optifine_vanilla/MixinLevelRenderer.java | 2 +- .../client/world/ClientChunkCacheDuck.java | 2 +- 4 files changed, 23 insertions(+), 29 deletions(-) diff --git a/common/src/main/java/org/valkyrienskies/mod/mixin/client/world/MixinClientChunkCache.java b/common/src/main/java/org/valkyrienskies/mod/mixin/client/world/MixinClientChunkCache.java index 1f3a2cdfc..0f4fb6db1 100644 --- a/common/src/main/java/org/valkyrienskies/mod/mixin/client/world/MixinClientChunkCache.java +++ b/common/src/main/java/org/valkyrienskies/mod/mixin/client/world/MixinClientChunkCache.java @@ -5,18 +5,16 @@ import java.util.function.Consumer; import net.minecraft.client.multiplayer.ClientChunkCache; import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.core.SectionPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData.BlockEntityTagOutput; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.chunk.ChunkStatus; import net.minecraft.world.level.chunk.LevelChunk; -import net.minecraft.world.level.chunk.LevelChunkSection; -import net.minecraft.world.level.lighting.LevelLightEngine; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -43,11 +41,12 @@ public abstract class MixinClientChunkCache implements ClientChunkCacheDuck { @Final ClientLevel level; - public LongObjectMap vs_getShipChunks() { - return shipChunks; + public LongObjectMap vs$getShipChunks() { + return vs$shipChunks; } - private final LongObjectMap shipChunks = new LongObjectHashMap<>(); + @Unique + private final LongObjectMap vs$shipChunks = new LongObjectHashMap<>(); @Inject(method = "replaceWithPacketData", at = @At("HEAD"), cancellable = true) private void preLoadChunkFromPacket(final int x, final int z, @@ -60,25 +59,19 @@ private void preLoadChunkFromPacket(final int x, final int z, if (VSGameUtilsKt.isChunkInShipyard(level, x, z)) { final long chunkPosLong = ChunkPos.asLong(x, z); - final LevelChunk worldChunk = new LevelChunk(this.level, new ChunkPos(x, z)); - worldChunk.replaceWithPacketData(buf, tag, consumer); - shipChunks.put(chunkPosLong, worldChunk); - - final LevelChunkSection[] chunkSections = worldChunk.getSections(); - final LevelLightEngine lightingProvider = this.getLightEngine(); - lightingProvider.enableLightSources(new ChunkPos(x, z), true); - - for (int j = 0; j < chunkSections.length; ++j) { - final LevelChunkSection chunkSection = chunkSections[j]; - lightingProvider - .updateSectionStatus(SectionPos.of(x, level.getSectionYFromSectionIndex(j), z), - chunkSection.hasOnlyAir()); + final LevelChunk oldChunk = vs$shipChunks.get(chunkPosLong); + final LevelChunk worldChunk; + if (oldChunk != null) { + worldChunk = oldChunk; + oldChunk.replaceWithPacketData(buf, tag, consumer); + } else { + worldChunk = new LevelChunk(this.level, new ChunkPos(x, z)); + worldChunk.replaceWithPacketData(buf, tag, consumer); + vs$shipChunks.put(chunkPosLong, worldChunk); } this.level.onChunkLoaded(new ChunkPos(x, z)); - SodiumCompat.onChunkAdded(x, z); - cir.setReturnValue(worldChunk); } } @@ -86,7 +79,7 @@ private void preLoadChunkFromPacket(final int x, final int z, @Inject(method = "drop", at = @At("HEAD"), cancellable = true) public void preUnload(final int chunkX, final int chunkZ, final CallbackInfo ci) { - shipChunks.remove(ChunkPos.asLong(chunkX, chunkZ)); + vs$shipChunks.remove(ChunkPos.asLong(chunkX, chunkZ)); if (ValkyrienCommonMixinConfigPlugin.getVSRenderer() != VSRenderer.SODIUM) { ((IVSViewAreaMethods) ((LevelRendererAccessor) ((ClientLevelAccessor) level).getLevelRenderer()).getViewArea()) .unloadChunk(chunkX, chunkZ); @@ -100,12 +93,9 @@ public void preUnload(final int chunkX, final int chunkZ, final CallbackInfo ci) at = @At("HEAD"), cancellable = true) public void preGetChunk(final int chunkX, final int chunkZ, final ChunkStatus chunkStatus, final boolean bl, final CallbackInfoReturnable cir) { - final LevelChunk shipChunk = shipChunks.get(ChunkPos.asLong(chunkX, chunkZ)); + final LevelChunk shipChunk = vs$shipChunks.get(ChunkPos.asLong(chunkX, chunkZ)); if (shipChunk != null) { cir.setReturnValue(shipChunk); } } - - @Shadow - public abstract LevelLightEngine getLightEngine(); } diff --git a/common/src/main/java/org/valkyrienskies/mod/mixin/mod_compat/flywheel/MixinBlockEntityInstanceManager.java b/common/src/main/java/org/valkyrienskies/mod/mixin/mod_compat/flywheel/MixinBlockEntityInstanceManager.java index 7424739e8..86ad788fa 100644 --- a/common/src/main/java/org/valkyrienskies/mod/mixin/mod_compat/flywheel/MixinBlockEntityInstanceManager.java +++ b/common/src/main/java/org/valkyrienskies/mod/mixin/mod_compat/flywheel/MixinBlockEntityInstanceManager.java @@ -5,6 +5,7 @@ import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.instancing.InstanceManager; import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry; +import com.jozufozu.flywheel.backend.instancing.RenderDispatcher; import com.jozufozu.flywheel.backend.instancing.batching.BatchingEngine; import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstanceManager; import com.jozufozu.flywheel.backend.instancing.instancing.InstancingEngine; @@ -70,7 +71,10 @@ void preCreateRaw(final BlockEntity blockEntity, final CallbackInfoReturnable { + ((ClientChunkCacheDuck) this.level.getChunkSource()).vs$getShipChunks().forEach((pos, chunk) -> { for (int y = level.getMinSection(); y < level.getMaxSection(); y++) { viewArea.setDirty(ChunkPos.getX(pos), y, ChunkPos.getZ(pos), false); } diff --git a/common/src/main/java/org/valkyrienskies/mod/mixinducks/client/world/ClientChunkCacheDuck.java b/common/src/main/java/org/valkyrienskies/mod/mixinducks/client/world/ClientChunkCacheDuck.java index 74136c9b6..89169d9a4 100644 --- a/common/src/main/java/org/valkyrienskies/mod/mixinducks/client/world/ClientChunkCacheDuck.java +++ b/common/src/main/java/org/valkyrienskies/mod/mixinducks/client/world/ClientChunkCacheDuck.java @@ -4,5 +4,5 @@ import net.minecraft.world.level.chunk.LevelChunk; public interface ClientChunkCacheDuck { - LongObjectMap vs_getShipChunks(); + LongObjectMap vs$getShipChunks(); }