Skip to content

Commit

Permalink
Adding TagWrapper interface to indicate classes which expose their Co…
Browse files Browse the repository at this point in the history
…mpoundTag data object.

ChunkBase fixed bug in ctor - should call initReferences0
  • Loading branch information
BuildTools committed Nov 12, 2021
1 parent 3b624a0 commit 52fbb72
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/main/java/net/querz/mca/ChunkBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* Abstraction for the base of all chunk types which represent chunks composed of sub-chunks {@link SectionBase}.
*/
public abstract class ChunkBase implements VersionedDataContainer {
public abstract class ChunkBase implements VersionedDataContainer, TagWrapper {
protected int dataVersion;
protected boolean partial;
protected boolean raw;
Expand All @@ -31,7 +31,7 @@ public abstract class ChunkBase implements VersionedDataContainer {
*/
public ChunkBase(CompoundTag data) {
this.data = data;
initReferences(ALL_DATA);
initReferences0(ALL_DATA);
}

private void initReferences0(long loadFlags) {
Expand Down Expand Up @@ -77,7 +77,6 @@ public void setDataVersion(int dataVersion) {
this.dataVersion = Math.max(0, dataVersion);
}


/**
* Serializes this chunk to a <code>RandomAccessFile</code>.
* @param raf The RandomAccessFile to be written to.
Expand Down Expand Up @@ -163,10 +162,16 @@ public CompoundTag getHandle() {
return data;
}

public CompoundTag updateHandle(int xPos, int zPos) {
public CompoundTag updateHandle() {
if (!raw) {
data.putInt("DataVersion", dataVersion);
}
return data;
}

// Note: Not all chunk formats store xz in their NBT, but {@link MCAFileBase} will call this update method
// to give them the chance to record them.
public CompoundTag updateHandle(int xPos, int zPos) {
return updateHandle();
}
}
18 changes: 18 additions & 0 deletions src/main/java/net/querz/mca/TagWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.querz.mca;

import net.querz.nbt.tag.CompoundTag;

public interface TagWrapper {
/**
* Updates the data tag held by this wrapper and returns it.
* @return A reference to the raw CompoundTag this object is based on.
*/
CompoundTag updateHandle();

/**
* Provides a reference to the wrapped data tag.
* May be null for objects which support partial loading such as chunks.
* @return A reference to the raw CompoundTag this object is based on.
*/
CompoundTag getHandle();
}

0 comments on commit 52fbb72

Please sign in to comment.