9
0
mirror of https://github.com/BX-Team/DivineMC.git synced 2025-12-19 14:59:25 +00:00
Files
DivineMC/patches/todo/minecraft-patches/0022-ModernFix-compact_bit_storage.patch
2025-10-10 01:56:03 +03:00

45 lines
2.3 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Sat, 8 Mar 2025 13:27:07 +0300
Subject: [PATCH] ModernFix: compact_bit_storage
This patch is based on following mixins:
* "org/embeddedt/modernfix/common/mixin/perf/compact_bit_storage/PalettedContainerMixin.java"
By: embeddedt <42941056+embeddedt@users.noreply.github.com>
As part of: ModernFix (https://github.com/embeddedt/ModernFix)
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
diff --git a/net/minecraft/world/level/chunk/PalettedContainer.java b/net/minecraft/world/level/chunk/PalettedContainer.java
index 9d892c1c3890e0aaf13fd5cd7b7d138afeaad260..ca3fab804e464a5db2b47495ecb588a96044265d 100644
--- a/net/minecraft/world/level/chunk/PalettedContainer.java
+++ b/net/minecraft/world/level/chunk/PalettedContainer.java
@@ -291,6 +291,28 @@ public class PalettedContainer<T> implements PaletteResize<T>, PalettedContainer
data.palette.read(buffer);
buffer.readFixedSizeLongArray(data.storage.getRaw());
this.data = data;
+ // DivineMC start - ModernFix: compact_bit_storage
+ if (org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.useCompactBitStorage && _byte > 1) {
+ long[] storageArray = this.data.storage.getRaw();
+ boolean empty = true;
+ for (long l : storageArray) {
+ if (l != 0) {
+ empty = false;
+ break;
+ }
+ }
+ if (empty && storageArray.length > 0) {
+ T value;
+ try {
+ value = this.data.palette.valueFor(0);
+ } catch (RuntimeException e) {
+ return;
+ }
+ this.data = this.createOrReuseData(null, 0);
+ this.data.palette.idFor(value);
+ }
+ }
+ // DivineMC end - ModernFix: compact_bit_storage
this.addPresetValues(); // Paper - Anti-Xray - Add preset values (inefficient, but this isn't used by the server)
this.updateData(this.data); // Paper - optimise palette reads
} finally {