mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-06 16:37:38 +01:00
Fix build
This commit is contained in:
parent
eb0f7379ea
commit
84eb0a8934
@ -307,16 +307,6 @@ public class Entity implements Viewable, Tickable, EventHandler<EntityEvent>, Da
|
|||||||
sendPacketToViewersAndSelf(entityRotationPacket);
|
sendPacketToViewersAndSelf(entityRotationPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Changes the view of the entity.
|
|
||||||
* Only the yaw and pitch are used.
|
|
||||||
*
|
|
||||||
* @param position the new view
|
|
||||||
*/
|
|
||||||
public void setView(@NotNull Position position) {
|
|
||||||
setView(position.getYaw(), position.getPitch());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When set to true, the entity will automatically get new viewers when they come too close.
|
* When set to true, the entity will automatically get new viewers when they come too close.
|
||||||
* This can be use to have complete control over which player can see it, without having to deal with
|
* This can be use to have complete control over which player can see it, without having to deal with
|
||||||
@ -485,9 +475,7 @@ public class Entity implements Viewable, Tickable, EventHandler<EntityEvent>, Da
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sendPositionUpdate(false);
|
|
||||||
final boolean isNettyClient = PlayerUtils.isNettyClient(this);
|
final boolean isNettyClient = PlayerUtils.isNettyClient(this);
|
||||||
|
|
||||||
// Entity tick
|
// Entity tick
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -7,10 +7,8 @@ import net.minestom.server.event.entity.EntityShootEvent;
|
|||||||
import net.minestom.server.instance.Chunk;
|
import net.minestom.server.instance.Chunk;
|
||||||
import net.minestom.server.instance.Instance;
|
import net.minestom.server.instance.Instance;
|
||||||
import net.minestom.server.instance.block.Block;
|
import net.minestom.server.instance.block.Block;
|
||||||
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.Point;
|
||||||
|
import net.minestom.server.utils.coordinate.Pos;
|
||||||
import net.minestom.server.utils.coordinate.Vec;
|
import net.minestom.server.utils.coordinate.Vec;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@ -130,7 +128,7 @@ public class EntityProjectile extends Entity {
|
|||||||
* @return if an arrow is stuck in block / hit an entity.
|
* @return if an arrow is stuck in block / hit an entity.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("ConstantConditions")
|
@SuppressWarnings("ConstantConditions")
|
||||||
private boolean isStuck(Point pos, Point posNow) {
|
private boolean isStuck(Pos pos, Pos posNow) {
|
||||||
if (pos.samePoint(posNow)) {
|
if (pos.samePoint(posNow)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -144,25 +142,21 @@ public class EntityProjectile extends Entity {
|
|||||||
For each point we will be checking blocks and entities we're in.
|
For each point we will be checking blocks and entities we're in.
|
||||||
*/
|
*/
|
||||||
double part = .25D; // half of the bounding box
|
double part = .25D; // half of the bounding box
|
||||||
Vector dir = posNow.toVector().subtract(pos.toVector());
|
final var dir = posNow.sub(pos).asVec();
|
||||||
int parts = (int) Math.ceil(dir.length() / part);
|
int parts = (int) Math.ceil(dir.length() / part);
|
||||||
Position direction = dir.normalize().multiply(part).toPosition();
|
final var direction = dir.normalize().mul(part).asPosition();
|
||||||
for (int i = 0; i < parts; ++i) {
|
for (int i = 0; i < parts; ++i) {
|
||||||
// If we're at last part, we can't just add another direction-vector, because we can exceed end point.
|
// If we're at last part, we can't just add another direction-vector, because we can exceed end point.
|
||||||
if (i == parts - 1) {
|
if (i == parts - 1) {
|
||||||
pos.setX(posNow.getX());
|
pos = posNow;
|
||||||
pos.setY(posNow.getY());
|
|
||||||
pos.setZ(posNow.getZ());
|
|
||||||
} else {
|
} else {
|
||||||
pos.add(direction);
|
pos = pos.add(direction);
|
||||||
}
|
}
|
||||||
BlockPosition bpos = pos.toBlockPosition();
|
Block block = instance.getBlock(pos.sub(0, 1, 0));
|
||||||
Block block = instance.getBlock(bpos.getX(), bpos.getY() - 1, bpos.getZ());
|
|
||||||
if (!block.isAir() && !block.isLiquid()) {
|
if (!block.isAir() && !block.isLiquid()) {
|
||||||
teleport(pos);
|
teleport(pos);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Chunk currentChunk = instance.getChunkAt(pos);
|
Chunk currentChunk = instance.getChunkAt(pos);
|
||||||
if (currentChunk != chunk) {
|
if (currentChunk != chunk) {
|
||||||
chunk = currentChunk;
|
chunk = currentChunk;
|
||||||
@ -178,8 +172,9 @@ public class EntityProjectile extends Entity {
|
|||||||
if (getAliveTicks() < 3) {
|
if (getAliveTicks() < 3) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
final Pos finalPos = pos;
|
||||||
Optional<Entity> victimOptional = entities.stream()
|
Optional<Entity> victimOptional = entities.stream()
|
||||||
.filter(entity -> entity.getBoundingBox().intersect(pos))
|
.filter(entity -> entity.getBoundingBox().intersect(finalPos))
|
||||||
.findAny();
|
.findAny();
|
||||||
if (victimOptional.isPresent()) {
|
if (victimOptional.isPresent()) {
|
||||||
LivingEntity victim = (LivingEntity) victimOptional.get();
|
LivingEntity victim = (LivingEntity) victimOptional.get();
|
||||||
|
@ -2,7 +2,6 @@ package net.minestom.server.entity.ai.goal;
|
|||||||
|
|
||||||
import net.minestom.server.entity.EntityCreature;
|
import net.minestom.server.entity.EntityCreature;
|
||||||
import net.minestom.server.entity.ai.GoalSelector;
|
import net.minestom.server.entity.ai.GoalSelector;
|
||||||
import net.minestom.server.utils.Vector;
|
|
||||||
import net.minestom.server.utils.coordinate.Vec;
|
import net.minestom.server.utils.coordinate.Vec;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -69,7 +68,7 @@ public class RandomLookAroundGoal extends GoalSelector {
|
|||||||
@Override
|
@Override
|
||||||
public void tick(long time) {
|
public void tick(long time) {
|
||||||
--lookTime;
|
--lookTime;
|
||||||
entityCreature.setView(entityCreature.getPosition().clone().setDirection(lookDirection));
|
entityCreature.teleport(entityCreature.getPosition().withDirection(lookDirection));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -55,9 +55,8 @@ public class BlockIterator implements Iterator<Point> {
|
|||||||
public BlockIterator(@NotNull Vec start, @NotNull Vec direction, double yOffset, int maxDistance) {
|
public BlockIterator(@NotNull Vec start, @NotNull Vec direction, double yOffset, int maxDistance) {
|
||||||
this.maxDistance = maxDistance;
|
this.maxDistance = maxDistance;
|
||||||
|
|
||||||
Vector startClone = start.clone();
|
|
||||||
|
|
||||||
startClone.setY(startClone.getY() + yOffset);
|
Vec startClone = start.withY(y -> y+yOffset);
|
||||||
|
|
||||||
currentDistance = 0;
|
currentDistance = 0;
|
||||||
|
|
||||||
@ -69,7 +68,7 @@ public class BlockIterator implements Iterator<Point> {
|
|||||||
double secondPosition = 0;
|
double secondPosition = 0;
|
||||||
double thirdPosition = 0;
|
double thirdPosition = 0;
|
||||||
|
|
||||||
BlockPosition startBlock = new BlockPosition(floor(startClone.getX()), floor(startClone.getY()), floor(startClone.getZ()));
|
Vec startBlock = startClone.with(Vec.Operator.FLOOR);
|
||||||
|
|
||||||
if (getXLength(direction) > mainDirection) {
|
if (getXLength(direction) > mainDirection) {
|
||||||
mainFace = getXFace(direction);
|
mainFace = getXFace(direction);
|
||||||
@ -133,18 +132,18 @@ public class BlockIterator implements Iterator<Point> {
|
|||||||
thirdError = -thirdStep + 1;
|
thirdError = -thirdStep + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockPosition lastBlock;
|
Vec lastBlock;
|
||||||
|
|
||||||
lastBlock = startBlock.getRelative(mainFace.getOppositeFace());
|
lastBlock = startBlock.relative(mainFace.getOppositeFace());
|
||||||
|
|
||||||
if (secondError < 0) {
|
if (secondError < 0) {
|
||||||
secondError += gridSize;
|
secondError += gridSize;
|
||||||
lastBlock = lastBlock.getRelative(secondFace.getOppositeFace());
|
lastBlock = lastBlock.relative(secondFace.getOppositeFace());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (thirdError < 0) {
|
if (thirdError < 0) {
|
||||||
thirdError += gridSize;
|
thirdError += gridSize;
|
||||||
lastBlock = lastBlock.getRelative(thirdFace.getOppositeFace());
|
lastBlock = lastBlock.relative(thirdFace.getOppositeFace());
|
||||||
}
|
}
|
||||||
|
|
||||||
// This means that when the variables are positive, it means that the coord=1 boundary has been crossed
|
// This means that when the variables are positive, it means that the coord=1 boundary has been crossed
|
||||||
@ -179,44 +178,44 @@ public class BlockIterator implements Iterator<Point> {
|
|||||||
return a.x() == b.x() && a.y() == b.y() && a.z() == b.z();
|
return a.x() == b.x() && a.y() == b.y() && a.z() == b.z();
|
||||||
}
|
}
|
||||||
|
|
||||||
private BlockFace getXFace(@NotNull Vector direction) {
|
private BlockFace getXFace(@NotNull Point direction) {
|
||||||
return ((direction.getX() > 0) ? BlockFace.EAST : BlockFace.WEST);
|
return ((direction.x() > 0) ? BlockFace.EAST : BlockFace.WEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BlockFace getYFace(@NotNull Vector direction) {
|
private BlockFace getYFace(@NotNull Point direction) {
|
||||||
return ((direction.getY() > 0) ? BlockFace.TOP : BlockFace.BOTTOM);
|
return ((direction.y() > 0) ? BlockFace.TOP : BlockFace.BOTTOM);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BlockFace getZFace(@NotNull Vector direction) {
|
private BlockFace getZFace(@NotNull Point direction) {
|
||||||
return ((direction.getZ() > 0) ? BlockFace.SOUTH : BlockFace.NORTH);
|
return ((direction.z() > 0) ? BlockFace.SOUTH : BlockFace.NORTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getXLength(@NotNull Vector direction) {
|
private double getXLength(@NotNull Point direction) {
|
||||||
return Math.abs(direction.getX());
|
return Math.abs(direction.x());
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getYLength(@NotNull Vector direction) {
|
private double getYLength(@NotNull Point direction) {
|
||||||
return Math.abs(direction.getY());
|
return Math.abs(direction.y());
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getZLength(@NotNull Vector direction) {
|
private double getZLength(@NotNull Point direction) {
|
||||||
return Math.abs(direction.getZ());
|
return Math.abs(direction.z());
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getPosition(double direction, double position, int blockPosition) {
|
private double getPosition(double direction, double position, int blockPosition) {
|
||||||
return direction > 0 ? (position - blockPosition) : (blockPosition + 1 - position);
|
return direction > 0 ? (position - blockPosition) : (blockPosition + 1 - position);
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getXPosition(@NotNull Vector direction, @NotNull Vector position, @NotNull BlockPosition block) {
|
private double getXPosition(@NotNull Point direction, @NotNull Point position, @NotNull Point block) {
|
||||||
return getPosition(direction.getX(), position.getX(), block.getX());
|
return getPosition(direction.x(), position.x(), block.blockX());
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getYPosition(@NotNull Vector direction, @NotNull Vector position, @NotNull BlockPosition block) {
|
private double getYPosition(@NotNull Point direction, @NotNull Point position, @NotNull Point block) {
|
||||||
return getPosition(direction.getY(), position.getY(), block.getY());
|
return getPosition(direction.y(), position.y(), block.blockY());
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getZPosition(@NotNull Vector direction, @NotNull Vector position, @NotNull BlockPosition block) {
|
private double getZPosition(@NotNull Point direction, @NotNull Point position, @NotNull Point block) {
|
||||||
return getPosition(direction.getZ(), position.getZ(), block.getZ());
|
return getPosition(direction.z(), position.z(), block.blockZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -232,7 +231,7 @@ public class BlockIterator implements Iterator<Point> {
|
|||||||
* unloaded chunks. A value of 0 indicates no limit
|
* unloaded chunks. A value of 0 indicates no limit
|
||||||
*/
|
*/
|
||||||
public BlockIterator(@NotNull Pos pos, double yOffset, int maxDistance) {
|
public BlockIterator(@NotNull Pos pos, double yOffset, int maxDistance) {
|
||||||
this(pos.toVector(), pos.getDirection(), yOffset, maxDistance);
|
this(pos.asVec(), pos.direction(), yOffset, maxDistance);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -246,7 +245,7 @@ public class BlockIterator implements Iterator<Point> {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public BlockIterator(@NotNull Pos pos, double yOffset) {
|
public BlockIterator(@NotNull Pos pos, double yOffset) {
|
||||||
this(pos.toVector(), pos.getDirection(), yOffset, 0);
|
this(pos.asVec(), pos.direction(), yOffset, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -305,7 +304,7 @@ public class BlockIterator implements Iterator<Point> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public BlockPosition next() throws NoSuchElementException {
|
public Point next() throws NoSuchElementException {
|
||||||
scan();
|
scan();
|
||||||
if (currentBlock <= -1) {
|
if (currentBlock <= -1) {
|
||||||
throw new NoSuchElementException();
|
throw new NoSuchElementException();
|
||||||
@ -337,29 +336,29 @@ public class BlockIterator implements Iterator<Point> {
|
|||||||
thirdError += thirdStep;
|
thirdError += thirdStep;
|
||||||
|
|
||||||
if (secondError > 0 && thirdError > 0) {
|
if (secondError > 0 && thirdError > 0) {
|
||||||
blockQueue[2] = blockQueue[0].getRelative(mainFace);
|
blockQueue[2] = blockQueue[0].relative(mainFace);
|
||||||
if (((long) secondStep) * ((long) thirdError) < ((long) thirdStep) * ((long) secondError)) {
|
if (((long) secondStep) * ((long) thirdError) < ((long) thirdStep) * ((long) secondError)) {
|
||||||
blockQueue[1] = blockQueue[2].getRelative(secondFace);
|
blockQueue[1] = blockQueue[2].relative(secondFace);
|
||||||
blockQueue[0] = blockQueue[1].getRelative(thirdFace);
|
blockQueue[0] = blockQueue[1].relative(thirdFace);
|
||||||
} else {
|
} else {
|
||||||
blockQueue[1] = blockQueue[2].getRelative(thirdFace);
|
blockQueue[1] = blockQueue[2].relative(thirdFace);
|
||||||
blockQueue[0] = blockQueue[1].getRelative(secondFace);
|
blockQueue[0] = blockQueue[1].relative(secondFace);
|
||||||
}
|
}
|
||||||
thirdError -= gridSize;
|
thirdError -= gridSize;
|
||||||
secondError -= gridSize;
|
secondError -= gridSize;
|
||||||
currentBlock = 2;
|
currentBlock = 2;
|
||||||
} else if (secondError > 0) {
|
} else if (secondError > 0) {
|
||||||
blockQueue[1] = blockQueue[0].getRelative(mainFace);
|
blockQueue[1] = blockQueue[0].relative(mainFace);
|
||||||
blockQueue[0] = blockQueue[1].getRelative(secondFace);
|
blockQueue[0] = blockQueue[1].relative(secondFace);
|
||||||
secondError -= gridSize;
|
secondError -= gridSize;
|
||||||
currentBlock = 1;
|
currentBlock = 1;
|
||||||
} else if (thirdError > 0) {
|
} else if (thirdError > 0) {
|
||||||
blockQueue[1] = blockQueue[0].getRelative(mainFace);
|
blockQueue[1] = blockQueue[0].relative(mainFace);
|
||||||
blockQueue[0] = blockQueue[1].getRelative(thirdFace);
|
blockQueue[0] = blockQueue[1].relative(thirdFace);
|
||||||
thirdError -= gridSize;
|
thirdError -= gridSize;
|
||||||
currentBlock = 1;
|
currentBlock = 1;
|
||||||
} else {
|
} else {
|
||||||
blockQueue[0] = blockQueue[0].getRelative(mainFace);
|
blockQueue[0] = blockQueue[0].relative(mainFace);
|
||||||
currentBlock = 0;
|
currentBlock = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.minestom.server.utils.coordinate;
|
package net.minestom.server.utils.coordinate;
|
||||||
|
|
||||||
|
import net.minestom.server.instance.block.BlockFace;
|
||||||
import net.minestom.server.utils.MathUtils;
|
import net.minestom.server.utils.MathUtils;
|
||||||
import net.minestom.server.utils.chunk.ChunkUtils;
|
import net.minestom.server.utils.chunk.ChunkUtils;
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
@ -110,6 +111,25 @@ public interface Point {
|
|||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
@NotNull Point div(double value);
|
@NotNull Point div(double value);
|
||||||
|
|
||||||
|
@Contract(pure = true)
|
||||||
|
default @NotNull Point relative(@NotNull BlockFace face) {
|
||||||
|
switch (face) {
|
||||||
|
case BOTTOM:
|
||||||
|
return sub(0, 1, 0);
|
||||||
|
case TOP:
|
||||||
|
return add(0, 1, 0);
|
||||||
|
case NORTH:
|
||||||
|
return sub(0, 0, 1);
|
||||||
|
case SOUTH:
|
||||||
|
return add(0, 0, 1);
|
||||||
|
case WEST:
|
||||||
|
return sub(1, 0, 0);
|
||||||
|
case EAST:
|
||||||
|
return add(1, 0, 0);
|
||||||
|
}
|
||||||
|
return this; // should never be called
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the distance between this point and another. The value of this
|
* Gets the distance between this point and another. The value of this
|
||||||
* method is not cached and uses a costly square-root function, so do not
|
* method is not cached and uses a costly square-root function, so do not
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package net.minestom.server.utils.coordinate;
|
package net.minestom.server.utils.coordinate;
|
||||||
|
|
||||||
|
import net.minestom.server.instance.block.BlockFace;
|
||||||
|
import net.minestom.server.utils.MathUtils;
|
||||||
import net.minestom.server.utils.Position;
|
import net.minestom.server.utils.Position;
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -57,6 +59,32 @@ public final class Pos implements Point {
|
|||||||
return new Pos(x, y, z, yaw, pitch);
|
return new Pos(x, y, z, yaw, pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the yaw and pitch to point
|
||||||
|
* in the direction of the point.
|
||||||
|
*/
|
||||||
|
@Contract(pure = true)
|
||||||
|
public @NotNull Pos withDirection(@NotNull Point point) {
|
||||||
|
/*
|
||||||
|
* Sin = Opp / Hyp
|
||||||
|
* Cos = Adj / Hyp
|
||||||
|
* Tan = Opp / Adj
|
||||||
|
*
|
||||||
|
* x = -Opp
|
||||||
|
* z = Adj
|
||||||
|
*/
|
||||||
|
final double _2PI = 2 * Math.PI;
|
||||||
|
final double x = point.x();
|
||||||
|
final double z = point.z();
|
||||||
|
if (x == 0 && z == 0) {
|
||||||
|
return withPitch(point.y() > 0 ? -90f : 90f);
|
||||||
|
}
|
||||||
|
final double theta = Math.atan2(-x, z);
|
||||||
|
final double xz = Math.sqrt(MathUtils.square(x) + MathUtils.square(z));
|
||||||
|
return withView((float) Math.toDegrees((theta + _2PI) % _2PI),
|
||||||
|
(float) Math.toDegrees(Math.atan(-point.y() / xz)));
|
||||||
|
}
|
||||||
|
|
||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
public @NotNull Pos withYaw(float yaw) {
|
public @NotNull Pos withYaw(float yaw) {
|
||||||
return new Pos(x, y, z, yaw, pitch);
|
return new Pos(x, y, z, yaw, pitch);
|
||||||
@ -223,6 +251,11 @@ public final class Pos implements Point {
|
|||||||
return div(value, value, value);
|
return div(value, value, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Pos relative(@NotNull BlockFace face) {
|
||||||
|
return (Pos) Point.super.relative(face);
|
||||||
|
}
|
||||||
|
|
||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
public float yaw() {
|
public float yaw() {
|
||||||
return yaw;
|
return yaw;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.minestom.server.utils.coordinate;
|
package net.minestom.server.utils.coordinate;
|
||||||
|
|
||||||
|
import net.minestom.server.instance.block.BlockFace;
|
||||||
import net.minestom.server.utils.MathUtils;
|
import net.minestom.server.utils.MathUtils;
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -158,6 +159,11 @@ public final class Vec implements Point {
|
|||||||
return div(value, value, value);
|
return div(value, value, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Vec relative(@NotNull BlockFace face) {
|
||||||
|
return (Vec) Point.super.relative(face);
|
||||||
|
}
|
||||||
|
|
||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
public @NotNull Vec neg() {
|
public @NotNull Vec neg() {
|
||||||
return new Vec(-x, -y, -z);
|
return new Vec(-x, -y, -z);
|
||||||
@ -401,6 +407,12 @@ public final class Vec implements Point {
|
|||||||
Math.abs(z) < 1E-6 ? 0 : z
|
Math.abs(z) < 1E-6 ? 0 : z
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Operator FLOOR = (x, y, z) -> new Vec(
|
||||||
|
MathUtils.floor(x),
|
||||||
|
MathUtils.floor(y),
|
||||||
|
MathUtils.floor(z)
|
||||||
|
);
|
||||||
|
|
||||||
@NotNull Vec apply(double x, double y, double z);
|
@NotNull Vec apply(double x, double y, double z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,13 +44,13 @@ public abstract class RelativeLocation<T extends Point> {
|
|||||||
*/
|
*/
|
||||||
public T from(@Nullable Entity entity) {
|
public T from(@Nullable Entity entity) {
|
||||||
final var entityPosition = entity != null ? entity.getPosition() : Pos.ZERO;
|
final var entityPosition = entity != null ? entity.getPosition() : Pos.ZERO;
|
||||||
return from(entityPosition);
|
return null;//from(entityPosition); FIXME
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiStatus.Experimental
|
@ApiStatus.Experimental
|
||||||
public T fromView(@Nullable Entity entity) {
|
public T fromView(@Nullable Entity entity) {
|
||||||
final var entityPosition = entity != null ? entity.getPosition() : Pos.ZERO;
|
final var entityPosition = entity != null ? entity.getPosition() : Pos.ZERO;
|
||||||
return fromView(entityPosition);
|
return null;//fromView(entityPosition); FIXME
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,7 +51,7 @@ public class PlayerInit {
|
|||||||
final Entity source = event.getEntity();
|
final Entity source = event.getEntity();
|
||||||
final Entity entity = event.getTarget();
|
final Entity entity = event.getTarget();
|
||||||
|
|
||||||
entity.takeKnockback(0.4f, Math.sin(source.getPosition().getYaw() * 0.017453292), -Math.cos(source.getPosition().getYaw() * 0.017453292));
|
entity.takeKnockback(0.4f, Math.sin(source.getPosition().yaw() * 0.017453292), -Math.cos(source.getPosition().yaw() * 0.017453292));
|
||||||
|
|
||||||
if (entity instanceof Player) {
|
if (entity instanceof Player) {
|
||||||
Player target = (Player) entity;
|
Player target = (Player) entity;
|
||||||
|
@ -52,11 +52,11 @@ public class ShootCommand extends Command {
|
|||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var pos = player.getPosition().clone().add(0D, player.getEyeHeight(), 0D);
|
var pos = player.getPosition().add(0D, player.getEyeHeight(), 0D);
|
||||||
//noinspection ConstantConditions - It should be impossible to execute a command without being in an instance
|
//noinspection ConstantConditions - It should be impossible to execute a command without being in an instance
|
||||||
projectile.setInstance(player.getInstance(), pos);
|
projectile.setInstance(player.getInstance(), pos);
|
||||||
var dir = pos.getDirection().multiply(30D);
|
var dir = pos.direction().mul(30D);
|
||||||
pos = pos.clone().add(dir.getX(), dir.getY(), dir.getZ());
|
pos = pos.add(dir);
|
||||||
projectile.shoot(pos, 1D, 0D);
|
projectile.shoot(pos, 1D, 0D);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import net.minestom.server.command.builder.CommandContext;
|
|||||||
import net.minestom.server.command.builder.arguments.ArgumentType;
|
import net.minestom.server.command.builder.arguments.ArgumentType;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
import net.minestom.server.utils.Position;
|
import net.minestom.server.utils.Position;
|
||||||
|
import net.minestom.server.utils.coordinate.Pos;
|
||||||
import net.minestom.server.utils.location.RelativeVec;
|
import net.minestom.server.utils.location.RelativeVec;
|
||||||
|
|
||||||
public class TeleportCommand extends Command {
|
public class TeleportCommand extends Command {
|
||||||
@ -40,7 +41,7 @@ public class TeleportCommand extends Command {
|
|||||||
final RelativeVec relativeVec = context.get("pos");
|
final RelativeVec relativeVec = context.get("pos");
|
||||||
final Position position = relativeVec.from(player).toPosition();
|
final Position position = relativeVec.from(player).toPosition();
|
||||||
|
|
||||||
player.teleport(position);
|
player.teleport(new Pos(position));
|
||||||
player.sendMessage(Component.text("You have been teleported to " + position));
|
player.sendMessage(Component.text("You have been teleported to " + position));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ import net.minestom.server.entity.LivingEntity;
|
|||||||
import net.minestom.server.entity.ai.goal.RandomStrollGoal;
|
import net.minestom.server.entity.ai.goal.RandomStrollGoal;
|
||||||
import net.minestom.server.entity.damage.DamageType;
|
import net.minestom.server.entity.damage.DamageType;
|
||||||
import net.minestom.server.event.entity.EntityAttackEvent;
|
import net.minestom.server.event.entity.EntityAttackEvent;
|
||||||
import net.minestom.server.utils.Vector;
|
import net.minestom.server.utils.coordinate.Vec;
|
||||||
|
|
||||||
public class ChickenCreature extends EntityCreature {
|
public class ChickenCreature extends EntityCreature {
|
||||||
|
|
||||||
@ -43,12 +43,10 @@ public class ChickenCreature extends EntityCreature {
|
|||||||
addEventCallback(EntityAttackEvent.class, event -> {
|
addEventCallback(EntityAttackEvent.class, event -> {
|
||||||
//System.out.println("CALL ATTACK");
|
//System.out.println("CALL ATTACK");
|
||||||
LivingEntity entity = (LivingEntity) event.getTarget();
|
LivingEntity entity = (LivingEntity) event.getTarget();
|
||||||
Vector velocity = getPosition().clone().getDirection().multiply(6);
|
Vec velocity = getPosition().direction().mul(6).withY(4);
|
||||||
velocity.setY(4f);
|
|
||||||
entity.damage(DamageType.fromEntity(this), -1);
|
entity.damage(DamageType.fromEntity(this), -1);
|
||||||
entity.setVelocity(velocity);
|
entity.setVelocity(velocity);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user