19
19
20
20
package com .sk89q .worldedit .world .chunk ;
21
21
22
- import com .sk89q .jnbt .ByteArrayTag ;
23
22
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 ;
28
23
import com .sk89q .worldedit .WorldEdit ;
29
24
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 ;
30
31
import com .sk89q .worldedit .world .DataException ;
31
32
import com .sk89q .worldedit .world .block .BaseBlock ;
32
33
import com .sk89q .worldedit .world .block .BlockState ;
35
36
import com .sk89q .worldedit .world .storage .InvalidFormatException ;
36
37
37
38
import java .util .HashMap ;
38
- import java .util .List ;
39
39
import java .util .Map ;
40
40
41
41
/**
42
42
* Represents an Alpha chunk.
43
43
*/
44
44
public class OldChunk implements Chunk {
45
45
46
- private final CompoundTag rootTag ;
46
+ private final CompoundBinaryTag rootTag ;
47
47
private final byte [] blocks ;
48
48
private final byte [] data ;
49
49
private final int rootX ;
50
50
private final int rootZ ;
51
51
52
- private Map <BlockVector3 , Map <String , Tag >> tileEntities ;
52
+ private Map <BlockVector3 , CompoundBinaryTag > tileEntities ;
53
+
53
54
54
55
/**
55
56
* Construct the chunk with a compound tag.
56
57
*
57
58
* @param tag the tag
58
59
* @throws DataException if there is an error getting the chunk data
60
+ * @deprecated Use {@link #OldChunk(CompoundBinaryTag)}
59
61
*/
62
+ @ Deprecated
60
63
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 {
61
74
rootTag = tag ;
62
75
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 ();
67
80
68
81
int size = 16 * 16 * 128 ;
69
82
if (blocks .length != size ) {
@@ -83,51 +96,50 @@ public OldChunk(CompoundTag tag) throws DataException {
83
96
* @throws DataException if there is an error getting the chunk data
84
97
*/
85
98
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 );
89
100
90
101
tileEntities = new HashMap <>();
91
102
92
- for (Tag tag : tags ) {
93
- if (!(tag instanceof CompoundTag )) {
103
+ for (BinaryTag tag : tags ) {
104
+ if (!(tag instanceof CompoundBinaryTag )) {
94
105
throw new InvalidFormatException ("CompoundTag expected in TileEntities" );
95
106
}
96
107
97
- CompoundTag t = (CompoundTag ) tag ;
108
+ CompoundBinaryTag t = (CompoundBinaryTag ) tag ;
98
109
99
110
int x = 0 ;
100
111
int y = 0 ;
101
112
int z = 0 ;
102
113
103
- Map < String , Tag > values = new HashMap <> ();
114
+ CompoundBinaryTag . Builder values = CompoundBinaryTag . builder ();
104
115
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 ) {
107
119
case "x" :
108
- if (entry . getValue () instanceof IntTag ) {
109
- x = ((IntTag ) entry . getValue ()). getValue ();
120
+ if (value instanceof IntBinaryTag ) {
121
+ x = ((IntBinaryTag ) value ). value ();
110
122
}
111
123
break ;
112
124
case "y" :
113
- if (entry . getValue () instanceof IntTag ) {
114
- y = ((IntTag ) entry . getValue ()). getValue ();
125
+ if (value instanceof IntBinaryTag ) {
126
+ y = ((IntBinaryTag ) value ). value ();
115
127
}
116
128
break ;
117
129
case "z" :
118
- if (entry . getValue () instanceof IntTag ) {
119
- z = ((IntTag ) entry . getValue ()). getValue ();
130
+ if (value instanceof IntBinaryTag ) {
131
+ z = ((IntBinaryTag ) value ). value ();
120
132
}
121
133
break ;
122
134
default :
123
135
break ;
124
136
}
125
137
126
- values .put (entry . getKey (), entry . getValue () );
138
+ values .put (key , value );
127
139
}
128
140
129
141
BlockVector3 vec = BlockVector3 .at (x , y , z );
130
- tileEntities .put (vec , values );
142
+ tileEntities .put (vec , values . build () );
131
143
}
132
144
}
133
145
@@ -140,16 +152,16 @@ private void populateTileEntities() throws DataException {
140
152
* @return a tag
141
153
* @throws DataException if there is an error getting the chunk data
142
154
*/
143
- private CompoundTag getBlockTileEntity (BlockVector3 position ) throws DataException {
155
+ private CompoundBinaryTag getBlockTileEntity (BlockVector3 position ) throws DataException {
144
156
if (tileEntities == null ) {
145
157
populateTileEntities ();
146
158
}
147
159
148
- Map < String , Tag > values = tileEntities .get (position );
160
+ CompoundBinaryTag values = tileEntities .get (position );
149
161
if (values == null ) {
150
162
return null ;
151
163
}
152
- return new CompoundTag ( values ) ;
164
+ return values ;
153
165
}
154
166
155
167
@ Override
@@ -189,7 +201,7 @@ public BaseBlock getBlock(BlockVector3 position) throws DataException {
189
201
return BlockTypes .AIR .getDefaultState ().toBaseBlock ();
190
202
}
191
203
192
- CompoundTag tileEntity = getBlockTileEntity (position );
204
+ CompoundBinaryTag tileEntity = getBlockTileEntity (position );
193
205
194
206
if (tileEntity != null ) {
195
207
return state .toBaseBlock (tileEntity );
0 commit comments