Fix build

This commit is contained in:
Sollace 2024-05-23 20:23:44 +01:00
parent 6175605069
commit d1b3e8702a
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
3 changed files with 98 additions and 27 deletions

View file

@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.ability.magic.spell;
import java.util.*; import java.util.*;
import java.util.stream.Stream; import java.util.stream.Stream;
import com.google.common.base.MoreObjects;
import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.Caster;
import com.minelittlepony.unicopia.ability.magic.SpellPredicate; import com.minelittlepony.unicopia.ability.magic.SpellPredicate;
import com.minelittlepony.unicopia.ability.magic.spell.effect.CustomisedSpellType; import com.minelittlepony.unicopia.ability.magic.spell.effect.CustomisedSpellType;
@ -28,6 +29,10 @@ public abstract class AbstractDelegatingSpell implements Spell {
return delegate.get(); return delegate.get();
} }
private Spell getOrEmpty() {
return MoreObjects.firstNonNull(delegate.get(), EmptySpell.INSTANCE);
}
@Override @Override
public boolean equalsOrContains(UUID id) { public boolean equalsOrContains(UUID id) {
return Spell.super.equalsOrContains(id) || delegate.equalsOrContains(id); return Spell.super.equalsOrContains(id) || delegate.equalsOrContains(id);
@ -50,26 +55,22 @@ public abstract class AbstractDelegatingSpell implements Spell {
@Override @Override
public void setDead() { public void setDead() {
if (delegate.get() != null) { getOrEmpty().setDead();
delegate.get().setDead();
}
} }
@Override @Override
public void tickDying(Caster<?> caster) { public void tickDying(Caster<?> caster) {
if (delegate.get() != null) { getOrEmpty().tickDying(caster);
delegate.get().tickDying(caster);
}
} }
@Override @Override
public boolean isDead() { public boolean isDead() {
return delegate.get() == null; return getOrEmpty().isDead();
} }
@Override @Override
public boolean isDying() { public boolean isDying() {
return delegate.get() != null && delegate.get().isDying(); return getOrEmpty().isDying();
} }
@Override @Override
@ -84,12 +85,12 @@ public abstract class AbstractDelegatingSpell implements Spell {
@Override @Override
public boolean isHidden() { public boolean isHidden() {
return hidden || (delegate.get() != null && delegate.get().isHidden()); return hidden || getOrEmpty().isHidden();
} }
@Override @Override
public void setHidden(boolean hidden) { public void setHidden(boolean hidden) {
this.hidden = hidden; getOrEmpty().setHidden(hidden);
} }
@Override @Override
@ -106,21 +107,17 @@ public abstract class AbstractDelegatingSpell implements Spell {
if (!caster.isClient()) { if (!caster.isClient()) {
Ether.get(caster.asWorld()).remove(this, caster); Ether.get(caster.asWorld()).remove(this, caster);
} }
if (delegate.get() instanceof Spell s) { getOrEmpty().destroy(caster);
s.destroy(caster);
}
} }
@Override @Override
public boolean tick(Caster<?> source, Situation situation) { public boolean tick(Caster<?> source, Situation situation) {
if (delegate.get() instanceof Spell s) { Spell s = getOrEmpty();
if (s.isDying()) { if (s.isDying()) {
s.tickDying(source); s.tickDying(source);
return !s.isDead(); return !s.isDead();
} }
return s.tick(source, situation) && !isDead(); return s.tick(source, situation);
}
return !isDead();
} }
@Override @Override

View file

@ -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{}";
}
}

View file

@ -64,11 +64,10 @@ public interface Disguise extends FlightType.Provider, PlayerDimensions.Provider
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
default boolean update(Caster<?> caster, boolean tick) { default boolean update(Caster<?> caster, boolean tick) {
if (!(caster instanceof Living)) { if (!(caster instanceof Living<?> source)) {
return false; return false;
} }
Living<?> source = (Living<?>)caster;
LivingEntity owner = source.asEntity(); LivingEntity owner = source.asEntity();
if (owner == null) { if (owner == null) {
@ -89,8 +88,8 @@ public interface Disguise extends FlightType.Provider, PlayerDimensions.Provider
entity.noClip = true; entity.noClip = true;
if (entity instanceof MobEntity) { if (entity instanceof MobEntity mob) {
((MobEntity)entity).setAiDisabled(true); mob.setAiDisabled(true);
} }
entity.setInvisible(false); entity.setInvisible(false);
@ -117,9 +116,7 @@ public interface Disguise extends FlightType.Provider, PlayerDimensions.Provider
behaviour.update(source, entity, this); behaviour.update(source, entity, this);
if (source instanceof Pony) { if (source instanceof Pony player) {
Pony player = (Pony)source;
source.asEntity().setInvisible(true); source.asEntity().setInvisible(true);
player.setInvisible(true); player.setInvisible(true);