Fixed multiple spell entities being spawned when far away

This commit is contained in:
Sollace 2022-09-16 17:54:20 +02:00
parent 8d2639b69b
commit a32a14f134
2 changed files with 11 additions and 4 deletions

View file

@ -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

View file

@ -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();
}