File tree 2 files changed +32
-2
lines changed
worldedit-core/src/main/java/com/sk89q/worldedit
2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change 19
19
20
20
package com .sk89q .worldedit .blocks ;
21
21
22
+ import com .sk89q .jnbt .AdventureNBTConverter ;
22
23
import com .sk89q .jnbt .CompoundTag ;
24
+ import com .sk89q .worldedit .WorldEdit ;
23
25
import com .sk89q .worldedit .world .NbtValued ;
24
26
import com .sk89q .worldedit .world .item .ItemType ;
27
+ import net .kyori .adventure .nbt .TagStringIO ;
25
28
29
+ import java .io .IOException ;
26
30
import javax .annotation .Nullable ;
27
31
28
32
import static com .google .common .base .Preconditions .checkNotNull ;
@@ -94,4 +98,18 @@ public CompoundTag getNbtData() {
94
98
public void setNbtData (@ Nullable CompoundTag nbtData ) {
95
99
this .nbtData = nbtData ;
96
100
}
101
+
102
+ @ Override
103
+ public String toString () {
104
+ String nbtString = "" ;
105
+ if (hasNbtData ()) {
106
+ try {
107
+ nbtString = TagStringIO .get ().asString (AdventureNBTConverter .toAdventure (getNbtData ()));
108
+ } catch (IOException e ) {
109
+ WorldEdit .logger .error ("Failed to parse NBT of Item" , e );
110
+ }
111
+ }
112
+
113
+ return getType ().getId () + nbtString ;
114
+ }
97
115
}
Original file line number Diff line number Diff line change 19
19
20
20
package com .sk89q .worldedit .world .block ;
21
21
22
+ import com .sk89q .jnbt .AdventureNBTConverter ;
22
23
import com .sk89q .jnbt .CompoundTag ;
23
24
import com .sk89q .jnbt .StringTag ;
24
25
import com .sk89q .jnbt .Tag ;
26
+ import com .sk89q .worldedit .WorldEdit ;
25
27
import com .sk89q .worldedit .blocks .TileEntityBlock ;
26
28
import com .sk89q .worldedit .registry .state .Property ;
29
+ import net .kyori .adventure .nbt .TagStringIO ;
27
30
31
+ import java .io .IOException ;
28
32
import java .util .Map ;
29
33
import java .util .Objects ;
30
34
import javax .annotation .Nullable ;
@@ -189,8 +193,16 @@ public int hashCode() {
189
193
190
194
@ Override
191
195
public String toString () {
192
- // TODO use a json serializer for the NBT data
193
- return blockState .getAsString () + (hasNbtData () ? "{hasNbt}" : "" );
196
+ String nbtString = "" ;
197
+ if (hasNbtData ()) {
198
+ try {
199
+ nbtString = TagStringIO .get ().asString (AdventureNBTConverter .toAdventure (getNbtData ()));
200
+ } catch (IOException e ) {
201
+ WorldEdit .logger .error ("Failed to parse NBT of Block" , e );
202
+ }
203
+ }
204
+
205
+ return blockState .getAsString () + nbtString ;
194
206
}
195
207
196
208
}
You can’t perform that action at this time.
0 commit comments