mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-01 11:36:43 +01:00
Slightly clean up flight and dimensions predicates
This commit is contained in:
parent
2cb57f85f2
commit
bb50b20be4
4 changed files with 27 additions and 14 deletions
|
@ -1,11 +1,10 @@
|
||||||
package com.minelittlepony.unicopia;
|
package com.minelittlepony.unicopia;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
|
||||||
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.sound.SoundEvent;
|
import net.minecraft.sound.SoundEvent;
|
||||||
|
|
||||||
public enum FlightType {
|
public enum FlightType {
|
||||||
|
UNSET,
|
||||||
NONE,
|
NONE,
|
||||||
AVIAN,
|
AVIAN,
|
||||||
INSECTOID,
|
INSECTOID,
|
||||||
|
@ -23,6 +22,10 @@ public enum FlightType {
|
||||||
return this == ARTIFICIAL;
|
return this == ARTIFICIAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isPresent() {
|
||||||
|
return this != UNSET;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean canFly() {
|
public boolean canFly() {
|
||||||
return !isGrounded();
|
return !isGrounded();
|
||||||
}
|
}
|
||||||
|
@ -41,6 +44,6 @@ public enum FlightType {
|
||||||
* This overrides what the race specifies.
|
* This overrides what the race specifies.
|
||||||
*/
|
*/
|
||||||
public interface Provider {
|
public interface Provider {
|
||||||
FlightType getFlightType(Pony player);
|
FlightType getFlightType();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,21 +205,22 @@ public class DisguiseSpell extends AbstractSpell implements Suppressable, Flight
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FlightType getFlightType(Pony player) {
|
public FlightType getFlightType() {
|
||||||
if (isSuppressed() || !disguise.isPresent()) {
|
return getAppearance().map(Disguise::getFlightType).orElse(FlightType.UNSET);
|
||||||
return player.getSpecies().getFlightType();
|
}
|
||||||
}
|
|
||||||
return disguise.getFlightType();
|
public Optional<Disguise> getAppearance() {
|
||||||
|
return isSuppressed() ? Optional.empty() : Optional.ofNullable(disguise);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Float> getTargetEyeHeight(Pony player) {
|
public Optional<Float> getTargetEyeHeight(Pony player) {
|
||||||
return isSuppressed() ? Optional.empty() : disguise.getStandingEyeHeight();
|
return getAppearance().flatMap(d -> d.getTargetEyeHeight(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<EntityDimensions> getTargetDimensions(Pony player) {
|
public Optional<EntityDimensions> getTargetDimensions(Pony player) {
|
||||||
return isSuppressed() ? Optional.empty() : disguise.getDimensions();
|
return getAppearance().flatMap(d -> d.getTargetDimensions(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
static abstract class PlayerAccess extends PlayerEntity {
|
static abstract class PlayerAccess extends PlayerEntity {
|
||||||
|
|
|
@ -17,6 +17,7 @@ import com.minelittlepony.unicopia.Owned;
|
||||||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||||
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
|
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
|
||||||
import com.minelittlepony.unicopia.entity.player.PlayerAttributes;
|
import com.minelittlepony.unicopia.entity.player.PlayerAttributes;
|
||||||
|
import com.minelittlepony.unicopia.entity.player.PlayerDimensions;
|
||||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||||
import com.minelittlepony.unicopia.projectile.ProjectileUtil;
|
import com.minelittlepony.unicopia.projectile.ProjectileUtil;
|
||||||
import com.minelittlepony.unicopia.util.NbtSerialisable;
|
import com.minelittlepony.unicopia.util.NbtSerialisable;
|
||||||
|
@ -49,7 +50,7 @@ import net.minecraft.util.shape.VoxelShape;
|
||||||
import net.minecraft.util.shape.VoxelShapes;
|
import net.minecraft.util.shape.VoxelShapes;
|
||||||
import net.minecraft.world.WorldAccess;
|
import net.minecraft.world.WorldAccess;
|
||||||
|
|
||||||
public class Disguise implements NbtSerialisable {
|
public class Disguise implements NbtSerialisable, PlayerDimensions.Provider, FlightType.Provider {
|
||||||
private static final Optional<Float> BLOCK_HEIGHT = Optional.of(0.5F);
|
private static final Optional<Float> BLOCK_HEIGHT = Optional.of(0.5F);
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
@ -206,7 +207,12 @@ public class Disguise implements NbtSerialisable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public FlightType getFlightType() {
|
public FlightType getFlightType() {
|
||||||
|
if (!isPresent()) {
|
||||||
|
return FlightType.UNSET;
|
||||||
|
}
|
||||||
|
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
return FlightType.NONE;
|
return FlightType.NONE;
|
||||||
}
|
}
|
||||||
|
@ -231,7 +237,8 @@ public class Disguise implements NbtSerialisable {
|
||||||
return FlightType.NONE;
|
return FlightType.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<Float> getStandingEyeHeight() {
|
@Override
|
||||||
|
public Optional<Float> getTargetEyeHeight(Pony player) {
|
||||||
if (entity != null) {
|
if (entity != null) {
|
||||||
if (entity instanceof FallingBlockEntity) {
|
if (entity instanceof FallingBlockEntity) {
|
||||||
return BLOCK_HEIGHT;
|
return BLOCK_HEIGHT;
|
||||||
|
@ -255,7 +262,8 @@ public class Disguise implements NbtSerialisable {
|
||||||
return EntityBehaviour.forEntity(entity).getCameraDistance(entity, player);
|
return EntityBehaviour.forEntity(entity).getCameraDistance(entity, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<EntityDimensions> getDimensions() {
|
@Override
|
||||||
|
public Optional<EntityDimensions> getTargetDimensions(Pony player) {
|
||||||
return dimensions = EntityBehaviour.forEntity(entity).getDimensions(entity, dimensions);
|
return dimensions = EntityBehaviour.forEntity(entity).getDimensions(entity, dimensions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -134,7 +134,8 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
|
||||||
|
|
||||||
return pony.getSpellSlot().get(true)
|
return pony.getSpellSlot().get(true)
|
||||||
.filter(effect -> !effect.isDead() && effect instanceof FlightType.Provider)
|
.filter(effect -> !effect.isDead() && effect instanceof FlightType.Provider)
|
||||||
.map(effect -> ((FlightType.Provider)effect).getFlightType(pony))
|
.map(effect -> ((FlightType.Provider)effect).getFlightType())
|
||||||
|
.filter(FlightType::isPresent)
|
||||||
.orElse(pony.getSpecies().getFlightType());
|
.orElse(pony.getSpecies().getFlightType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue