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;
|
return 0.5F;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ public final class PlayerDimensions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (physics.isFlying && physics.isRainboom()) {
|
if (physics.isFlyingSurvival && physics.isRainboom()) {
|
||||||
return defaultBodyHeight / 2;
|
return defaultBodyHeight / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,8 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
|
||||||
public int ticksNextLevel = 0;
|
public int ticksNextLevel = 0;
|
||||||
public float flightExperience = 0;
|
public float flightExperience = 0;
|
||||||
|
|
||||||
public boolean isFlying = false;
|
public boolean isFlyingEither = false;
|
||||||
|
public boolean isFlyingSurvival = false;
|
||||||
public boolean isRainbooming = false;
|
public boolean isRainbooming = false;
|
||||||
|
|
||||||
private double lastTickPosX = 0;
|
private double lastTickPosX = 0;
|
||||||
|
@ -106,13 +107,18 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
|
||||||
entity.abilities.allowFlying = checkCanFly();
|
entity.abilities.allowFlying = checkCanFly();
|
||||||
|
|
||||||
if (!creative) {
|
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 (!creative && !entity.isFallFlying()) {
|
||||||
if (isFlying && !entity.hasVehicle()) {
|
if (isFlyingSurvival && !entity.hasVehicle()) {
|
||||||
|
|
||||||
if (!isRainbooming && getHorizontalMotion(entity) > 0.2 && flightExperience < MAXIMUM_FLIGHT_EXPERIENCE) {
|
if (!isRainbooming && getHorizontalMotion(entity) > 0.2 && flightExperience < MAXIMUM_FLIGHT_EXPERIENCE) {
|
||||||
flightExperience++;
|
flightExperience++;
|
||||||
|
@ -179,7 +185,7 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
|
||||||
|
|
||||||
if (entity.isOnGround()) {
|
if (entity.isOnGround()) {
|
||||||
entity.abilities.flying = false;
|
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) {
|
if (entity.abilities.allowFlying) {
|
||||||
entity.abilities.flying |= flying;
|
entity.abilities.flying |= flying;
|
||||||
|
|
||||||
isFlying = entity.abilities.flying;
|
isFlyingSurvival = entity.abilities.flying;
|
||||||
|
|
||||||
if (isFlying) {
|
if (isFlyingSurvival) {
|
||||||
ticksNextLevel = 0;
|
ticksNextLevel = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
entity.abilities.flying = false;
|
entity.abilities.flying = false;
|
||||||
isFlying = false;
|
isFlyingSurvival = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,7 +309,8 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
|
||||||
super.toNBT(compound);
|
super.toNBT(compound);
|
||||||
compound.putInt("flightDuration", ticksNextLevel);
|
compound.putInt("flightDuration", ticksNextLevel);
|
||||||
compound.putFloat("flightExperience", flightExperience);
|
compound.putFloat("flightExperience", flightExperience);
|
||||||
compound.putBoolean("isFlying", isFlying);
|
compound.putBoolean("isFlying", isFlyingSurvival);
|
||||||
|
compound.putBoolean("isFlyingEither", isFlyingEither);
|
||||||
compound.putBoolean("isRainbooming", isRainbooming);
|
compound.putBoolean("isRainbooming", isRainbooming);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,7 +319,8 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
|
||||||
super.fromNBT(compound);
|
super.fromNBT(compound);
|
||||||
ticksNextLevel = compound.getInt("flightDuration");
|
ticksNextLevel = compound.getInt("flightDuration");
|
||||||
flightExperience = compound.getFloat("flightExperience");
|
flightExperience = compound.getFloat("flightExperience");
|
||||||
isFlying = compound.getBoolean("isFlying");
|
isFlyingSurvival = compound.getBoolean("isFlying");
|
||||||
|
isFlyingEither = compound.getBoolean("isFlyingEither");
|
||||||
isRainbooming = compound.getBoolean("isRainbooming");
|
isRainbooming = compound.getBoolean("isRainbooming");
|
||||||
|
|
||||||
pony.getOwner().calculateDimensions();
|
pony.getOwner().calculateDimensions();
|
||||||
|
@ -320,7 +328,7 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFlying() {
|
public boolean isFlying() {
|
||||||
return isFlying;
|
return isFlyingSurvival;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -69,8 +69,6 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
|
||||||
|
|
||||||
private final Interpolator interpolator = new LinearInterpolator();
|
private final Interpolator interpolator = new LinearInterpolator();
|
||||||
|
|
||||||
private float nextStepDistance = 1;
|
|
||||||
|
|
||||||
private final PlayerEntity entity;
|
private final PlayerEntity entity;
|
||||||
|
|
||||||
private boolean dirty;
|
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);
|
EntityAttributeInstance attr = entity.getAttributes().getCustomInstance(PlayerAttributes.ENTITY_GRAVTY_MODIFIER);
|
||||||
|
|
||||||
if (attr.hasModifier(PlayerAttributes.BAT_HANGING)) {
|
if (attr.hasModifier(PlayerAttributes.BAT_HANGING)) {
|
||||||
gravity.isFlying = false;
|
gravity.isFlyingSurvival = false;
|
||||||
|
gravity.isFlyingEither = false;
|
||||||
entity.abilities.flying = false;
|
entity.abilities.flying = false;
|
||||||
|
|
||||||
if (Entity.squaredHorizontalLength(entity.getVelocity()) > 0.01 || entity.isSneaking() || !canHangAt()) {
|
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();
|
prevSneaking = entity.isSneaking();
|
||||||
}
|
}
|
||||||
|
|
||||||
public float onImpact(float distance) {
|
public Optional<Float> onImpact(float distance, float damageMultiplier) {
|
||||||
if (getSpecies().canFly()) {
|
if (getSpecies().canFly() && !entity.isCreative() && !entity.isSpectator()) {
|
||||||
distance = Math.max(0, distance - 5);
|
return Optional.of(Math.max(0, distance - 5));
|
||||||
}
|
}
|
||||||
return distance;
|
|
||||||
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -323,17 +323,6 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
|
||||||
return entity.getHealth() > 0;
|
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) {
|
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()))) {
|
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.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
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.CallbackInfo;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
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.attribute.DefaultAttributeContainer;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.stat.Stats;
|
||||||
import net.minecraft.util.Unit;
|
import net.minecraft.util.Unit;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.GameMode;
|
import net.minecraft.world.GameMode;
|
||||||
|
@ -33,12 +33,17 @@ abstract class MixinPlayerEntity extends LivingEntity implements PonyContainer<P
|
||||||
return new Pony((PlayerEntity)(Object)this);
|
return new Pony((PlayerEntity)(Object)this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ModifyVariable(method = "handleFallDamage(FF)Z",
|
@Inject(method = "handleFallDamage(FF)Z", at = @At("HEAD"), cancellable = true)
|
||||||
at = @At("HEAD"),
|
private void onHandleFallDamage(float distance, float damageMultiplier, CallbackInfoReturnable<Boolean> info) {
|
||||||
ordinal = 0,
|
get().onImpact(fallDistance, damageMultiplier).ifPresent(newDistance -> {
|
||||||
argsOnly = true)
|
PlayerEntity self = (PlayerEntity)(Object)this;
|
||||||
private float onHandleFallDamage(float distance) {
|
|
||||||
return get().onImpact(distance);
|
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"))
|
@Inject(method = "createPlayerAttributes()Lnet/minecraft/entity/attribute/DefaultAttributeContainer$Builder;", at = @At("RETURN"))
|
||||||
|
|
Loading…
Reference in a new issue