Fixed ground pound not taking into accoutn the player's gravity

This commit is contained in:
Sollace 2021-03-01 09:41:55 +02:00
parent f0e43cdbe7
commit 0cd45ad1ae
3 changed files with 15 additions and 15 deletions

View file

@ -58,8 +58,8 @@ public class EarthPonyStompAbility implements Ability<Hit> {
@Nullable @Nullable
@Override @Override
public Hit tryActivate(Pony player) { public Hit tryActivate(Pony player) {
if (!player.getMaster().isOnGround() && !player.getMaster().abilities.flying) { if (!player.getMaster().isOnGround() && player.getMaster().getVelocity().y * player.getPhysics().getGravitySignum() < 0 && !player.getMaster().abilities.flying) {
thrustDownwards(player.getMaster()); thrustDownwards(player);
return Hit.INSTANCE; return Hit.INSTANCE;
} }
@ -71,22 +71,22 @@ public class EarthPonyStompAbility implements Ability<Hit> {
return Hit.SERIALIZER; return Hit.SERIALIZER;
} }
private void thrustDownwards(PlayerEntity player) { private void thrustDownwards(Pony player) {
BlockPos ppos = player.getBlockPos(); BlockPos ppos = player.getOrigin();
BlockPos pos = PosHelper.findSolidGroundAt(player.getEntityWorld(), ppos); BlockPos pos = PosHelper.findSolidGroundAt(player.getWorld(), ppos, player.getPhysics().getGravitySignum());
double downV = Math.sqrt(ppos.getSquaredDistance(pos)); double downV = Math.sqrt(ppos.getSquaredDistance(pos)) * player.getPhysics().getGravitySignum();
player.addVelocity(0, -downV, 0); player.getMaster().addVelocity(0, -downV, 0);
} }
@Override @Override
public void apply(Pony iplayer, Hit data) { public void apply(Pony iplayer, Hit data) {
PlayerEntity player = iplayer.getMaster(); PlayerEntity player = iplayer.getMaster();
thrustDownwards(player); thrustDownwards(iplayer);
iplayer.waitForFall(() -> { iplayer.waitForFall(() -> {
BlockPos center = PosHelper.findSolidGroundAt(player.getEntityWorld(), player.getBlockPos()); BlockPos center = PosHelper.findSolidGroundAt(player.getEntityWorld(), player.getBlockPos(), iplayer.getPhysics().getGravitySignum());
float heavyness = 1 + EnchantmentHelper.getEquipmentLevel(UEnchantments.HEAVY, player); float heavyness = 1 + EnchantmentHelper.getEquipmentLevel(UEnchantments.HEAVY, player);
@ -101,7 +101,7 @@ public class EarthPonyStompAbility implements Ability<Hit> {
} }
inertia /= heavyness; inertia /= heavyness;
double liftAmount = Math.sin(Math.PI * dist / rad) * 12; double liftAmount = Math.sin(Math.PI * dist / rad) * 12 * iplayer.getPhysics().getGravitySignum();
i.addVelocity( i.addVelocity(
-(player.getX() - i.getX()) / inertia, -(player.getX() - i.getX()) / inertia,

View file

@ -30,7 +30,7 @@ public class ScorchSpell extends FireSpell {
@Override @Override
public boolean update(Caster<?> source) { public boolean update(Caster<?> source) {
BlockPos pos = PosHelper.findSolidGroundAt(source.getWorld(), source.getOrigin()); BlockPos pos = PosHelper.findSolidGroundAt(source.getWorld(), source.getOrigin(), source.getPhysics().getGravitySignum());
BlockState state = source.getWorld().getBlockState(pos); BlockState state = source.getWorld().getBlockState(pos);

View file

@ -14,6 +14,7 @@ import com.minelittlepony.unicopia.util.shape.Shape;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Direction.Axis;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.Vec3i; import net.minecraft.util.math.Vec3i;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -26,10 +27,9 @@ public interface PosHelper {
return a.add(b.getX(), b.getY(), b.getZ()); return a.add(b.getX(), b.getY(), b.getZ());
} }
static BlockPos findSolidGroundAt(World world, BlockPos pos) { static BlockPos findSolidGroundAt(World world, BlockPos pos, int signum) {
while ((pos.getY() > 0 || !World.isInBuildLimit(pos)) while (World.isInBuildLimit(pos) && (world.isAir(pos) || !world.getBlockState(pos).canPlaceAt(world, pos))) {
&& (world.isAir(pos) || !world.getBlockState(pos).canPlaceAt(world, pos))) { pos = pos.offset(Axis.Y, -signum);
pos = pos.down();
} }
return pos; return pos;