Rename with to apply

This commit is contained in:
TheMode 2021-07-08 13:22:04 +02:00
parent 30464d903d
commit ca2a2eb233
4 changed files with 6 additions and 15 deletions

View File

@ -40,7 +40,7 @@ public class CollisionUtils {
deltaPosition.z() > 0 ? boundingBox.getBackFace() : boundingBox.getFrontFace());
return new PhysicsResult(currentPosition.withCoord(zCollision.newPosition),
deltaPosition.with(((x, y, z) -> new Vec(
deltaPosition.apply(((x, y, z) -> new Vec(
xCollision.foundCollision ? 0 : x,
yCollision.foundCollision ? 0 : y,
zCollision.foundCollision ? 0 : z
@ -114,7 +114,7 @@ public class CollisionUtils {
// TODO: block collision boxes
// TODO: for the moment, always consider a full block
if (block.isSolid()) {
corners[cornerIndex] = originalCorner.with(((x, y, z) -> new Vec(
corners[cornerIndex] = originalCorner.apply(((x, y, z) -> new Vec(
Math.abs(axis.x()) > 10e-16 ? newCorner.blockX() - axis.x() * sign : x,
Math.abs(axis.y()) > 10e-16 ? newCorner.blockY() - axis.y() * sign : y,
Math.abs(axis.z()) > 10e-16 ? newCorner.blockZ() - axis.z() * sign : z

View File

@ -547,13 +547,13 @@ public class Entity implements Viewable, Tickable, EventHandler<EntityEvent>, Da
// Convert from blocks/tick to blocks/sec
.mul(tps)
// Apply drag
.with((x, y, z) -> new Vec(
.apply((x, y, z) -> new Vec(
x * drag,
!hasNoGravity() ? y * (1 - gravityDragPerTick) : y,
z * drag
))
// Prevent infinitely decreasing velocity
.with(Vec.Operator.EPSILON);
.apply(Vec.Operator.EPSILON);
}
}

View File

@ -2,9 +2,6 @@ package net.minestom.server.utils.block;
import net.minestom.server.entity.LivingEntity;
import net.minestom.server.instance.block.BlockFace;
import net.minestom.server.utils.BlockPosition;
import net.minestom.server.utils.Position;
import net.minestom.server.utils.Vector;
import net.minestom.server.utils.coordinate.Point;
import net.minestom.server.utils.coordinate.Pos;
import net.minestom.server.utils.coordinate.Vec;
@ -68,7 +65,7 @@ public class BlockIterator implements Iterator<Point> {
double secondPosition = 0;
double thirdPosition = 0;
Vec startBlock = startClone.with(Vec.Operator.FLOOR);
Vec startBlock = startClone.apply(Vec.Operator.FLOOR);
if (getXLength(direction) > mainDirection) {
mainFace = getXFace(direction);

View File

@ -7,7 +7,6 @@ import org.jetbrains.annotations.NotNull;
import java.util.Objects;
import java.util.function.DoubleUnaryOperator;
import java.util.function.UnaryOperator;
/**
* Represents an immutable 3D vector.
@ -59,7 +58,7 @@ public final class Vec implements Point {
* @return the created point
*/
@Contract(pure = true)
public @NotNull Vec with(@NotNull Operator operator) {
public @NotNull Vec apply(@NotNull Operator operator) {
return operator.apply(x, y, z);
}
@ -194,11 +193,6 @@ public final class Vec implements Point {
return new Vec(Math.max(x, value), Math.max(y, value), Math.max(z, value));
}
@Contract(pure = true)
public Vec apply(@NotNull UnaryOperator<@NotNull Vec> operator) {
return operator.apply(this);
}
@Contract(pure = true)
public @NotNull Pos asPosition() {
return new Pos(x, y, z);