Send a velocity update to the client when modifying player velocities. (should fix some instances of knockback not working when it should)

i.e.
When wearing the alicorn amulet,
When hit by a jar,
When hit by a polearm
When hit by an earth pony stomp
When kicked by an earth pony
When screeched at by a bat pony
This commit is contained in:
Sollace 2022-09-26 21:11:28 +02:00
parent 66cbf1ff2b
commit 88ba52efc5
10 changed files with 28 additions and 13 deletions

View file

@ -7,6 +7,7 @@ import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.ability.data.Hit; import com.minelittlepony.unicopia.ability.data.Hit;
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
import com.minelittlepony.unicopia.advancement.UCriteria; import com.minelittlepony.unicopia.advancement.UCriteria;
import com.minelittlepony.unicopia.entity.Living;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.util.MagicalDamageSource; import com.minelittlepony.unicopia.util.MagicalDamageSource;
@ -79,15 +80,16 @@ public class BatEeeeAbility implements Ability<Hit> {
} }
int total = player.findAllEntitiesInRange(5).mapToInt(e -> { int total = player.findAllEntitiesInRange(5).mapToInt(e -> {
if (e instanceof LivingEntity && !SpellType.SHIELD.isOn(e)) { if (e instanceof LivingEntity living && !SpellType.SHIELD.isOn(e)) {
boolean isEarthPony = EquinePredicates.PLAYER_EARTH.test(e); boolean isEarthPony = EquinePredicates.PLAYER_EARTH.test(e);
e.damage(MagicalDamageSource.create("eeee", player).setBreakSunglasses(), isEarthPony ? 0.1F : 0.3F); e.damage(MagicalDamageSource.create("eeee", player).setBreakSunglasses(), isEarthPony ? 0.1F : 0.3F);
Vec3d knockVec = origin.subtract(e.getPos()); Vec3d knockVec = origin.subtract(e.getPos());
((LivingEntity) e).takeKnockback(isEarthPony ? 0.3F : 0.5F, knockVec.getX(), knockVec.getZ()); living.takeKnockback(isEarthPony ? 0.3F : 0.5F, knockVec.getX(), knockVec.getZ());
if (!isEarthPony) { if (!isEarthPony) {
e.addVelocity(0, 0.1, 0); e.addVelocity(0, 0.1, 0);
} }
Living.updateVelocity(e);
} }
return 1; return 1;
}).sum(); }).sum();

View file

@ -12,6 +12,7 @@ import com.minelittlepony.unicopia.ability.data.tree.TreeType;
import com.minelittlepony.unicopia.block.data.BlockDestructionManager; import com.minelittlepony.unicopia.block.data.BlockDestructionManager;
import com.minelittlepony.unicopia.client.minelittlepony.MineLPDelegate; import com.minelittlepony.unicopia.client.minelittlepony.MineLPDelegate;
import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation; import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation;
import com.minelittlepony.unicopia.entity.Living;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.particle.ParticleUtils; import com.minelittlepony.unicopia.particle.ParticleUtils;
import com.minelittlepony.unicopia.particle.UParticles; import com.minelittlepony.unicopia.particle.UParticles;
@ -84,6 +85,7 @@ public class EarthPonyKickAbility implements Ability<Pos> {
float calculatedStrength = 0.5F * (1 + player.getLevel().getScaled(9)); float calculatedStrength = 0.5F * (1 + player.getLevel().getScaled(9));
entity.damage(MagicalDamageSource.KICK, player.getReferenceWorld().random.nextBetween(2, 10) + calculatedStrength); entity.damage(MagicalDamageSource.KICK, player.getReferenceWorld().random.nextBetween(2, 10) + calculatedStrength);
entity.takeKnockback(calculatedStrength, origin.x - entity.getX(), origin.z - entity.getZ()); entity.takeKnockback(calculatedStrength, origin.x - entity.getX(), origin.z - entity.getZ());
Living.updateVelocity(entity);
player.subtractEnergyCost(3); player.subtractEnergyCost(3);
player.setAnimation(Animation.KICK); player.setAnimation(Animation.KICK);
return; return;

View file

@ -6,6 +6,7 @@ import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.ability.data.Hit; import com.minelittlepony.unicopia.ability.data.Hit;
import com.minelittlepony.unicopia.block.data.BlockDestructionManager; import com.minelittlepony.unicopia.block.data.BlockDestructionManager;
import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation; import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation;
import com.minelittlepony.unicopia.entity.Living;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.item.UItems;
import com.minelittlepony.unicopia.item.enchantment.UEnchantments; import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
@ -85,6 +86,7 @@ public class EarthPonyStompAbility implements Ability<Hit> {
double downV = Math.sqrt(ppos.getSquaredDistance(pos)) * player.getPhysics().getGravitySignum(); double downV = Math.sqrt(ppos.getSquaredDistance(pos)) * player.getPhysics().getGravitySignum();
player.getMaster().addVelocity(0, -downV, 0); player.getMaster().addVelocity(0, -downV, 0);
player.updateVelocity();
} }
@Override @Override
@ -138,6 +140,7 @@ public class EarthPonyStompAbility implements Ability<Hit> {
} }
i.damage(damage, (float)amount); i.damage(damage, (float)amount);
Living.updateVelocity(i);
} }
}); });

View file

@ -2,8 +2,7 @@ package com.minelittlepony.unicopia.ability;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.*;
import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.ability.data.Hit; import com.minelittlepony.unicopia.ability.data.Hit;
import com.minelittlepony.unicopia.ability.magic.spell.HomingSpell; import com.minelittlepony.unicopia.ability.magic.spell.HomingSpell;
import com.minelittlepony.unicopia.ability.magic.spell.Spell; import com.minelittlepony.unicopia.ability.magic.spell.Spell;

View file

@ -1,5 +1,6 @@
package com.minelittlepony.unicopia.ability.magic.spell.effect; package com.minelittlepony.unicopia.ability.magic.spell.effect;
import com.minelittlepony.unicopia.entity.Living;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.item.enchantment.UEnchantments; import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
@ -37,6 +38,7 @@ public interface AttractionUtils {
center.y + yChange, center.y + yChange,
center.z center.z
); );
Living.updateVelocity(target);
} }
/** /**

View file

@ -148,6 +148,8 @@ public class AirBalloonEntity extends FlyingEntity implements EntityCollisions.C
e.setVelocity(vel.getX(), yVel, vel.getZ()); e.setVelocity(vel.getX(), yVel, vel.getZ());
e.setVelocity(e.getVelocity().multiply(0.3).add(getVelocity().multiply(0.786))); e.setVelocity(e.getVelocity().multiply(0.3).add(getVelocity().multiply(0.786)));
e.setOnGround(true); e.setOnGround(true);
Living.updateVelocity(e);
} }
} }
@ -163,6 +165,7 @@ public class AirBalloonEntity extends FlyingEntity implements EntityCollisions.C
@Override @Override
public void onPlayerCollision(PlayerEntity player) { public void onPlayerCollision(PlayerEntity player) {
// TODO: check that this is still working correctly after adding Living.updateVelocity(i) in AirBalloonEntity.tick()
if (getVelocity().lengthSquared() > 0) { if (getVelocity().lengthSquared() > 0) {
// player.setVelocity(getVelocity().multiply(1.3)); // player.setVelocity(getVelocity().multiply(1.3));
player.setVelocity(player.getVelocity().multiply(0.3).add(getVelocity().multiply( player.setVelocity(player.getVelocity().multiply(0.3).add(getVelocity().multiply(
@ -174,6 +177,8 @@ public class AirBalloonEntity extends FlyingEntity implements EntityCollisions.C
if (diff > 0) { if (diff > 0) {
player.addVelocity(0, diff, 0); player.addVelocity(0, diff, 0);
} }
Living.updateVelocity(player);
} }
} }

View file

@ -9,8 +9,7 @@ import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.Affinity; import com.minelittlepony.unicopia.Affinity;
import com.minelittlepony.unicopia.AwaitTickQueue; import com.minelittlepony.unicopia.AwaitTickQueue;
import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.entity.IItemEntity; import com.minelittlepony.unicopia.entity.*;
import com.minelittlepony.unicopia.entity.ItemImpl;
import com.minelittlepony.unicopia.entity.effect.UEffects; import com.minelittlepony.unicopia.entity.effect.UEffects;
import com.minelittlepony.unicopia.entity.player.MagicReserves; import com.minelittlepony.unicopia.entity.player.MagicReserves;
import com.minelittlepony.unicopia.entity.player.PlayerCharmTracker; import com.minelittlepony.unicopia.entity.player.PlayerCharmTracker;
@ -133,6 +132,7 @@ public class AlicornAmuletItem extends AmuletItem implements PlayerCharmTracker.
if (attachedTime > 120) { if (attachedTime > 120) {
pony.getMaster().takeKnockback(1, 1, 1); pony.getMaster().takeKnockback(1, 1, 1);
pony.updateVelocity();
} }
} }

View file

@ -1,6 +1,7 @@
package com.minelittlepony.unicopia.item; package com.minelittlepony.unicopia.item;
import com.minelittlepony.unicopia.entity.IItemEntity; import com.minelittlepony.unicopia.entity.IItemEntity;
import com.minelittlepony.unicopia.entity.Living;
import com.minelittlepony.unicopia.projectile.MagicProjectileEntity; import com.minelittlepony.unicopia.projectile.MagicProjectileEntity;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -89,12 +90,13 @@ public class FilledJarItem extends JarItem implements ChameleonItem {
final float toRadians = (float)Math.PI / 180F; final float toRadians = (float)Math.PI / 180F;
if (entity instanceof LivingEntity) { if (entity instanceof LivingEntity living) {
((LivingEntity)entity).takeKnockback( living.takeKnockback(
knockback / 2F, knockback / 2F,
MathHelper.sin(projectile.getYaw() * toRadians), MathHelper.sin(projectile.getYaw() * toRadians),
-MathHelper.cos(projectile.getYaw() * toRadians) -MathHelper.cos(projectile.getYaw() * toRadians)
); );
Living.updateVelocity(living);
if (fire > 0) { if (fire > 0) {
entity.setOnFireFor(fire * 4); entity.setOnFireFor(fire * 4);

View file

@ -5,6 +5,7 @@ import java.util.UUID;
import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.minelittlepony.unicopia.UTags; import com.minelittlepony.unicopia.UTags;
import com.minelittlepony.unicopia.entity.Living;
import com.minelittlepony.unicopia.entity.UEntityAttributes; import com.minelittlepony.unicopia.entity.UEntityAttributes;
import net.minecraft.block.*; import net.minecraft.block.*;
@ -12,8 +13,6 @@ import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.attribute.*; import net.minecraft.entity.attribute.*;
import net.minecraft.item.*; import net.minecraft.item.*;
import net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket;
import net.minecraft.server.network.ServerPlayerEntity;
public class PolearmItem extends SwordItem { public class PolearmItem extends SwordItem {
protected static final UUID ATTACK_RANGE_MODIFIER_ID = UUID.fromString("A7B3659C-AA74-469C-963A-09A391DCAA0F"); protected static final UUID ATTACK_RANGE_MODIFIER_ID = UUID.fromString("A7B3659C-AA74-469C-963A-09A391DCAA0F");
@ -57,11 +56,10 @@ public class PolearmItem extends SwordItem {
boolean tooNear = target.distanceTo(attacker) <= 2; boolean tooNear = target.distanceTo(attacker) <= 2;
stack.damage(tooNear ? 4 : 1, attacker, e -> e.sendEquipmentBreakStatus(EquipmentSlot.MAINHAND)); stack.damage(tooNear ? 4 : 1, attacker, e -> e.sendEquipmentBreakStatus(EquipmentSlot.MAINHAND));
target.takeKnockback(0.15, attacker.getX() - target.getX(), attacker.getZ() - target.getZ()); target.takeKnockback(0.15, attacker.getX() - target.getX(), attacker.getZ() - target.getZ());
Living.updateVelocity(target);
if (tooNear) { if (tooNear) {
attacker.takeKnockback(attacker.getRandom().nextTriangular(0.4, 0.2), target.getX() - attacker.getX(), target.getZ() - attacker.getZ()); attacker.takeKnockback(attacker.getRandom().nextTriangular(0.4, 0.2), target.getX() - attacker.getX(), target.getZ() - attacker.getZ());
if (attacker instanceof ServerPlayerEntity ply) { Living.updateVelocity(attacker);
ply.networkHandler.sendPacket(new EntityVelocityUpdateS2CPacket(ply));
}
} }
return true; return true;

View file

@ -2,6 +2,7 @@ package com.minelittlepony.unicopia.projectile;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.entity.Living;
import com.minelittlepony.unicopia.mixin.MixinPersistentProjectileEntity; import com.minelittlepony.unicopia.mixin.MixinPersistentProjectileEntity;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@ -50,6 +51,7 @@ public interface ProjectileUtil {
Vec3d vel = throwable.getVelocity(); Vec3d vel = throwable.getVelocity();
throwable.addVelocity(heading.x - vel.x, heading.y - vel.y, heading.z - vel.z); throwable.addVelocity(heading.x - vel.x, heading.y - vel.y, heading.z - vel.z);
Living.updateVelocity(throwable);
} }
} }