mirror of
https://github.com/Minestom/Minestom.git
synced 2024-09-28 22:47:41 +02:00
Small improvements to entity movement (#1421)
This commit is contained in:
parent
caaad1693e
commit
95fa6607ed
@ -75,7 +75,16 @@ public final class AttributeInstance {
|
|||||||
* @param modifier the modifier to remove
|
* @param modifier the modifier to remove
|
||||||
*/
|
*/
|
||||||
public void removeModifier(@NotNull AttributeModifier modifier) {
|
public void removeModifier(@NotNull AttributeModifier modifier) {
|
||||||
if (modifiers.remove(modifier.getId()) != null) {
|
removeModifier(modifier.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a modifier from this instance.
|
||||||
|
*
|
||||||
|
* @param uuid The UUID of the modifier to remove
|
||||||
|
*/
|
||||||
|
public void removeModifier(@NotNull UUID uuid) {
|
||||||
|
if (modifiers.remove(uuid) != null) {
|
||||||
refreshCachedValue();
|
refreshCachedValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import com.extollit.gaming.ai.path.HydrazinePathFinder;
|
|||||||
import com.extollit.gaming.ai.path.PathOptions;
|
import com.extollit.gaming.ai.path.PathOptions;
|
||||||
import com.extollit.gaming.ai.path.model.IPath;
|
import com.extollit.gaming.ai.path.model.IPath;
|
||||||
import net.minestom.server.collision.CollisionUtils;
|
import net.minestom.server.collision.CollisionUtils;
|
||||||
|
import net.minestom.server.collision.PhysicsResult;
|
||||||
import net.minestom.server.coordinate.Point;
|
import net.minestom.server.coordinate.Point;
|
||||||
import net.minestom.server.coordinate.Pos;
|
import net.minestom.server.coordinate.Pos;
|
||||||
import net.minestom.server.coordinate.Vec;
|
import net.minestom.server.coordinate.Vec;
|
||||||
@ -43,7 +44,7 @@ public final class Navigator {
|
|||||||
* @param direction the targeted position
|
* @param direction the targeted position
|
||||||
* @param speed define how far the entity will move
|
* @param speed define how far the entity will move
|
||||||
*/
|
*/
|
||||||
public void moveTowards(@NotNull Point direction, double speed) {
|
public PhysicsResult moveTowards(@NotNull Point direction, double speed) {
|
||||||
final Pos position = entity.getPosition();
|
final Pos position = entity.getPosition();
|
||||||
final double dx = direction.x() - position.x();
|
final double dx = direction.x() - position.x();
|
||||||
final double dy = direction.y() - position.y();
|
final double dy = direction.y() - position.y();
|
||||||
@ -62,6 +63,7 @@ public final class Navigator {
|
|||||||
// Prevent ghosting
|
// Prevent ghosting
|
||||||
final var physicsResult = CollisionUtils.handlePhysics(entity, new Vec(speedX, speedY, speedZ));
|
final var physicsResult = CollisionUtils.handlePhysics(entity, new Vec(speedX, speedY, speedZ));
|
||||||
this.entity.refreshPosition(physicsResult.newPosition().withView(yaw, pitch));
|
this.entity.refreshPosition(physicsResult.newPosition().withView(yaw, pitch));
|
||||||
|
return physicsResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void jump(float height) {
|
public void jump(float height) {
|
||||||
|
@ -3,6 +3,7 @@ package net.minestom.server.entity.pathfinding;
|
|||||||
import com.extollit.gaming.ai.path.model.IBlockDescription;
|
import com.extollit.gaming.ai.path.model.IBlockDescription;
|
||||||
import com.extollit.gaming.ai.path.model.IBlockObject;
|
import com.extollit.gaming.ai.path.model.IBlockObject;
|
||||||
import com.extollit.linalg.immutable.AxisAlignedBBox;
|
import com.extollit.linalg.immutable.AxisAlignedBBox;
|
||||||
|
import net.minestom.server.collision.Shape;
|
||||||
import net.minestom.server.instance.block.Block;
|
import net.minestom.server.instance.block.Block;
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -32,9 +33,10 @@ public final class PFBlock implements IBlockDescription, IBlockObject {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AxisAlignedBBox bounds() {
|
public AxisAlignedBBox bounds() {
|
||||||
|
Shape shape = this.block.registry().collisionShape();
|
||||||
return new AxisAlignedBBox(
|
return new AxisAlignedBBox(
|
||||||
0, 0, 0,
|
shape.relativeStart().x(), shape.relativeStart().y(), shape.relativeStart().z(),
|
||||||
1, 1, 1
|
shape.relativeEnd().x(), shape.relativeEnd().y(), shape.relativeEnd().z()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +49,7 @@ public final class PFBlock implements IBlockDescription, IBlockObject {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Return all walls
|
// Return all walls
|
||||||
// It just so happens that their namespace IDs all end with "door".
|
// It just so happens that their namespace IDs all end with "wall".
|
||||||
return block.namespace().asString().endsWith("wall");
|
return block.namespace().asString().endsWith("wall");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,60 +80,11 @@ public final class PFBlock implements IBlockDescription, IBlockObject {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFullyBounded() {
|
public boolean isFullyBounded() {
|
||||||
// TODO: Use Hitbox (would probably be faster as well)
|
Shape shape = block.registry().collisionShape();
|
||||||
// Return false for anything that does not have a full hitbox but impedes
|
return shape.relativeStart().isZero()
|
||||||
// e.g. Anvils, Lilypads, Ladders, Walls, Fences, EnchantmentTables
|
&& shape.relativeEnd().x() == 1.0d
|
||||||
// Fences & Walls
|
&& shape.relativeEnd().y() == 1.0d
|
||||||
if (isFenceLike()) {
|
&& shape.relativeEnd().z() == 1.0d;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Ladders and Vines
|
|
||||||
if (isClimbable()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// All doors/trapdoors.
|
|
||||||
if (isDoor()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (block.name().startsWith("potted")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Skulls & Heads
|
|
||||||
if (block.name().contains("skull") || block.name().contains("head")) {
|
|
||||||
// NOTE: blocks.getName().contains("head") also matches Piston_Head
|
|
||||||
// I could not find out by documentation if piston_head is fully bounded, I would presume it is NOT.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Carpets
|
|
||||||
if (block.name().endsWith("carpet")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Slabs
|
|
||||||
if (block.name().contains("slab")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Beds
|
|
||||||
if (block.name().endsWith("bed")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Glass Panes
|
|
||||||
if (block.name().endsWith("pane")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return !Block.CHORUS_FLOWER.compare(block) && !Block.CHORUS_PLANT.compare(block) && !Block.BAMBOO.compare(block)
|
|
||||||
&& !Block.BAMBOO_SAPLING.compare(block) && !Block.SEA_PICKLE.compare(block)
|
|
||||||
&& !Block.TURTLE_EGG.compare(block) && !Block.SNOW.compare(block) && !Block.FLOWER_POT.compare(block)
|
|
||||||
&& !Block.LILY_PAD.compare(block) && !Block.ANVIL.compare(block) && !Block.CHIPPED_ANVIL.compare(block)
|
|
||||||
&& !Block.DAMAGED_ANVIL.compare(block) && !Block.CAKE.compare(block) && !Block.CACTUS.compare(block)
|
|
||||||
&& !Block.BREWING_STAND.compare(block) && !Block.LECTERN.compare(block)
|
|
||||||
&& !Block.DAYLIGHT_DETECTOR.compare(block) && !Block.CAMPFIRE.compare(block)
|
|
||||||
&& !Block.SOUL_CAMPFIRE.compare(block) && !Block.ENCHANTING_TABLE.compare(block)
|
|
||||||
&& !Block.CHEST.compare(block) && !Block.ENDER_CHEST.compare(block) && !Block.GRINDSTONE.compare(block)
|
|
||||||
&& !Block.TRAPPED_CHEST.compare(block) && !Block.SOUL_SAND.compare(block)
|
|
||||||
&& !Block.SOUL_SOIL.compare(block) && !Block.LANTERN.compare(block) && !Block.COCOA.compare(block)
|
|
||||||
&& !Block.CONDUIT.compare(block) && !Block.DIRT_PATH.compare(block) && !Block.FARMLAND.compare(block)
|
|
||||||
&& !Block.END_ROD.compare(block) && !Block.STONECUTTER.compare(block) && !Block.BELL.compare(block);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -192,7 +192,10 @@ public final class PFPathingEntity implements IPathingEntity {
|
|||||||
public void moveTo(Vec3d position, Passibility passibility, Gravitation gravitation) {
|
public void moveTo(Vec3d position, Passibility passibility, Gravitation gravitation) {
|
||||||
final Point targetPosition = new Vec(position.x, position.y, position.z);
|
final Point targetPosition = new Vec(position.x, position.y, position.z);
|
||||||
this.navigator.moveTowards(targetPosition, getAttributeValue(Attribute.MOVEMENT_SPEED));
|
this.navigator.moveTowards(targetPosition, getAttributeValue(Attribute.MOVEMENT_SPEED));
|
||||||
final double entityY = entity.getPosition().y();
|
final double entityY = entity.getPosition().y() + 0.00001D; // After any negative y movement, entities will always be extremely
|
||||||
|
// slightly below floor level. This +0.00001D is here to offset this
|
||||||
|
// error and stop the entity from permanently jumping.
|
||||||
|
|
||||||
if (entityY < targetPosition.y()) {
|
if (entityY < targetPosition.y()) {
|
||||||
this.navigator.jump(1);
|
this.navigator.jump(1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user