Prevent EntityCreature from ignoring gravity

This commit is contained in:
Felix Cravic 2020-11-26 14:14:40 +01:00
parent e813037475
commit 3bc90fffd9
2 changed files with 4 additions and 1 deletions

View File

@ -455,6 +455,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P
// Velocity // Velocity
final boolean applyVelocity = (hasVelocity() && !PlayerUtils.isNettyClient(this)) || final boolean applyVelocity = (hasVelocity() && !PlayerUtils.isNettyClient(this)) ||
(!isOnGround() && !PlayerUtils.isNettyClient(this)) ||
(PlayerUtils.isNettyClient(this) && hasVelocity()); (PlayerUtils.isNettyClient(this) && hasVelocity());
if (applyVelocity) { if (applyVelocity) {
final float tps = MinecraftServer.TICK_PER_SECOND; final float tps = MinecraftServer.TICK_PER_SECOND;

View File

@ -2,6 +2,7 @@ package net.minestom.server.entity;
import com.extollit.gaming.ai.path.HydrazinePathFinder; import com.extollit.gaming.ai.path.HydrazinePathFinder;
import com.extollit.gaming.ai.path.model.IPath; import com.extollit.gaming.ai.path.model.IPath;
import net.minestom.server.MinecraftServer;
import net.minestom.server.attribute.Attributes; import net.minestom.server.attribute.Attributes;
import net.minestom.server.collision.CollisionUtils; import net.minestom.server.collision.CollisionUtils;
import net.minestom.server.entity.ai.GoalSelector; import net.minestom.server.entity.ai.GoalSelector;
@ -431,6 +432,7 @@ public abstract class EntityCreature extends LivingEntity {
final float radians = (float) Math.atan2(dz, dx); final float radians = (float) Math.atan2(dz, dx);
final float speedX = (float) (Math.cos(radians) * speed); final float speedX = (float) (Math.cos(radians) * speed);
final float speedY = noGravity ? 0 : -gravityDragPerTick * MinecraftServer.TICK_PER_SECOND;
final float speedZ = (float) (Math.sin(radians) * speed); final float speedZ = (float) (Math.sin(radians) * speed);
lookAlong(dx, direction.getY(), dz); lookAlong(dx, direction.getY(), dz);
@ -439,7 +441,7 @@ public abstract class EntityCreature extends LivingEntity {
Vector newVelocityOut = new Vector(); Vector newVelocityOut = new Vector();
// Prevent ghosting // Prevent ghosting
CollisionUtils.handlePhysics(this, new Vector(speedX, 0, speedZ), newPosition, newVelocityOut); CollisionUtils.handlePhysics(this, new Vector(speedX, speedY, speedZ), newPosition, newVelocityOut);
getPosition().setX(newPosition.getX()); getPosition().setX(newPosition.getX());
getPosition().setZ(newPosition.getZ()); getPosition().setZ(newPosition.getZ());