File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed
worldedit-core/src/main/java/com/sk89q/worldedit Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change 1919
2020package com .sk89q .worldedit .blocks ;
2121
22+ import com .sk89q .jnbt .AdventureNBTConverter ;
2223import com .sk89q .jnbt .CompoundTag ;
24+ import com .sk89q .worldedit .WorldEdit ;
2325import com .sk89q .worldedit .world .NbtValued ;
2426import com .sk89q .worldedit .world .item .ItemType ;
27+ import net .kyori .adventure .nbt .TagStringIO ;
2528
29+ import java .io .IOException ;
2630import javax .annotation .Nullable ;
2731
2832import static com .google .common .base .Preconditions .checkNotNull ;
@@ -94,4 +98,18 @@ public CompoundTag getNbtData() {
9498 public void setNbtData (@ Nullable CompoundTag nbtData ) {
9599 this .nbtData = nbtData ;
96100 }
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+ }
97115}
Original file line number Diff line number Diff line change 1919
2020package com .sk89q .worldedit .world .block ;
2121
22+ import com .sk89q .jnbt .AdventureNBTConverter ;
2223import com .sk89q .jnbt .CompoundTag ;
2324import com .sk89q .jnbt .StringTag ;
2425import com .sk89q .jnbt .Tag ;
26+ import com .sk89q .worldedit .WorldEdit ;
2527import com .sk89q .worldedit .blocks .TileEntityBlock ;
2628import com .sk89q .worldedit .registry .state .Property ;
29+ import net .kyori .adventure .nbt .TagStringIO ;
2730
31+ import java .io .IOException ;
2832import java .util .Map ;
2933import java .util .Objects ;
3034import javax .annotation .Nullable ;
@@ -189,8 +193,16 @@ public int hashCode() {
189193
190194 @ Override
191195 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 ;
194206 }
195207
196208}
You can’t perform that action at this time.
0 commit comments