mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Minor fixes to Ether and some owned style changes
This commit is contained in:
parent
12bc0b6973
commit
e465a21839
6 changed files with 28 additions and 18 deletions
|
@ -53,7 +53,7 @@ public interface Owned<E extends Entity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
default boolean hasCommonOwner(Owned<?> sibling) {
|
default boolean hasCommonOwner(Owned<?> sibling) {
|
||||||
return getMasterId().isPresent() && getMasterId().equals(sibling.getMasterId());
|
return getMasterId().equals(sibling.getMasterId());
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Mutable<E extends Entity> {
|
interface Mutable<E extends Entity> {
|
||||||
|
|
|
@ -42,8 +42,8 @@ public interface WeaklyOwned<E extends Entity> extends Owned<E>, WorldConvertabl
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
default void setMaster(Owned<? extends E> sibling) {
|
default void setMaster(Owned<? extends E> sibling) {
|
||||||
if (sibling instanceof WeaklyOwned) {
|
if (sibling instanceof WeaklyOwned w) {
|
||||||
getMasterReference().copyFrom(((WeaklyOwned<E>)sibling).getMasterReference());
|
getMasterReference().copyFrom(w.getMasterReference());
|
||||||
} else {
|
} else {
|
||||||
setMaster(sibling.getMaster());
|
setMaster(sibling.getMaster());
|
||||||
}
|
}
|
||||||
|
|
|
@ -197,7 +197,7 @@ public class NecromancySpell extends AbstractAreaEffectSpell implements Projecti
|
||||||
}
|
}
|
||||||
|
|
||||||
Equine.of(minion).filter(eq -> eq instanceof Creature).ifPresent(eq -> {
|
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)) {
|
if (source.asWorld().random.nextFloat() < source.getCorruption().getScaled(1)) {
|
||||||
((Creature)eq).setDiscorded(true);
|
((Creature)eq).setDiscorded(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class PortalSpell extends AbstractSpell implements PlaceableSpell.Placeme
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLinked() {
|
public boolean isLinked() {
|
||||||
return teleportationTarget.getTarget().isPresent();
|
return teleportationTarget.isSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<EntityReference.EntityValues<Entity>> getTarget() {
|
public Optional<EntityReference.EntityValues<Entity>> getTarget() {
|
||||||
|
@ -85,7 +85,7 @@ public class PortalSpell extends AbstractSpell implements PlaceableSpell.Placeme
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@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));
|
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
|
@Override
|
||||||
public boolean tick(Caster<?> source, Situation situation) {
|
public boolean tick(Caster<?> source, Situation situation) {
|
||||||
if (situation == Situation.GROUND) {
|
if (situation == Situation.GROUND) {
|
||||||
|
|
||||||
if (source.isClient()) {
|
if (source.isClient()) {
|
||||||
source.spawnParticles(particleArea, 5, pos -> {
|
source.spawnParticles(particleArea, 5, pos -> {
|
||||||
source.addParticle(ParticleTypes.ELECTRIC_SPARK, pos, Vec3d.ZERO);
|
source.addParticle(ParticleTypes.ELECTRIC_SPARK, pos, Vec3d.ZERO);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
getTarget().ifPresent(target -> {
|
teleportationTarget.getTarget().ifPresent(target -> {
|
||||||
if (Ether.get(source.asWorld()).get(getType(), target, targetPortalId) == null) {
|
if (Ether.get(source.asWorld()).get(getType(), target, targetPortalId) == null) {
|
||||||
Unicopia.LOGGER.debug("Lost sibling, breaking connection to " + target.uuid());
|
Unicopia.LOGGER.debug("Lost sibling, breaking connection to " + target.uuid());
|
||||||
teleportationTarget.set(null);
|
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),
|
entry -> tickWithTargetLink(source, entry),
|
||||||
() -> findLink(source)
|
() -> 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.pitch = pitch;
|
||||||
entry.yaw = yaw;
|
entry.yaw = yaw;
|
||||||
Ether.get(source.asWorld()).markDirty();
|
ether.markDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
return !isDead();
|
return !isDead();
|
||||||
|
@ -185,8 +185,7 @@ public class PortalSpell extends AbstractSpell implements PlaceableSpell.Placeme
|
||||||
}
|
}
|
||||||
|
|
||||||
Ether.get(source.asWorld()).anyMatch(getType(), entry -> {
|
Ether.get(source.asWorld()).anyMatch(getType(), entry -> {
|
||||||
if (entry.isAvailable() && !entry.entity.referenceEquals(source.asEntity()) && entry.entity.isSet()) {
|
if (!entry.entity.referenceEquals(source.asEntity()) && entry.claim()) {
|
||||||
entry.setTaken(true);
|
|
||||||
teleportationTarget.copyFrom(entry.entity);
|
teleportationTarget.copyFrom(entry.entity);
|
||||||
targetPortalId = entry.getSpellId();
|
targetPortalId = entry.getSpellId();
|
||||||
setDirty();
|
setDirty();
|
||||||
|
@ -216,9 +215,8 @@ public class PortalSpell extends AbstractSpell implements PlaceableSpell.Placeme
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroyed(Caster<?> caster) {
|
protected void onDestroyed(Caster<?> caster) {
|
||||||
Ether ether = Ether.get(caster.asWorld());
|
Ether.get(caster.asWorld()).remove(getType(), caster);
|
||||||
ether.remove(getType(), caster);
|
getDestination(caster).ifPresent(Ether.Entry::release);
|
||||||
getTarget(caster).ifPresent(e -> e.setTaken(false));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -22,7 +22,7 @@ import net.minecraft.world.World;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An indirect reference to an entity by its unique id.
|
* 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.
|
* remember who they belong to even when the entity has been unloaded.
|
||||||
*
|
*
|
||||||
* Will also remember the position and certain attributes of the owner.
|
* Will also remember the position and certain attributes of the owner.
|
||||||
|
|
|
@ -211,7 +211,7 @@ public class Ether extends PersistentState {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
return !isDead() && !taken;
|
return !isDead() && !taken && entity.isSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTaken(boolean taken) {
|
public void setTaken(boolean taken) {
|
||||||
|
@ -219,6 +219,18 @@ public class Ether extends PersistentState {
|
||||||
markDirty();
|
markDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void release() {
|
||||||
|
setTaken(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean claim() {
|
||||||
|
if (isAvailable()) {
|
||||||
|
setTaken(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public T getSpell() {
|
public T getSpell() {
|
||||||
if (removed) {
|
if (removed) {
|
||||||
|
|
Loading…
Reference in a new issue