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