Skip to content

Commit 5f7c2a9

Browse files
committed
Also migrate the OldChunk
1 parent ed41a87 commit 5f7c2a9

File tree

5 files changed

+49
-37
lines changed

5 files changed

+49
-37
lines changed

worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BaseItemStack.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public BaseItemStack(ItemType itemType, int amount) {
6161
* @param id The item type
6262
* @param tag Tag value
6363
* @param amount amount in the stack
64-
* @deprecated Use {@link BaseItemStack(ItemType, CompoundBinaryTag, int)}
64+
* @deprecated Use {@link #BaseItemStack(ItemType, CompoundBinaryTag, int)}
6565
*/
6666
@Deprecated
6767
public BaseItemStack(ItemType id, CompoundTag tag, int amount) {

worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class AnvilChunk implements Chunk {
5757
*
5858
* @param tag the tag to read
5959
* @throws DataException on a data error
60-
* @deprecated Use {@link AnvilChunk(CompoundBinaryTag)}
60+
* @deprecated Use {@link #AnvilChunk(CompoundBinaryTag)}
6161
*/
6262
public AnvilChunk(CompoundTag tag) throws DataException {
6363
this(tag.asBinaryTag());

worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk13.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class AnvilChunk13 implements Chunk {
5959
*
6060
* @param tag the tag to read
6161
* @throws DataException on a data error
62-
* @deprecated Use {@link AnvilChunk13(CompoundBinaryTag)}
62+
* @deprecated Use {@link #AnvilChunk13(CompoundBinaryTag)}
6363
*/
6464
@Deprecated
6565
public AnvilChunk13(CompoundTag tag) throws DataException {

worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk16.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class AnvilChunk16 extends AnvilChunk13 {
3535
*
3636
* @param tag the tag to read
3737
* @throws DataException on a data error
38-
* @deprecated Use {@link AnvilChunk16(CompoundBinaryTag)}
38+
* @deprecated Use {@link #AnvilChunk16(CompoundBinaryTag)}
3939
*/
4040
@Deprecated
4141
public AnvilChunk16(CompoundTag tag) throws DataException {

worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/OldChunk.java

+45-33
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919

2020
package com.sk89q.worldedit.world.chunk;
2121

22-
import com.sk89q.jnbt.ByteArrayTag;
2322
import com.sk89q.jnbt.CompoundTag;
24-
import com.sk89q.jnbt.IntTag;
25-
import com.sk89q.jnbt.ListTag;
26-
import com.sk89q.jnbt.NBTUtils;
27-
import com.sk89q.jnbt.Tag;
2823
import com.sk89q.worldedit.WorldEdit;
2924
import com.sk89q.worldedit.math.BlockVector3;
25+
import com.sk89q.worldedit.util.NbtUtils;
26+
import com.sk89q.worldedit.util.nbt.BinaryTag;
27+
import com.sk89q.worldedit.util.nbt.ByteArrayBinaryTag;
28+
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
29+
import com.sk89q.worldedit.util.nbt.IntBinaryTag;
30+
import com.sk89q.worldedit.util.nbt.ListBinaryTag;
3031
import com.sk89q.worldedit.world.DataException;
3132
import com.sk89q.worldedit.world.block.BaseBlock;
3233
import com.sk89q.worldedit.world.block.BlockState;
@@ -35,35 +36,47 @@
3536
import com.sk89q.worldedit.world.storage.InvalidFormatException;
3637

3738
import java.util.HashMap;
38-
import java.util.List;
3939
import java.util.Map;
4040

4141
/**
4242
* Represents an Alpha chunk.
4343
*/
4444
public class OldChunk implements Chunk {
4545

46-
private final CompoundTag rootTag;
46+
private final CompoundBinaryTag rootTag;
4747
private final byte[] blocks;
4848
private final byte[] data;
4949
private final int rootX;
5050
private final int rootZ;
5151

52-
private Map<BlockVector3, Map<String, Tag>> tileEntities;
52+
private Map<BlockVector3, CompoundBinaryTag> tileEntities;
53+
5354

5455
/**
5556
* Construct the chunk with a compound tag.
5657
*
5758
* @param tag the tag
5859
* @throws DataException if there is an error getting the chunk data
60+
* @deprecated Use {@link #OldChunk(CompoundBinaryTag)}
5961
*/
62+
@Deprecated
6063
public OldChunk(CompoundTag tag) throws DataException {
64+
this(tag.asBinaryTag());
65+
}
66+
67+
/**
68+
* Construct the chunk with a compound tag.
69+
*
70+
* @param tag the tag
71+
* @throws DataException if there is an error getting the chunk data
72+
*/
73+
public OldChunk(CompoundBinaryTag tag) throws DataException {
6174
rootTag = tag;
6275

63-
blocks = NBTUtils.getChildTag(rootTag.getValue(), "Blocks", ByteArrayTag.class).getValue();
64-
data = NBTUtils.getChildTag(rootTag.getValue(), "Data", ByteArrayTag.class).getValue();
65-
rootX = NBTUtils.getChildTag(rootTag.getValue(), "xPos", IntTag.class).getValue();
66-
rootZ = NBTUtils.getChildTag(rootTag.getValue(), "zPos", IntTag.class).getValue();
76+
blocks = NbtUtils.getChildTag(rootTag, "Blocks", ByteArrayBinaryTag.class).value();
77+
data = NbtUtils.getChildTag(rootTag, "Data", ByteArrayBinaryTag.class).value();
78+
rootX = NbtUtils.getChildTag(rootTag, "xPos", IntBinaryTag.class).value();
79+
rootZ = NbtUtils.getChildTag(rootTag, "zPos", IntBinaryTag.class).value();
6780

6881
int size = 16 * 16 * 128;
6982
if (blocks.length != size) {
@@ -83,51 +96,50 @@ public OldChunk(CompoundTag tag) throws DataException {
8396
* @throws DataException if there is an error getting the chunk data
8497
*/
8598
private void populateTileEntities() throws DataException {
86-
List<Tag> tags = NBTUtils.getChildTag(
87-
rootTag.getValue(), "TileEntities", ListTag.class)
88-
.getValue();
99+
ListBinaryTag tags = NbtUtils.getChildTag(rootTag, "TileEntities", ListBinaryTag.class);
89100

90101
tileEntities = new HashMap<>();
91102

92-
for (Tag tag : tags) {
93-
if (!(tag instanceof CompoundTag)) {
103+
for (BinaryTag tag : tags) {
104+
if (!(tag instanceof CompoundBinaryTag)) {
94105
throw new InvalidFormatException("CompoundTag expected in TileEntities");
95106
}
96107

97-
CompoundTag t = (CompoundTag) tag;
108+
CompoundBinaryTag t = (CompoundBinaryTag) tag;
98109

99110
int x = 0;
100111
int y = 0;
101112
int z = 0;
102113

103-
Map<String, Tag> values = new HashMap<>();
114+
CompoundBinaryTag.Builder values = CompoundBinaryTag.builder();
104115

105-
for (Map.Entry<String, Tag> entry : t.getValue().entrySet()) {
106-
switch (entry.getKey()) {
116+
for (String key : t.keySet()) {
117+
BinaryTag value = t.get(key);
118+
switch (key) {
107119
case "x":
108-
if (entry.getValue() instanceof IntTag) {
109-
x = ((IntTag) entry.getValue()).getValue();
120+
if (value instanceof IntBinaryTag) {
121+
x = ((IntBinaryTag) value).value();
110122
}
111123
break;
112124
case "y":
113-
if (entry.getValue() instanceof IntTag) {
114-
y = ((IntTag) entry.getValue()).getValue();
125+
if (value instanceof IntBinaryTag) {
126+
y = ((IntBinaryTag) value).value();
115127
}
116128
break;
117129
case "z":
118-
if (entry.getValue() instanceof IntTag) {
119-
z = ((IntTag) entry.getValue()).getValue();
130+
if (value instanceof IntBinaryTag) {
131+
z = ((IntBinaryTag) value).value();
120132
}
121133
break;
122134
default:
123135
break;
124136
}
125137

126-
values.put(entry.getKey(), entry.getValue());
138+
values.put(key, value);
127139
}
128140

129141
BlockVector3 vec = BlockVector3.at(x, y, z);
130-
tileEntities.put(vec, values);
142+
tileEntities.put(vec, values.build());
131143
}
132144
}
133145

@@ -140,16 +152,16 @@ private void populateTileEntities() throws DataException {
140152
* @return a tag
141153
* @throws DataException if there is an error getting the chunk data
142154
*/
143-
private CompoundTag getBlockTileEntity(BlockVector3 position) throws DataException {
155+
private CompoundBinaryTag getBlockTileEntity(BlockVector3 position) throws DataException {
144156
if (tileEntities == null) {
145157
populateTileEntities();
146158
}
147159

148-
Map<String, Tag> values = tileEntities.get(position);
160+
CompoundBinaryTag values = tileEntities.get(position);
149161
if (values == null) {
150162
return null;
151163
}
152-
return new CompoundTag(values);
164+
return values;
153165
}
154166

155167
@Override
@@ -189,7 +201,7 @@ public BaseBlock getBlock(BlockVector3 position) throws DataException {
189201
return BlockTypes.AIR.getDefaultState().toBaseBlock();
190202
}
191203

192-
CompoundTag tileEntity = getBlockTileEntity(position);
204+
CompoundBinaryTag tileEntity = getBlockTileEntity(position);
193205

194206
if (tileEntity != null) {
195207
return state.toBaseBlock(tileEntity);

0 commit comments

Comments
 (0)