Unicopia/src/main/java/com/minelittlepony/unicopia/ability/ToggleFlightAbility.java
Sollace d6286c7a00
Fixed player position messed up when mounting a boat whilst flying
Players can now fly from boats again.
Fixes #377
2024-10-08 15:30:56 +01:00

86 lines
2.5 KiB
Java

package com.minelittlepony.unicopia.ability;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.ability.data.Hit;
import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation;
import com.minelittlepony.unicopia.entity.Living;
import com.minelittlepony.unicopia.entity.player.Pony;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3d;
public class ToggleFlightAbility implements Ability<Hit> {
@Override
public int getWarmupTime(Pony player) {
return 0;
}
@Override
public int getCooldownTime(Pony player) {
return 0;
}
@Nullable
@Override
public Optional<Hit> prepare(Pony player) {
return Hit.of(!player.asEntity().isCreative() && !player.getPhysics().getFlightType().isGrounded());
}
@Override
public Hit.Serializer<Hit> getSerializer() {
return Hit.SERIALIZER;
}
@Override
public Identifier getIcon(Pony player) {
Identifier id = Abilities.REGISTRY.getId(this);
Race race = player.getObservedSpecies();
return new Identifier(id.getNamespace(), "textures/gui/ability/" + id.getPath()
+ (player.getPhysics().isFlying() ? "_land" : "_takeoff")
+ "_" + (race.isHuman() ? Race.EARTH : race).getId().getPath()
+ ".png");
}
@Override
public double getCostEstimate(Pony player) {
return 0;
}
@Override
public boolean apply(Pony player, Hit data) {
if (prepare(player).isEmpty()) {
return false;
}
player.subtractEnergyCost(1);
if (!player.getPhysics().isFlying()) {
if (player.asEntity().hasVehicle()) {
Vec3d pos = player.asEntity().getPos();
player.asEntity().stopRiding();
player.asEntity().setPosition(pos.getX(), pos.getY() + 0.25, pos.getZ());
}
player.asEntity().addVelocity(0, player.getPhysics().getGravitySignum() * 0.7F, 0);
Living.updateVelocity(player.asEntity());
player.getPhysics().startFlying(true);
} else {
player.getPhysics().cancelFlight(true);
}
player.setAnimation(Animation.SPREAD_WINGS, Animation.Recipient.ANYONE);
return true;
}
@Override
public void warmUp(Pony player, AbilitySlot slot) {
player.getMagicalReserves().getExertion().addPercent(6);
}
@Override
public void coolDown(Pony player, AbilitySlot slot) {
}
}