Fixed player position messed up when mounting a boat whilst flying

Players can now fly from boats again.
Fixes #377
This commit is contained in:
Sollace 2024-09-16 18:12:58 +01:00
parent afc8a87965
commit 6a36249d68
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
2 changed files with 12 additions and 1 deletions

View file

@ -11,6 +11,7 @@ import com.minelittlepony.unicopia.entity.Living;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3d;
public class ToggleFlightAbility implements Ability<Hit> { public class ToggleFlightAbility implements Ability<Hit> {
@ -27,7 +28,7 @@ public class ToggleFlightAbility implements Ability<Hit> {
@Nullable @Nullable
@Override @Override
public Optional<Hit> prepare(Pony player) { public Optional<Hit> prepare(Pony player) {
return Hit.of(!player.asEntity().hasVehicle() && !player.asEntity().isCreative() && !player.getPhysics().getFlightType().isGrounded()); return Hit.of(!player.asEntity().isCreative() && !player.getPhysics().getFlightType().isGrounded());
} }
@Override @Override
@ -59,6 +60,11 @@ public class ToggleFlightAbility implements Ability<Hit> {
player.subtractEnergyCost(1); player.subtractEnergyCost(1);
if (!player.getPhysics().isFlying()) { 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); player.asEntity().addVelocity(0, player.getPhysics().getGravitySignum() * 0.7F, 0);
Living.updateVelocity(player.asEntity()); Living.updateVelocity(player.asEntity());
player.getPhysics().startFlying(true); player.getPhysics().startFlying(true);

View file

@ -52,4 +52,9 @@ abstract class MixinServerPlayerEntity extends PlayerEntity implements ScreenHan
private void onUpdateKilledAdvancementCriterion(Entity entityKilled, int score, DamageSource damageSource, CallbackInfo info) { private void onUpdateKilledAdvancementCriterion(Entity entityKilled, int score, DamageSource damageSource, CallbackInfo info) {
get().onKill(entityKilled, damageSource); get().onKill(entityKilled, damageSource);
} }
@Inject(method = "startRiding(Lnet/minecraft/entity/Entity;Z)Z", at = @At("HEAD"))
private void onStartRiding(Entity entity, boolean force, CallbackInfoReturnable<Boolean> info) {
get().getPhysics().cancelFlight(true);
}
} }