mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Fix #516
This commit is contained in:
parent
1bb14a6e1d
commit
8a384f3904
3 changed files with 18 additions and 8 deletions
|
@ -20,11 +20,12 @@ import net.minecraft.registry.RegistryKey;
|
||||||
import net.minecraft.registry.RegistryKeys;
|
import net.minecraft.registry.RegistryKeys;
|
||||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.Util;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class PlacementControlSpell extends AbstractSpell implements OrientedSpell {
|
public class PlacementControlSpell extends AbstractSpell implements OrientedSpell {
|
||||||
private final DataTracker.Entry<UUID> placedEntityId = dataTracker.startTracking(TrackableDataType.UUID, null);
|
private final DataTracker.Entry<UUID> placedEntityId = dataTracker.startTracking(TrackableDataType.UUID, Util.NIL_UUID);
|
||||||
private final DataTracker.Entry<Optional<RegistryKey<World>>> dimension = dataTracker.startTracking(TrackableDataType.ofRegistryKey(), Optional.empty());
|
private final DataTracker.Entry<Optional<RegistryKey<World>>> dimension = dataTracker.startTracking(TrackableDataType.ofRegistryKey(), Optional.empty());
|
||||||
private final DataTracker.Entry<Optional<Vec3d>> position = dataTracker.startTracking(TrackableDataType.OPTIONAL_VECTOR, Optional.empty());
|
private final DataTracker.Entry<Optional<Vec3d>> position = dataTracker.startTracking(TrackableDataType.OPTIONAL_VECTOR, Optional.empty());
|
||||||
private final DataTracker.Entry<Optional<Vec3d>> orientation = dataTracker.startTracking(TrackableDataType.OPTIONAL_VECTOR, Optional.empty());
|
private final DataTracker.Entry<Optional<Vec3d>> orientation = dataTracker.startTracking(TrackableDataType.OPTIONAL_VECTOR, Optional.empty());
|
||||||
|
@ -82,7 +83,7 @@ public class PlacementControlSpell extends AbstractSpell implements OrientedSpel
|
||||||
public boolean tick(Caster<?> source, Situation situation) {
|
public boolean tick(Caster<?> source, Situation situation) {
|
||||||
if (!source.isClient()) {
|
if (!source.isClient()) {
|
||||||
|
|
||||||
if (placedEntityId.get() == null) {
|
if (Util.NIL_UUID.equals(placedEntityId.getOrDefault(Util.NIL_UUID))) {
|
||||||
if (dimension.get().isEmpty()) {
|
if (dimension.get().isEmpty()) {
|
||||||
setDimension(source.asWorld().getRegistryKey());
|
setDimension(source.asWorld().getRegistryKey());
|
||||||
}
|
}
|
||||||
|
@ -111,7 +112,7 @@ public class PlacementControlSpell extends AbstractSpell implements OrientedSpel
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private Ether.Entry<?> getConnection(Caster<?> source) {
|
private Ether.Entry<?> getConnection(Caster<?> source) {
|
||||||
return delegate == null || placedEntityId.get() == null ? null : getWorld(source)
|
return delegate == null || Util.NIL_UUID.equals(placedEntityId.getOrDefault(Util.NIL_UUID)) ? null : getWorld(source)
|
||||||
.map(world -> Ether.get(world).get(getDelegate().getTypeAndTraits().type(), placedEntityId.get(), delegate.getUuid()))
|
.map(world -> Ether.get(world).get(getDelegate().getTypeAndTraits().type(), placedEntityId.get(), delegate.getUuid()))
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
@ -127,8 +128,9 @@ public class PlacementControlSpell extends AbstractSpell implements OrientedSpel
|
||||||
position.get().ifPresent(pos -> compound.put("position", NbtSerialisable.writeVector(pos)));
|
position.get().ifPresent(pos -> compound.put("position", NbtSerialisable.writeVector(pos)));
|
||||||
orientation.get().ifPresent(o -> compound.put("orientation", NbtSerialisable.writeVector(o)));
|
orientation.get().ifPresent(o -> compound.put("orientation", NbtSerialisable.writeVector(o)));
|
||||||
dimension.get().ifPresent(d -> compound.putString("dimension", d.getValue().toString()));
|
dimension.get().ifPresent(d -> compound.putString("dimension", d.getValue().toString()));
|
||||||
if (placedEntityId.get() != null) {
|
@Nullable UUID placeEntityUuid = placedEntityId.getOrDefault(Util.NIL_UUID);
|
||||||
compound.putUuid("placedEntityId", placedEntityId.get());
|
if (!Util.NIL_UUID.equals(placeEntityUuid)) {
|
||||||
|
compound.putUuid("placedEntityId", placeEntityUuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +138,7 @@ public class PlacementControlSpell extends AbstractSpell implements OrientedSpel
|
||||||
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
|
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||||
super.fromNBT(compound, lookup);
|
super.fromNBT(compound, lookup);
|
||||||
delegate = Spell.readNbt(compound.getCompound("spell"), lookup);
|
delegate = Spell.readNbt(compound.getCompound("spell"), lookup);
|
||||||
placedEntityId.set(compound.containsUuid("placedEntityId") ? compound.getUuid("placedEntityId") : null);
|
placedEntityId.set(compound.containsUuid("placedEntityId") ? compound.getUuid("placedEntityId") : Util.NIL_UUID);
|
||||||
position.set(compound.contains("position") ? Optional.of(NbtSerialisable.readVector(compound.getList("position", NbtElement.DOUBLE_TYPE))) : Optional.empty());
|
position.set(compound.contains("position") ? Optional.of(NbtSerialisable.readVector(compound.getList("position", NbtElement.DOUBLE_TYPE))) : Optional.empty());
|
||||||
orientation.set(compound.contains("orientation") ? Optional.of(NbtSerialisable.readVector(compound.getList("orientation", NbtElement.DOUBLE_TYPE))) : Optional.empty());
|
orientation.set(compound.contains("orientation") ? Optional.of(NbtSerialisable.readVector(compound.getList("orientation", NbtElement.DOUBLE_TYPE))) : Optional.empty());
|
||||||
dimension.set(compound.contains("dimension", NbtElement.STRING_TYPE) ? Optional.ofNullable(Identifier.tryParse(compound.getString("dimension"))).map(id -> RegistryKey.of(RegistryKeys.WORLD, id)) : Optional.empty());
|
dimension.set(compound.contains("dimension", NbtElement.STRING_TYPE) ? Optional.ofNullable(Identifier.tryParse(compound.getString("dimension"))).map(id -> RegistryKey.of(RegistryKeys.WORLD, id)) : Optional.empty());
|
||||||
|
|
|
@ -84,7 +84,7 @@ public class PortalSpell extends AbstractSpell implements PlacementControlSpell.
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private Ether.Entry<PortalSpell> getDestination(Caster<?> source) {
|
private Ether.Entry<PortalSpell> getDestination(Caster<?> source) {
|
||||||
return Util.NIL_UUID.equals(targetPortalId.get()) ? null : getDestinationReference()
|
return Util.NIL_UUID.equals(targetPortalId.getOrDefault(Util.NIL_UUID)) ? null : getDestinationReference()
|
||||||
.getTarget()
|
.getTarget()
|
||||||
.map(target -> Ether.get(source.asWorld()).get((SpellType<PortalSpell>)getType(), target.uuid(), targetPortalId.get()))
|
.map(target -> Ether.get(source.asWorld()).get((SpellType<PortalSpell>)getType(), target.uuid(), targetPortalId.get()))
|
||||||
.filter(destination -> destination.isClaimedBy(getUuid()))
|
.filter(destination -> destination.isClaimedBy(getUuid()))
|
||||||
|
@ -229,7 +229,10 @@ public class PortalSpell extends AbstractSpell implements PlacementControlSpell.
|
||||||
@Override
|
@Override
|
||||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||||
super.toNBT(compound, lookup);
|
super.toNBT(compound, lookup);
|
||||||
compound.putUuid("targetPortalId", targetPortalId.get());
|
@Nullable UUID otherPortalUuid = targetPortalId.getOrDefault(Util.NIL_UUID);
|
||||||
|
if (!Util.NIL_UUID.equals(otherPortalUuid)) {
|
||||||
|
compound.putUuid("targetPortalId", otherPortalUuid);
|
||||||
|
}
|
||||||
compound.put("teleportationTarget", teleportationTarget.toNBT(lookup));
|
compound.put("teleportationTarget", teleportationTarget.toNBT(lookup));
|
||||||
compound.putFloat("pitch", getPitch());
|
compound.putFloat("pitch", getPitch());
|
||||||
compound.putFloat("yaw", getYaw());
|
compound.putFloat("yaw", getYaw());
|
||||||
|
|
|
@ -140,6 +140,11 @@ public class DataTracker {
|
||||||
return tracker.get(this);
|
return tracker.get(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public T getOrDefault(T def) {
|
||||||
|
T t = get();
|
||||||
|
return t == null ? def : t;
|
||||||
|
}
|
||||||
|
|
||||||
public void set(T t) {
|
public void set(T t) {
|
||||||
tracker.set(this, t);
|
tracker.set(this, t);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue