1919
2020package com .sk89q .worldedit .world .chunk ;
2121
22- import com .sk89q .jnbt .ByteArrayTag ;
2322import 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 ;
2823import com .sk89q .worldedit .WorldEdit ;
2924import 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 ;
3031import com .sk89q .worldedit .world .DataException ;
3132import com .sk89q .worldedit .world .block .BaseBlock ;
3233import com .sk89q .worldedit .world .block .BlockState ;
3536import com .sk89q .worldedit .world .storage .InvalidFormatException ;
3637
3738import java .util .HashMap ;
38- import java .util .List ;
3939import java .util .Map ;
4040
4141/**
4242 * Represents an Alpha chunk.
4343 */
4444public 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