20
20
import net .minecraft .registry .RegistryKeys ;
21
21
import net .minecraft .registry .RegistryWrapper .WrapperLookup ;
22
22
import net .minecraft .util .Identifier ;
23
+ import net .minecraft .util .Util ;
23
24
import net .minecraft .util .math .Vec3d ;
24
25
import net .minecraft .world .World ;
25
26
26
27
public class PlacementControlSpell extends AbstractSpell implements OrientedSpell {
27
- private final DataTracker .Entry <UUID > placedEntityId = dataTracker .startTracking (TrackableDataType .UUID , null );
28
+ private final DataTracker .Entry <UUID > placedEntityId = dataTracker .startTracking (TrackableDataType .UUID , Util . NIL_UUID );
28
29
private final DataTracker .Entry <Optional <RegistryKey <World >>> dimension = dataTracker .startTracking (TrackableDataType .ofRegistryKey (), Optional .empty ());
29
30
private final DataTracker .Entry <Optional <Vec3d >> position = dataTracker .startTracking (TrackableDataType .OPTIONAL_VECTOR , Optional .empty ());
30
31
private final DataTracker .Entry <Optional <Vec3d >> orientation = dataTracker .startTracking (TrackableDataType .OPTIONAL_VECTOR , Optional .empty ());
@@ -82,7 +83,7 @@ public boolean apply(Caster<?> caster) {
82
83
public boolean tick (Caster <?> source , Situation situation ) {
83
84
if (!source .isClient ()) {
84
85
85
- if (placedEntityId .get () == null ) {
86
+ if (Util . NIL_UUID . equals ( placedEntityId .getOrDefault ( Util . NIL_UUID )) ) {
86
87
if (dimension .get ().isEmpty ()) {
87
88
setDimension (source .asWorld ().getRegistryKey ());
88
89
}
@@ -111,7 +112,7 @@ public boolean tick(Caster<?> source, Situation situation) {
111
112
112
113
@ Nullable
113
114
private Ether .Entry <?> getConnection (Caster <?> source ) {
114
- return delegate == null || placedEntityId .get () == null ? null : getWorld (source )
115
+ return delegate == null || Util . NIL_UUID . equals ( placedEntityId .getOrDefault ( Util . NIL_UUID )) ? null : getWorld (source )
115
116
.map (world -> Ether .get (world ).get (getDelegate ().getTypeAndTraits ().type (), placedEntityId .get (), delegate .getUuid ()))
116
117
.orElse (null );
117
118
}
@@ -127,16 +128,17 @@ public void toNBT(NbtCompound compound, WrapperLookup lookup) {
127
128
position .get ().ifPresent (pos -> compound .put ("position" , NbtSerialisable .writeVector (pos )));
128
129
orientation .get ().ifPresent (o -> compound .put ("orientation" , NbtSerialisable .writeVector (o )));
129
130
dimension .get ().ifPresent (d -> compound .putString ("dimension" , d .getValue ().toString ()));
130
- if (placedEntityId .get () != null ) {
131
- compound .putUuid ("placedEntityId" , placedEntityId .get ());
131
+ @ Nullable UUID placeEntityUuid = placedEntityId .getOrDefault (Util .NIL_UUID );
132
+ if (!Util .NIL_UUID .equals (placeEntityUuid )) {
133
+ compound .putUuid ("placedEntityId" , placeEntityUuid );
132
134
}
133
135
}
134
136
135
137
@ Override
136
138
public void fromNBT (NbtCompound compound , WrapperLookup lookup ) {
137
139
super .fromNBT (compound , lookup );
138
140
delegate = Spell .readNbt (compound .getCompound ("spell" ), lookup );
139
- placedEntityId .set (compound .containsUuid ("placedEntityId" ) ? compound .getUuid ("placedEntityId" ) : null );
141
+ placedEntityId .set (compound .containsUuid ("placedEntityId" ) ? compound .getUuid ("placedEntityId" ) : Util . NIL_UUID );
140
142
position .set (compound .contains ("position" ) ? Optional .of (NbtSerialisable .readVector (compound .getList ("position" , NbtElement .DOUBLE_TYPE ))) : Optional .empty ());
141
143
orientation .set (compound .contains ("orientation" ) ? Optional .of (NbtSerialisable .readVector (compound .getList ("orientation" , NbtElement .DOUBLE_TYPE ))) : Optional .empty ());
142
144
dimension .set (compound .contains ("dimension" , NbtElement .STRING_TYPE ) ? Optional .ofNullable (Identifier .tryParse (compound .getString ("dimension" ))).map (id -> RegistryKey .of (RegistryKeys .WORLD , id )) : Optional .empty ());
0 commit comments