Update part of Entity.java

This commit is contained in:
Németh Noel 2021-07-07 01:06:32 +02:00
parent 4187bc0e4d
commit 6f6b15fa96

View File

@ -38,7 +38,6 @@ import net.minestom.server.tag.Tag;
import net.minestom.server.tag.TagHandler; import net.minestom.server.tag.TagHandler;
import net.minestom.server.thread.ThreadProvider; import net.minestom.server.thread.ThreadProvider;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import net.minestom.server.utils.Vector;
import net.minestom.server.utils.callback.OptionalCallback; import net.minestom.server.utils.callback.OptionalCallback;
import net.minestom.server.utils.chunk.ChunkCallback; import net.minestom.server.utils.chunk.ChunkCallback;
import net.minestom.server.utils.chunk.ChunkUtils; import net.minestom.server.utils.chunk.ChunkUtils;
@ -549,27 +548,23 @@ public class Entity implements Viewable, Tickable, EventHandler<EntityEvent>, Da
} }
// Update velocity // Update velocity
if (hasVelocity() || !newVelocity.isZero()) { if (hasVelocity() || !newVelocity.equals(Vec.ZERO)) {
this.velocity.copy(newVelocity); velocity = newVelocity.mul(tps); // Convert from blocks/tick to blocks/sec
this.velocity.multiply(tps);
final Block block = finalChunk.getBlock(position); final Block block = finalChunk.getBlock(position);
final double drag = block.registry().friction(); final double drag = block.registry().friction();
if (onGround) { if (onGround) {
// Stop player velocity // Stop player velocity
if (isNettyClient) { if (isNettyClient) {
this.velocity.zero(); velocity = Vec.ZERO;
} }
} }
this.velocity.setX(velocity.getX() * drag); velocity = velocity.with((x, y, z) -> new Vec(
this.velocity.setZ(velocity.getZ() * drag); x * drag,
if (!hasNoGravity()) !hasNoGravity() ? y * (1 - gravityDragPerTick) : y,
this.velocity.setY(velocity.getY() * (1 - gravityDragPerTick)); z * drag
)).with(Vec.Operator.EPSILON);
if (velocity.equals(new Vector())) {
this.velocity.zero();
}
} }
// Synchronization and packets... // Synchronization and packets...