mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-17 10:24:23 +01:00
Fixed multiple spell entities being spawned when far away
This commit is contained in:
parent
8d2639b69b
commit
a32a14f134
2 changed files with 11 additions and 4 deletions
|
@ -79,7 +79,7 @@ public class PlaceableSpell extends AbstractDelegatingSpell {
|
|||
setDirty();
|
||||
}
|
||||
|
||||
if (getSpellEntity(source).isEmpty()) {
|
||||
if (getWorld(source).map(castEntity::isUnlinked).orElse(false)) {
|
||||
CastSpellEntity entity = UEntities.CAST_SPELL.create(source.getReferenceWorld());
|
||||
Vec3d pos = castEntity.getPosition().orElse(source.getOriginVector());
|
||||
entity.updatePositionAndAngles(pos.x, pos.y, pos.z, 0, 0);
|
||||
|
@ -119,10 +119,13 @@ public class PlaceableSpell extends AbstractDelegatingSpell {
|
|||
super.onDestroyed(source);
|
||||
}
|
||||
|
||||
protected Optional<CastSpellEntity> getSpellEntity(Caster<?> source) {
|
||||
public Optional<CastSpellEntity> getSpellEntity(Caster<?> source) {
|
||||
return getWorld(source).map(castEntity::get);
|
||||
}
|
||||
|
||||
protected Optional<World> getWorld(Caster<?> source) {
|
||||
return Optional.ofNullable(dimension)
|
||||
.map(dim -> source.getReferenceWorld().getServer().getWorld(dimension))
|
||||
.map(castEntity::get);
|
||||
.map(dim -> source.getReferenceWorld().getServer().getWorld(dim));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -69,6 +69,10 @@ public class EntityReference<T extends Entity> implements NbtSerialisable {
|
|||
return entity != null && entity.getUuid().equals(uuid.orElse(null));
|
||||
}
|
||||
|
||||
public boolean isUnlinked(World world) {
|
||||
return getId().isEmpty() || getOrEmpty(world).map(e -> e.isRemoved()).orElse(false);
|
||||
}
|
||||
|
||||
public boolean isPresent(World world) {
|
||||
return getOrEmpty(world).isPresent();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue