mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-01 11:36:43 +01:00
Fixed pegasi not taking fall damage when they're supposed to
This commit is contained in:
parent
c9ee710ab5
commit
76667f95ac
4 changed files with 40 additions and 38 deletions
|
@ -71,7 +71,7 @@ public final class PlayerDimensions {
|
|||
}
|
||||
}
|
||||
|
||||
if (physics.isFlying && physics.isRainboom()) {
|
||||
if (physics.isFlyingSurvival && physics.isRainboom()) {
|
||||
return 0.5F;
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ public final class PlayerDimensions {
|
|||
}
|
||||
}
|
||||
|
||||
if (physics.isFlying && physics.isRainboom()) {
|
||||
if (physics.isFlyingSurvival && physics.isRainboom()) {
|
||||
return defaultBodyHeight / 2;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,8 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
|
|||
public int ticksNextLevel = 0;
|
||||
public float flightExperience = 0;
|
||||
|
||||
public boolean isFlying = false;
|
||||
public boolean isFlyingEither = false;
|
||||
public boolean isFlyingSurvival = false;
|
||||
public boolean isRainbooming = false;
|
||||
|
||||
private double lastTickPosX = 0;
|
||||
|
@ -106,13 +107,18 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
|
|||
entity.abilities.allowFlying = checkCanFly();
|
||||
|
||||
if (!creative) {
|
||||
entity.abilities.flying |= entity.abilities.allowFlying && isFlying && !entity.isOnGround() && !entity.isTouchingWater();
|
||||
entity.abilities.flying |= entity.abilities.allowFlying && isFlyingEither;
|
||||
|
||||
if ((entity.isOnGround() && entity.isSneaking()) || entity.isTouchingWater()) {
|
||||
entity.abilities.flying = false;
|
||||
}
|
||||
}
|
||||
|
||||
isFlying = entity.abilities.flying && !creative;
|
||||
isFlyingSurvival = entity.abilities.flying && !creative;
|
||||
isFlyingEither = isFlyingSurvival || (creative && entity.abilities.flying);
|
||||
|
||||
if (!creative && !entity.isFallFlying()) {
|
||||
if (isFlying && !entity.hasVehicle()) {
|
||||
if (isFlyingSurvival && !entity.hasVehicle()) {
|
||||
|
||||
if (!isRainbooming && getHorizontalMotion(entity) > 0.2 && flightExperience < MAXIMUM_FLIGHT_EXPERIENCE) {
|
||||
flightExperience++;
|
||||
|
@ -179,7 +185,7 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
|
|||
|
||||
if (entity.isOnGround()) {
|
||||
entity.abilities.flying = false;
|
||||
isFlying = false;
|
||||
isFlyingSurvival = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -287,14 +293,14 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
|
|||
if (entity.abilities.allowFlying) {
|
||||
entity.abilities.flying |= flying;
|
||||
|
||||
isFlying = entity.abilities.flying;
|
||||
isFlyingSurvival = entity.abilities.flying;
|
||||
|
||||
if (isFlying) {
|
||||
if (isFlyingSurvival) {
|
||||
ticksNextLevel = 0;
|
||||
}
|
||||
} else {
|
||||
entity.abilities.flying = false;
|
||||
isFlying = false;
|
||||
isFlyingSurvival = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -303,7 +309,8 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
|
|||
super.toNBT(compound);
|
||||
compound.putInt("flightDuration", ticksNextLevel);
|
||||
compound.putFloat("flightExperience", flightExperience);
|
||||
compound.putBoolean("isFlying", isFlying);
|
||||
compound.putBoolean("isFlying", isFlyingSurvival);
|
||||
compound.putBoolean("isFlyingEither", isFlyingEither);
|
||||
compound.putBoolean("isRainbooming", isRainbooming);
|
||||
}
|
||||
|
||||
|
@ -312,7 +319,8 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
|
|||
super.fromNBT(compound);
|
||||
ticksNextLevel = compound.getInt("flightDuration");
|
||||
flightExperience = compound.getFloat("flightExperience");
|
||||
isFlying = compound.getBoolean("isFlying");
|
||||
isFlyingSurvival = compound.getBoolean("isFlying");
|
||||
isFlyingEither = compound.getBoolean("isFlyingEither");
|
||||
isRainbooming = compound.getBoolean("isRainbooming");
|
||||
|
||||
pony.getOwner().calculateDimensions();
|
||||
|
@ -320,7 +328,7 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
|
|||
|
||||
@Override
|
||||
public boolean isFlying() {
|
||||
return isFlying;
|
||||
return isFlyingSurvival;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -69,8 +69,6 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
|
|||
|
||||
private final Interpolator interpolator = new LinearInterpolator();
|
||||
|
||||
private float nextStepDistance = 1;
|
||||
|
||||
private final PlayerEntity entity;
|
||||
|
||||
private boolean dirty;
|
||||
|
@ -244,7 +242,8 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
|
|||
EntityAttributeInstance attr = entity.getAttributes().getCustomInstance(PlayerAttributes.ENTITY_GRAVTY_MODIFIER);
|
||||
|
||||
if (attr.hasModifier(PlayerAttributes.BAT_HANGING)) {
|
||||
gravity.isFlying = false;
|
||||
gravity.isFlyingSurvival = false;
|
||||
gravity.isFlyingEither = false;
|
||||
entity.abilities.flying = false;
|
||||
|
||||
if (Entity.squaredHorizontalLength(entity.getVelocity()) > 0.01 || entity.isSneaking() || !canHangAt()) {
|
||||
|
@ -280,11 +279,12 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
|
|||
prevSneaking = entity.isSneaking();
|
||||
}
|
||||
|
||||
public float onImpact(float distance) {
|
||||
if (getSpecies().canFly()) {
|
||||
distance = Math.max(0, distance - 5);
|
||||
public Optional<Float> onImpact(float distance, float damageMultiplier) {
|
||||
if (getSpecies().canFly() && !entity.isCreative() && !entity.isSpectator()) {
|
||||
return Optional.of(Math.max(0, distance - 5));
|
||||
}
|
||||
return distance;
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -323,17 +323,6 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
|
|||
return entity.getHealth() > 0;
|
||||
}
|
||||
|
||||
public boolean stepOnCloud() {
|
||||
if (entity.fallDistance > 1 || entity.distanceTraveled > nextStepDistance) {
|
||||
nextStepDistance = entity.distanceTraveled + 2;
|
||||
entity.fallDistance = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Optional<Text> trySleep(BlockPos pos) {
|
||||
|
||||
if (findAllSpellsInRange(10).filter(p -> p instanceof Pony).map(Pony.class::cast).map(Pony::getSpecies).anyMatch(r -> r.isEnemy(getSpecies()))) {
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.minelittlepony.unicopia.mixin;
|
|||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
|
@ -19,6 +18,7 @@ import net.minecraft.entity.LivingEntity;
|
|||
import net.minecraft.entity.attribute.DefaultAttributeContainer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.stat.Stats;
|
||||
import net.minecraft.util.Unit;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.GameMode;
|
||||
|
@ -33,12 +33,17 @@ abstract class MixinPlayerEntity extends LivingEntity implements PonyContainer<P
|
|||
return new Pony((PlayerEntity)(Object)this);
|
||||
}
|
||||
|
||||
@ModifyVariable(method = "handleFallDamage(FF)Z",
|
||||
at = @At("HEAD"),
|
||||
ordinal = 0,
|
||||
argsOnly = true)
|
||||
private float onHandleFallDamage(float distance) {
|
||||
return get().onImpact(distance);
|
||||
@Inject(method = "handleFallDamage(FF)Z", at = @At("HEAD"), cancellable = true)
|
||||
private void onHandleFallDamage(float distance, float damageMultiplier, CallbackInfoReturnable<Boolean> info) {
|
||||
get().onImpact(fallDistance, damageMultiplier).ifPresent(newDistance -> {
|
||||
PlayerEntity self = (PlayerEntity)(Object)this;
|
||||
|
||||
if (newDistance >= 2) {
|
||||
self.increaseStat(Stats.FALL_ONE_CM, Math.round(newDistance * 100));
|
||||
}
|
||||
|
||||
info.setReturnValue(super.handleFallDamage(newDistance, damageMultiplier));
|
||||
});
|
||||
}
|
||||
|
||||
@Inject(method = "createPlayerAttributes()Lnet/minecraft/entity/attribute/DefaultAttributeContainer$Builder;", at = @At("RETURN"))
|
||||
|
|
Loading…
Reference in a new issue