Skip to content

Commit 8a384f3

Browse files
committed
Fix #516
1 parent 1bb14a6 commit 8a384f3

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/main/java/com/minelittlepony/unicopia/ability/magic/spell/PlacementControlSpell.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
import net.minecraft.registry.RegistryKeys;
2121
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
2222
import net.minecraft.util.Identifier;
23+
import net.minecraft.util.Util;
2324
import net.minecraft.util.math.Vec3d;
2425
import net.minecraft.world.World;
2526

2627
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);
2829
private final DataTracker.Entry<Optional<RegistryKey<World>>> dimension = dataTracker.startTracking(TrackableDataType.ofRegistryKey(), Optional.empty());
2930
private final DataTracker.Entry<Optional<Vec3d>> position = dataTracker.startTracking(TrackableDataType.OPTIONAL_VECTOR, Optional.empty());
3031
private final DataTracker.Entry<Optional<Vec3d>> orientation = dataTracker.startTracking(TrackableDataType.OPTIONAL_VECTOR, Optional.empty());
@@ -82,7 +83,7 @@ public boolean apply(Caster<?> caster) {
8283
public boolean tick(Caster<?> source, Situation situation) {
8384
if (!source.isClient()) {
8485

85-
if (placedEntityId.get() == null) {
86+
if (Util.NIL_UUID.equals(placedEntityId.getOrDefault(Util.NIL_UUID))) {
8687
if (dimension.get().isEmpty()) {
8788
setDimension(source.asWorld().getRegistryKey());
8889
}
@@ -111,7 +112,7 @@ public boolean tick(Caster<?> source, Situation situation) {
111112

112113
@Nullable
113114
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)
115116
.map(world -> Ether.get(world).get(getDelegate().getTypeAndTraits().type(), placedEntityId.get(), delegate.getUuid()))
116117
.orElse(null);
117118
}
@@ -127,16 +128,17 @@ public void toNBT(NbtCompound compound, WrapperLookup lookup) {
127128
position.get().ifPresent(pos -> compound.put("position", NbtSerialisable.writeVector(pos)));
128129
orientation.get().ifPresent(o -> compound.put("orientation", NbtSerialisable.writeVector(o)));
129130
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);
132134
}
133135
}
134136

135137
@Override
136138
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
137139
super.fromNBT(compound, lookup);
138140
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);
140142
position.set(compound.contains("position") ? Optional.of(NbtSerialisable.readVector(compound.getList("position", NbtElement.DOUBLE_TYPE))) : Optional.empty());
141143
orientation.set(compound.contains("orientation") ? Optional.of(NbtSerialisable.readVector(compound.getList("orientation", NbtElement.DOUBLE_TYPE))) : Optional.empty());
142144
dimension.set(compound.contains("dimension", NbtElement.STRING_TYPE) ? Optional.ofNullable(Identifier.tryParse(compound.getString("dimension"))).map(id -> RegistryKey.of(RegistryKeys.WORLD, id)) : Optional.empty());

src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/PortalSpell.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public float getYawDifference() {
8484

8585
@SuppressWarnings("unchecked")
8686
private Ether.Entry<PortalSpell> getDestination(Caster<?> source) {
87-
return Util.NIL_UUID.equals(targetPortalId.get()) ? null : getDestinationReference()
87+
return Util.NIL_UUID.equals(targetPortalId.getOrDefault(Util.NIL_UUID)) ? null : getDestinationReference()
8888
.getTarget()
8989
.map(target -> Ether.get(source.asWorld()).get((SpellType<PortalSpell>)getType(), target.uuid(), targetPortalId.get()))
9090
.filter(destination -> destination.isClaimedBy(getUuid()))
@@ -229,7 +229,10 @@ protected void onDestroyed(Caster<?> caster) {
229229
@Override
230230
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
231231
super.toNBT(compound, lookup);
232-
compound.putUuid("targetPortalId", targetPortalId.get());
232+
@Nullable UUID otherPortalUuid = targetPortalId.getOrDefault(Util.NIL_UUID);
233+
if (!Util.NIL_UUID.equals(otherPortalUuid)) {
234+
compound.putUuid("targetPortalId", otherPortalUuid);
235+
}
233236
compound.put("teleportationTarget", teleportationTarget.toNBT(lookup));
234237
compound.putFloat("pitch", getPitch());
235238
compound.putFloat("yaw", getYaw());

src/main/java/com/minelittlepony/unicopia/network/track/DataTracker.java

+5
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ public T get() {
140140
return tracker.get(this);
141141
}
142142

143+
public T getOrDefault(T def) {
144+
T t = get();
145+
return t == null ? def : t;
146+
}
147+
143148
public void set(T t) {
144149
tracker.set(this, t);
145150
}

0 commit comments

Comments
 (0)