21
21
22
22
import com .sk89q .jnbt .CompoundTag ;
23
23
import com .sk89q .worldedit .WorldEdit ;
24
+ import com .sk89q .worldedit .util .concurrency .LazyReference ;
24
25
import com .sk89q .worldedit .util .nbt .CompoundBinaryTag ;
25
26
import com .sk89q .worldedit .util .nbt .TagStringIO ;
26
27
import com .sk89q .worldedit .world .NbtValued ;
@@ -41,7 +42,7 @@ public class BaseItem implements NbtValued {
41
42
42
43
private ItemType itemType ;
43
44
@ Nullable
44
- private CompoundBinaryTag nbtData ;
45
+ private LazyReference < CompoundBinaryTag > nbtData ;
45
46
46
47
/**
47
48
* Construct the object.
@@ -61,7 +62,7 @@ public BaseItem(ItemType itemType) {
61
62
*/
62
63
@ Deprecated
63
64
public BaseItem (ItemType itemType , @ Nullable CompoundTag nbtData ) {
64
- this (itemType , nbtData == null ? null : nbtData . asBinaryTag ( ));
65
+ this (itemType , nbtData == null ? null : LazyReference . from ( nbtData :: asBinaryTag ));
65
66
}
66
67
67
68
/**
@@ -70,7 +71,7 @@ public BaseItem(ItemType itemType, @Nullable CompoundTag nbtData) {
70
71
* @param itemType Type of the item
71
72
* @param tag NBT Compound tag
72
73
*/
73
- public BaseItem (ItemType itemType , @ Nullable CompoundBinaryTag tag ) {
74
+ public BaseItem (ItemType itemType , @ Nullable LazyReference < CompoundBinaryTag > tag ) {
74
75
checkNotNull (itemType );
75
76
this .itemType = itemType ;
76
77
this .nbtData = tag ;
@@ -94,30 +95,26 @@ public void setType(ItemType itemType) {
94
95
this .itemType = itemType ;
95
96
}
96
97
97
- @ Override
98
- public boolean hasNbt () {
99
- return this .nbtData != null ;
100
- }
101
-
102
98
@ Nullable
103
99
@ Override
104
- public CompoundBinaryTag getNbt () {
100
+ public LazyReference < CompoundBinaryTag > getNbtReference () {
105
101
return this .nbtData ;
106
102
}
107
103
108
104
@ Override
109
- public void setNbt (@ Nullable CompoundBinaryTag nbtData ) {
105
+ public void setNbtReference (@ Nullable LazyReference < CompoundBinaryTag > nbtData ) {
110
106
this .nbtData = nbtData ;
111
107
}
112
108
113
109
@ Override
114
110
public String toString () {
115
111
String nbtString = "" ;
116
- if (hasNbt ()) {
112
+ LazyReference <CompoundBinaryTag > nbtData = this .nbtData ;
113
+ if (nbtData != null ) {
117
114
try {
118
- nbtString = TagStringIO .get ().asString (nbtData );
115
+ nbtString = TagStringIO .get ().asString (nbtData . getValue () );
119
116
} catch (IOException e ) {
120
- WorldEdit .logger .error ("Failed to parse NBT of Item" , e );
117
+ WorldEdit .logger .error ("Failed to serialize NBT of Item" , e );
121
118
}
122
119
}
123
120
0 commit comments