From d1b3e8702acc475c28fbfeceda7793e24ed3bda6 Mon Sep 17 00:00:00 2001 From: Sollace Date: Thu, 23 May 2024 20:23:44 +0100 Subject: [PATCH] Fix build --- .../magic/spell/AbstractDelegatingSpell.java | 37 ++++----- .../ability/magic/spell/EmptySpell.java | 77 +++++++++++++++++++ .../unicopia/entity/behaviour/Disguise.java | 11 +-- 3 files changed, 98 insertions(+), 27 deletions(-) create mode 100644 src/main/java/com/minelittlepony/unicopia/ability/magic/spell/EmptySpell.java diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/AbstractDelegatingSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/AbstractDelegatingSpell.java index b65acecf..ffd032c7 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/AbstractDelegatingSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/AbstractDelegatingSpell.java @@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.ability.magic.spell; import java.util.*; import java.util.stream.Stream; +import com.google.common.base.MoreObjects; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.SpellPredicate; import com.minelittlepony.unicopia.ability.magic.spell.effect.CustomisedSpellType; @@ -28,6 +29,10 @@ public abstract class AbstractDelegatingSpell implements Spell { return delegate.get(); } + private Spell getOrEmpty() { + return MoreObjects.firstNonNull(delegate.get(), EmptySpell.INSTANCE); + } + @Override public boolean equalsOrContains(UUID id) { return Spell.super.equalsOrContains(id) || delegate.equalsOrContains(id); @@ -50,26 +55,22 @@ public abstract class AbstractDelegatingSpell implements Spell { @Override public void setDead() { - if (delegate.get() != null) { - delegate.get().setDead(); - } + getOrEmpty().setDead(); } @Override public void tickDying(Caster caster) { - if (delegate.get() != null) { - delegate.get().tickDying(caster); - } + getOrEmpty().tickDying(caster); } @Override public boolean isDead() { - return delegate.get() == null; + return getOrEmpty().isDead(); } @Override public boolean isDying() { - return delegate.get() != null && delegate.get().isDying(); + return getOrEmpty().isDying(); } @Override @@ -84,12 +85,12 @@ public abstract class AbstractDelegatingSpell implements Spell { @Override public boolean isHidden() { - return hidden || (delegate.get() != null && delegate.get().isHidden()); + return hidden || getOrEmpty().isHidden(); } @Override public void setHidden(boolean hidden) { - this.hidden = hidden; + getOrEmpty().setHidden(hidden); } @Override @@ -106,21 +107,17 @@ public abstract class AbstractDelegatingSpell implements Spell { if (!caster.isClient()) { Ether.get(caster.asWorld()).remove(this, caster); } - if (delegate.get() instanceof Spell s) { - s.destroy(caster); - } + getOrEmpty().destroy(caster); } @Override public boolean tick(Caster source, Situation situation) { - if (delegate.get() instanceof Spell s) { - if (s.isDying()) { - s.tickDying(source); - return !s.isDead(); - } - return s.tick(source, situation) && !isDead(); + Spell s = getOrEmpty(); + if (s.isDying()) { + s.tickDying(source); + return !s.isDead(); } - return !isDead(); + return s.tick(source, situation); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/EmptySpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/EmptySpell.java new file mode 100644 index 00000000..202c3830 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/EmptySpell.java @@ -0,0 +1,77 @@ +package com.minelittlepony.unicopia.ability.magic.spell; + +import java.util.UUID; + +import com.minelittlepony.unicopia.ability.magic.Caster; +import com.minelittlepony.unicopia.ability.magic.spell.effect.CustomisedSpellType; +import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; + +import net.minecraft.nbt.NbtCompound; +import net.minecraft.util.Util; + +public final class EmptySpell implements Spell { + public static final EmptySpell INSTANCE = new EmptySpell(); + + private EmptySpell() {} + + @Override + public void toNBT(NbtCompound compound) { } + + @Override + public void fromNBT(NbtCompound compound) { } + + @Override + public CustomisedSpellType getTypeAndTraits() { + return SpellType.EMPTY_KEY.withTraits(); + } + + @Override + public UUID getUuid() { + return Util.NIL_UUID; + } + + @Override + public void setDead() { } + + @Override + public boolean isDead() { + return true; + } + + @Override + public boolean isDying() { + return false; + } + + @Override + public boolean isDirty() { + return false; + } + + @Override + public boolean tick(Caster caster, Situation situation) { + return false; + } + + @Override + public void tickDying(Caster caster) { } + + @Override + public void setDirty() { } + + @Override + public boolean isHidden() { + return true; + } + + @Override + public void setHidden(boolean hidden) { } + + @Override + public void destroy(Caster caster) { } + + @Override + public String toString() { + return "EmptySpell{}"; + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/Disguise.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/Disguise.java index 7041b6e7..b34606f7 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/Disguise.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/Disguise.java @@ -64,11 +64,10 @@ public interface Disguise extends FlightType.Provider, PlayerDimensions.Provider @SuppressWarnings("unchecked") default boolean update(Caster caster, boolean tick) { - if (!(caster instanceof Living)) { + if (!(caster instanceof Living source)) { return false; } - Living source = (Living)caster; LivingEntity owner = source.asEntity(); if (owner == null) { @@ -89,8 +88,8 @@ public interface Disguise extends FlightType.Provider, PlayerDimensions.Provider entity.noClip = true; - if (entity instanceof MobEntity) { - ((MobEntity)entity).setAiDisabled(true); + if (entity instanceof MobEntity mob) { + mob.setAiDisabled(true); } entity.setInvisible(false); @@ -117,9 +116,7 @@ public interface Disguise extends FlightType.Provider, PlayerDimensions.Provider behaviour.update(source, entity, this); - if (source instanceof Pony) { - Pony player = (Pony)source; - + if (source instanceof Pony player) { source.asEntity().setInvisible(true); player.setInvisible(true);