Some minor restructuring

This commit is contained in:
Sollace 2020-10-09 16:45:27 +02:00
parent cef123e162
commit e3e374dd87
7 changed files with 28 additions and 43 deletions

View file

@ -1,5 +1,7 @@
package com.minelittlepony.unicopia; package com.minelittlepony.unicopia;
import com.minelittlepony.unicopia.entity.player.Pony;
public enum FlightType { public enum FlightType {
NONE, NONE,
CREATIVE, CREATIVE,
@ -21,4 +23,13 @@ public enum FlightType {
public boolean canFlySurvival() { public boolean canFlySurvival() {
return canFly() && !canFlyCreative(); return canFly() && !canFlyCreative();
} }
/**
* Predicate for abilities to control whether a player can fly.
*
* This overrides what the race specifies.
*/
public interface Provider {
FlightType getFlightType(Pony player);
}
} }

View file

@ -1,18 +0,0 @@
package com.minelittlepony.unicopia.ability;
import java.util.Optional;
import com.minelittlepony.unicopia.entity.player.Pony;
import net.minecraft.entity.EntityDimensions;
/**
* Predicate for abilities to control what the player's physical height is.
*
* This overrides the default.
*/
public interface DimensionsPredicate {
float getTargetEyeHeight(Pony player);
Optional<EntityDimensions> getTargetDimensions(Pony player);
}

View file

@ -1,13 +0,0 @@
package com.minelittlepony.unicopia.ability;
import com.minelittlepony.unicopia.FlightType;
import com.minelittlepony.unicopia.entity.player.Pony;
/**
* Predicate for abilities to control whether a player can fly.
*
* This overrides what the race specifies.
*/
public interface FlightPredicate {
FlightType getFlightType(Pony player);
}

View file

@ -5,7 +5,7 @@ package com.minelittlepony.unicopia.ability.magic;
*/ */
public interface Attached extends Spell { public interface Attached extends Spell {
/** /**
* Called every tick when attached to a player. * Called every tick when attached to a living entity.
* *
* @param source The entity we are currently attached to. * @param source The entity we are currently attached to.
* @return true to keep alive * @return true to keep alive
@ -13,7 +13,8 @@ public interface Attached extends Spell {
boolean updateOnPerson(Caster<?> caster); boolean updateOnPerson(Caster<?> caster);
/** /**
* Called every tick when attached to a player. Used to apply particle effects. * Called every tick when attached to a living entity.
* Used to apply particle effects.
* Is only called on the client side. * Is only called on the client side.
* *
* @param source The entity we are currently attached to. * @param source The entity we are currently attached to.

View file

@ -7,8 +7,6 @@ import javax.annotation.Nullable;
import com.minelittlepony.unicopia.Affinity; import com.minelittlepony.unicopia.Affinity;
import com.minelittlepony.unicopia.FlightType; import com.minelittlepony.unicopia.FlightType;
import com.minelittlepony.unicopia.Owned; import com.minelittlepony.unicopia.Owned;
import com.minelittlepony.unicopia.ability.FlightPredicate;
import com.minelittlepony.unicopia.ability.DimensionsPredicate;
import com.minelittlepony.unicopia.ability.magic.Attached; import com.minelittlepony.unicopia.ability.magic.Attached;
import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.Caster;
import com.minelittlepony.unicopia.ability.magic.Spell; import com.minelittlepony.unicopia.ability.magic.Spell;
@ -16,6 +14,7 @@ import com.minelittlepony.unicopia.ability.magic.Suppressable;
import com.minelittlepony.unicopia.entity.behaviour.EntityBehaviour; import com.minelittlepony.unicopia.entity.behaviour.EntityBehaviour;
import com.minelittlepony.unicopia.entity.behaviour.Disguise; import com.minelittlepony.unicopia.entity.behaviour.Disguise;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.entity.player.PlayerDimensions;
import com.minelittlepony.unicopia.particle.MagicParticleEffect; import com.minelittlepony.unicopia.particle.MagicParticleEffect;
import com.minelittlepony.unicopia.particle.UParticles; import com.minelittlepony.unicopia.particle.UParticles;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@ -27,7 +26,7 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.ProjectileEntity; import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
public class DisguiseSpell extends AbstractSpell implements Attached, Suppressable, FlightPredicate, DimensionsPredicate { public class DisguiseSpell extends AbstractSpell implements Attached, Suppressable, FlightType.Provider, PlayerDimensions.Provider {
private final Disguise disguise = new Disguise(); private final Disguise disguise = new Disguise();

View file

@ -4,7 +4,6 @@ import java.util.Optional;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.minelittlepony.unicopia.ability.DimensionsPredicate;
import com.minelittlepony.unicopia.ability.magic.Spell; import com.minelittlepony.unicopia.ability.magic.Spell;
import net.minecraft.entity.EntityDimensions; import net.minecraft.entity.EntityDimensions;
@ -64,13 +63,19 @@ public final class PlayerDimensions {
return defaultEyeHeight; return defaultEyeHeight;
} }
Optional<DimensionsPredicate> getPredicate() { Optional<Provider> getPredicate() {
if (pony.hasSpell()) { if (pony.hasSpell()) {
Spell effect = pony.getSpell(true); Spell effect = pony.getSpell(true);
if (!effect.isDead() && effect instanceof DimensionsPredicate) { if (!effect.isDead() && effect instanceof Provider) {
return Optional.of(((DimensionsPredicate)effect)); return Optional.of(((Provider)effect));
} }
} }
return Optional.empty(); return Optional.empty();
} }
public interface Provider {
float getTargetEyeHeight(Pony player);
Optional<EntityDimensions> getTargetDimensions(Pony player);
}
} }

View file

@ -3,7 +3,6 @@ package com.minelittlepony.unicopia.entity.player;
import com.minelittlepony.unicopia.FlightType; import com.minelittlepony.unicopia.FlightType;
import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.ability.FlightPredicate;
import com.minelittlepony.unicopia.ability.magic.Spell; import com.minelittlepony.unicopia.ability.magic.Spell;
import com.minelittlepony.unicopia.entity.EntityPhysics; import com.minelittlepony.unicopia.entity.EntityPhysics;
import com.minelittlepony.unicopia.entity.player.MagicReserves.Bar; import com.minelittlepony.unicopia.entity.player.MagicReserves.Bar;
@ -302,8 +301,8 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
if (pony.hasSpell()) { if (pony.hasSpell()) {
Spell effect = pony.getSpell(true); Spell effect = pony.getSpell(true);
if (!effect.isDead() && effect instanceof FlightPredicate) { if (!effect.isDead() && effect instanceof FlightType.Provider) {
return ((FlightPredicate)effect).getFlightType(pony); return ((FlightType.Provider)effect).getFlightType(pony);
} }
} }
@ -343,4 +342,5 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
pony.getMaster().calculateDimensions(); pony.getMaster().calculateDimensions();
} }
} }