mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 10:12:53 +00:00
Support negative MCA file sections
This commit is contained in:
parent
5fa1efb1f2
commit
6c2b65055b
@ -20,6 +20,7 @@ package com.volmit.iris.util.nbt.mca;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.nbt.io.NBTDeserializer;
|
||||
import com.volmit.iris.util.nbt.io.NBTSerializer;
|
||||
import com.volmit.iris.util.nbt.io.NamedTag;
|
||||
@ -39,7 +40,7 @@ import static com.volmit.iris.util.nbt.mca.LoadFlags.*;
|
||||
|
||||
public class Chunk {
|
||||
public static final int DEFAULT_DATA_VERSION = 2730;
|
||||
private final AtomicReferenceArray<Section> sections = new AtomicReferenceArray<>(16);
|
||||
private final KMap<Integer, Section> sections = new KMap<>();
|
||||
private boolean partial;
|
||||
private int lastMCAUpdate;
|
||||
private CompoundTag data;
|
||||
@ -151,7 +152,7 @@ public class Chunk {
|
||||
if(newSection.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
sections.set(sectionIndex, newSection);
|
||||
sections.put(sectionIndex, newSection);
|
||||
}
|
||||
}
|
||||
|
||||
@ -272,10 +273,6 @@ public class Chunk {
|
||||
public CompoundTag getBlockStateAt(int blockX, int blockY, int blockZ) {
|
||||
int s = MCAUtil.blockToChunk(blockY);
|
||||
|
||||
if(sections.length() <= s) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Section section = sections.get(s);
|
||||
if(section == null) {
|
||||
return null;
|
||||
@ -303,14 +300,10 @@ public class Chunk {
|
||||
public void setBlockStateAt(int blockX, int blockY, int blockZ, CompoundTag state, boolean cleanup) {
|
||||
int sectionIndex = MCAUtil.blockToChunk(blockY);
|
||||
|
||||
if(sections.length() <= sectionIndex) {
|
||||
return;
|
||||
}
|
||||
|
||||
Section section = sections.get(sectionIndex);
|
||||
if(section == null) {
|
||||
section = Section.newSection();
|
||||
sections.set(sectionIndex, section);
|
||||
sections.put(sectionIndex, section);
|
||||
}
|
||||
section.setBlockStateAt(blockX, blockY, blockZ, state, cleanup);
|
||||
}
|
||||
@ -387,7 +380,7 @@ public class Chunk {
|
||||
* The section to be set.
|
||||
*/
|
||||
public void setSection(int sectionY, Section section) {
|
||||
sections.set(sectionY, section);
|
||||
sections.put(sectionY, section);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -616,8 +609,7 @@ public class Chunk {
|
||||
}
|
||||
|
||||
public void cleanupPalettesAndBlockStates() {
|
||||
for(int i = 0; i < sections.length(); i++) {
|
||||
Section section = sections.get(i);
|
||||
for(Section section : sections.values()) {
|
||||
if(section != null) {
|
||||
section.cleanupPaletteAndBlockStates();
|
||||
}
|
||||
@ -645,16 +637,19 @@ public class Chunk {
|
||||
level.putString("Status", status);
|
||||
if(structures != null) level.put("Structures", structures);
|
||||
ListTag<CompoundTag> sections = new ListTag<>(CompoundTag.class);
|
||||
for(int i = 0; i < this.sections.length(); i++) {
|
||||
|
||||
for(int i : this.sections.keySet())
|
||||
{
|
||||
if(this.sections.get(i) != null) {
|
||||
sections.add(this.sections.get(i).updateHandle(i));
|
||||
}
|
||||
}
|
||||
|
||||
level.put("Sections", sections);
|
||||
return data;
|
||||
}
|
||||
|
||||
public int sectionCount() {
|
||||
return sections.length();
|
||||
return sections.size();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user