Minor fixes to Ether and some owned style changes

This commit is contained in:
Sollace 2024-04-08 16:53:01 +01:00
parent 12bc0b6973
commit e465a21839
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
6 changed files with 28 additions and 18 deletions

View file

@ -53,7 +53,7 @@ public interface Owned<E extends Entity> {
}
default boolean hasCommonOwner(Owned<?> sibling) {
return getMasterId().isPresent() && getMasterId().equals(sibling.getMasterId());
return getMasterId().equals(sibling.getMasterId());
}
interface Mutable<E extends Entity> {

View file

@ -42,8 +42,8 @@ public interface WeaklyOwned<E extends Entity> extends Owned<E>, WorldConvertabl
@Override
@SuppressWarnings("unchecked")
default void setMaster(Owned<? extends E> sibling) {
if (sibling instanceof WeaklyOwned) {
getMasterReference().copyFrom(((WeaklyOwned<E>)sibling).getMasterReference());
if (sibling instanceof WeaklyOwned w) {
getMasterReference().copyFrom(w.getMasterReference());
} else {
setMaster(sibling.getMaster());
}

View file

@ -197,7 +197,7 @@ public class NecromancySpell extends AbstractAreaEffectSpell implements Projecti
}
Equine.of(minion).filter(eq -> eq instanceof Creature).ifPresent(eq -> {
((Creature)eq).setMaster(source.getMaster());
((Creature)eq).setMaster(source);
if (source.asWorld().random.nextFloat() < source.getCorruption().getScaled(1)) {
((Creature)eq).setDiscorded(true);
}

View file

@ -57,7 +57,7 @@ public class PortalSpell extends AbstractSpell implements PlaceableSpell.Placeme
}
public boolean isLinked() {
return teleportationTarget.getTarget().isPresent();
return teleportationTarget.isSet();
}
public Optional<EntityReference.EntityValues<Entity>> getTarget() {
@ -85,7 +85,7 @@ public class PortalSpell extends AbstractSpell implements PlaceableSpell.Placeme
}
@SuppressWarnings("unchecked")
private Optional<Ether.Entry<PortalSpell>> getTarget(Caster<?> source) {
private Optional<Ether.Entry<PortalSpell>> getDestination(Caster<?> source) {
return getTarget().map(target -> Ether.get(source.asWorld()).get((SpellType<PortalSpell>)getType(), target, targetPortalId));
}
@ -98,13 +98,12 @@ public class PortalSpell extends AbstractSpell implements PlaceableSpell.Placeme
@Override
public boolean tick(Caster<?> source, Situation situation) {
if (situation == Situation.GROUND) {
if (source.isClient()) {
source.spawnParticles(particleArea, 5, pos -> {
source.addParticle(ParticleTypes.ELECTRIC_SPARK, pos, Vec3d.ZERO);
});
} else {
getTarget().ifPresent(target -> {
teleportationTarget.getTarget().ifPresent(target -> {
if (Ether.get(source.asWorld()).get(getType(), target, targetPortalId) == null) {
Unicopia.LOGGER.debug("Lost sibling, breaking connection to " + target.uuid());
teleportationTarget.set(null);
@ -113,16 +112,17 @@ public class PortalSpell extends AbstractSpell implements PlaceableSpell.Placeme
}
});
getTarget(source).ifPresentOrElse(
getDestination(source).ifPresentOrElse(
entry -> tickWithTargetLink(source, entry),
() -> findLink(source)
);
}
var entry = Ether.get(source.asWorld()).getOrCreate(this, source);
Ether ether = Ether.get(source.asWorld());
var entry = ether.getOrCreate(this, source);
entry.pitch = pitch;
entry.yaw = yaw;
Ether.get(source.asWorld()).markDirty();
ether.markDirty();
}
return !isDead();
@ -185,8 +185,7 @@ public class PortalSpell extends AbstractSpell implements PlaceableSpell.Placeme
}
Ether.get(source.asWorld()).anyMatch(getType(), entry -> {
if (entry.isAvailable() && !entry.entity.referenceEquals(source.asEntity()) && entry.entity.isSet()) {
entry.setTaken(true);
if (!entry.entity.referenceEquals(source.asEntity()) && entry.claim()) {
teleportationTarget.copyFrom(entry.entity);
targetPortalId = entry.getSpellId();
setDirty();
@ -216,9 +215,8 @@ public class PortalSpell extends AbstractSpell implements PlaceableSpell.Placeme
@Override
protected void onDestroyed(Caster<?> caster) {
Ether ether = Ether.get(caster.asWorld());
ether.remove(getType(), caster);
getTarget(caster).ifPresent(e -> e.setTaken(false));
Ether.get(caster.asWorld()).remove(getType(), caster);
getDestination(caster).ifPresent(Ether.Entry::release);
}
@Override

View file

@ -22,7 +22,7 @@ import net.minecraft.world.World;
/**
* An indirect reference to an entity by its unique id.
* Used to store the 'owner' reference for certain objects that allows them to\
* Used to store the 'owner' reference for certain objects that allows them to
* remember who they belong to even when the entity has been unloaded.
*
* Will also remember the position and certain attributes of the owner.

View file

@ -211,7 +211,7 @@ public class Ether extends PersistentState {
}
public boolean isAvailable() {
return !isDead() && !taken;
return !isDead() && !taken && entity.isSet();
}
public void setTaken(boolean taken) {
@ -219,6 +219,18 @@ public class Ether extends PersistentState {
markDirty();
}
public void release() {
setTaken(false);
}
public boolean claim() {
if (isAvailable()) {
setTaken(true);
return true;
}
return false;
}
@Nullable
public T getSpell() {
if (removed) {