update lithium: chunk structure storage
This commit is contained in:
@@ -7,7 +7,7 @@ Original code by CaffeineMC, licensed under GNU Lesser General Public License v3
|
||||
You can find the original code on https://github.com/CaffeineMC/lithium-fabric (Yarn mappings)
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java b/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java
|
||||
index 5aeaaae6f15050a2da271fe196d0a234ecafc8a1..15b645403bb3d5125a02c75d608e83b48c8bbd4d 100644
|
||||
index 5aeaaae6f15050a2da271fe196d0a234ecafc8a1..c95aaea6cc984095654f7e44baa806342537061d 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java
|
||||
@@ -51,6 +51,8 @@ import net.minecraft.world.ticks.SerializableTickContainer;
|
||||
@@ -33,7 +33,7 @@ index 5aeaaae6f15050a2da271fe196d0a234ecafc8a1..15b645403bb3d5125a02c75d608e83b4
|
||||
|
||||
public void setAllStarts(Map<StructureFeature<?>, StructureStart<?>> structureStarts) {
|
||||
+ // JettPack start - lithium: chunk.structure_storage
|
||||
+ if (structureStarts instanceof HashMap) {
|
||||
+ if (structureStarts instanceof HashMap && !structureStarts.isEmpty()) {
|
||||
+ structureStarts.values().removeIf(structureStart -> structureStart == null || structureStart == StructureStart.INVALID_START);
|
||||
+ }
|
||||
+ // JettPack end
|
||||
@@ -76,7 +76,7 @@ index 5aeaaae6f15050a2da271fe196d0a234ecafc8a1..15b645403bb3d5125a02c75d608e83b4
|
||||
- this.structuresRefences.clear();
|
||||
- this.structuresRefences.putAll(structureReferences);
|
||||
+ // JettPack start - lithium: chunk.structure_storage
|
||||
+ if (structureReferences instanceof HashMap) {
|
||||
+ if (structureReferences instanceof HashMap && !structureReferences.isEmpty()) {
|
||||
+ structureReferences.values().removeIf(longs -> longs == null || longs.isEmpty());
|
||||
+ }
|
||||
+ // JettPack end
|
||||
@@ -85,3 +85,75 @@ index 5aeaaae6f15050a2da271fe196d0a234ecafc8a1..15b645403bb3d5125a02c75d608e83b4
|
||||
this.unsaved = true;
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java b/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java
|
||||
index 300c95a3839954b9e631aa4d76c131a5c2d96394..ef443167e593d2eb515dc9ad6ae6d791ddd410b8 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java
|
||||
@@ -64,6 +64,9 @@ import net.minecraft.world.ticks.LevelChunkTicks;
|
||||
import net.minecraft.world.ticks.ProtoChunkTicks;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
+import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; // JettPack
|
||||
+import it.unimi.dsi.fastutil.objects.Object2ObjectMaps; // JettPack
|
||||
+import it.unimi.dsi.fastutil.longs.LongSets; // JettPack
|
||||
|
||||
public class ChunkSerializer {
|
||||
// Paper start
|
||||
@@ -73,6 +76,48 @@ public class ChunkSerializer {
|
||||
}
|
||||
// Paper end
|
||||
|
||||
+ // JettPack start - lithium: chunk.structure_storage
|
||||
+ private static final Object2ObjectOpenHashMap<StructureFeature<?>, StructureStart<?>> DEFAULT_STRUCTURE_STARTS;
|
||||
+ private static final Map<StructureFeature<?>, StructureStart<?>> DEFAULT_STRUCTURE_STARTS_READONLY;
|
||||
+ private static final Object2ObjectOpenHashMap<StructureFeature<?>, LongSet> DEFAULT_STRUCTURE_REFERENCES;
|
||||
+ private static final Map<StructureFeature<?>, LongSet> DEFAULT_STRUCTURE_REFERENCES_READONLY;
|
||||
+
|
||||
+ static {
|
||||
+ Object2ObjectOpenHashMap<StructureFeature<?>, StructureStart<?>> structureStarts = new Object2ObjectOpenHashMap<>();
|
||||
+ Object2ObjectOpenHashMap<StructureFeature<?>, LongSet> structureReferences = new Object2ObjectOpenHashMap<>();
|
||||
+ for (StructureFeature<?> structureFeature : Registry.STRUCTURE_FEATURE) {
|
||||
+ structureStarts.put(structureFeature, StructureStart.INVALID_START);
|
||||
+ structureReferences.put(structureFeature, LongSets.emptySet());
|
||||
+ }
|
||||
+ structureStarts.trim();
|
||||
+ structureReferences.trim();
|
||||
+ DEFAULT_STRUCTURE_STARTS = structureStarts;
|
||||
+ DEFAULT_STRUCTURE_REFERENCES = structureReferences;
|
||||
+ DEFAULT_STRUCTURE_STARTS_READONLY = Object2ObjectMaps.unmodifiable(structureStarts);
|
||||
+ DEFAULT_STRUCTURE_REFERENCES_READONLY = Object2ObjectMaps.unmodifiable(structureReferences);
|
||||
+ }
|
||||
+
|
||||
+ private static Map<StructureFeature<?>, StructureStart<?>> getCompleteStructureStarts(ChunkAccess chunk) {
|
||||
+ Map<StructureFeature<?>, StructureStart<?>> structureStarts = chunk.getAllStarts();
|
||||
+ if (structureStarts.isEmpty()) {
|
||||
+ return DEFAULT_STRUCTURE_STARTS_READONLY;
|
||||
+ }
|
||||
+ Object2ObjectOpenHashMap<StructureFeature<?>, StructureStart<?>> completeStructureStarts = DEFAULT_STRUCTURE_STARTS.clone();
|
||||
+ completeStructureStarts.putAll(structureStarts);
|
||||
+ return completeStructureStarts;
|
||||
+ }
|
||||
+
|
||||
+ private static Map<StructureFeature<?>, LongSet> getCompleteStructureReferences(ChunkAccess chunk) {
|
||||
+ Map<StructureFeature<?>, LongSet> structureReferences = chunk.getAllReferences();
|
||||
+ if (structureReferences.isEmpty()) {
|
||||
+ return DEFAULT_STRUCTURE_REFERENCES_READONLY;
|
||||
+ }
|
||||
+ Object2ObjectOpenHashMap<StructureFeature<?>, LongSet> completeStructureReferences = DEFAULT_STRUCTURE_REFERENCES.clone();
|
||||
+ completeStructureReferences.putAll(structureReferences);
|
||||
+ return completeStructureReferences;
|
||||
+ }
|
||||
+ // JettPack end
|
||||
+
|
||||
public static final Codec<PalettedContainer<BlockState>> BLOCK_STATE_CODEC = PalettedContainer.codec(Block.BLOCK_STATE_REGISTRY, BlockState.CODEC, PalettedContainer.Strategy.SECTION_STATES, Blocks.AIR.defaultBlockState(), null); // Paper - Anti-Xray - Add preset block states
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final String TAG_UPGRADE_DATA = "UpgradeData";
|
||||
@@ -676,7 +721,7 @@ public class ChunkSerializer {
|
||||
}
|
||||
|
||||
nbttagcompound.put("Heightmaps", nbttagcompound3);
|
||||
- nbttagcompound.put("structures", ChunkSerializer.packStructureData(StructurePieceSerializationContext.fromLevel(world), chunkcoordintpair, chunk.getAllStarts(), chunk.getAllReferences()));
|
||||
+ nbttagcompound.put("structures", ChunkSerializer.packStructureData(StructurePieceSerializationContext.fromLevel(world), chunkcoordintpair, getCompleteStructureStarts(chunk), getCompleteStructureReferences(chunk))); // JettPack - lithium: chunk.structure_storage
|
||||
// CraftBukkit start - store chunk persistent data in nbt
|
||||
if (!chunk.persistentDataContainer.isEmpty()) { // SPIGOT-6814: Always save PDC to account for 1.17 to 1.18 chunk upgrading.
|
||||
nbttagcompound.put("ChunkBukkitValues", chunk.persistentDataContainer.toTagCompound());
|
||||
|
||||
Reference in New Issue
Block a user