mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-30 04:02:50 +01:00
789bc79280
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: c9a46ebf #653: Add World#spawn with randomizeData parameter e49c2e3a Damageable should extend ItemMeta 01ff04f4 SPIGOT-5880, SPIGOT-5567: New ChunkGenerator API ca5b4b1a SPIGOT-6697: Deprecate generateTree with BlockChangeDelegate as it does not handle tiles CraftBukkit Changes: 7c8bbcbe SPIGOT-6716: Preserve the order of stored enchantments of enchanted books. 18027d02 #914: Add World#spawn with randomizeData parameter 3cad0316 SPIGOT-6714: Don't fire PlayerBucketEvent when empty 8c6d60cf Fix server crash with BlockPopulator when entities are at a negative chunk border 4f6bcc84 SPIGOT-5880, SPIGOT-5567: New ChunkGenerator API 78d5b35b SPIGOT-6697: Restore generateTree with BlockChangeDelegate behaviour 15792f0d Rebuild patch c949675e SPIGOT-6713: Cancelling EntityTransformEvent Causes Deceased Slimes To Not Despawn a955f15c Fix issues with new ChunkGenerator API a0a37f41 SPIGOT-6630: Replacing an enchantment on an item creates a conflict error Spigot Changes: b166a49b Rebuild patches 3c1fc60a SPIGOT-6693: Composters only take in one item at custom hopper speeds
180 lines
6.5 KiB
Diff
180 lines
6.5 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Sun, 9 Sep 2018 13:30:00 -0400
|
|
Subject: [PATCH] Mob Pathfinding API
|
|
|
|
Implements Pathfinding API for mobs
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/entity/PaperPathfinder.java b/src/main/java/com/destroystokyo/paper/entity/PaperPathfinder.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..8c9f0c6c38627beded373ca29f1989ae3ba6f873
|
|
--- /dev/null
|
|
+++ b/src/main/java/com/destroystokyo/paper/entity/PaperPathfinder.java
|
|
@@ -0,0 +1,139 @@
|
|
+package com.destroystokyo.paper.entity;
|
|
+
|
|
+import org.apache.commons.lang.Validate;
|
|
+import org.bukkit.Location;
|
|
+import org.bukkit.craftbukkit.entity.CraftLivingEntity;
|
|
+import org.bukkit.entity.LivingEntity;
|
|
+import org.bukkit.entity.Mob;
|
|
+import javax.annotation.Nonnull;
|
|
+import javax.annotation.Nullable;
|
|
+import net.minecraft.world.level.pathfinder.Node;
|
|
+import net.minecraft.world.level.pathfinder.Path;
|
|
+import java.util.ArrayList;
|
|
+import java.util.List;
|
|
+
|
|
+public class PaperPathfinder implements com.destroystokyo.paper.entity.Pathfinder {
|
|
+
|
|
+ private final net.minecraft.world.entity.Mob entity;
|
|
+
|
|
+ public PaperPathfinder(net.minecraft.world.entity.Mob entity) {
|
|
+ this.entity = entity;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Mob getEntity() {
|
|
+ return entity.getBukkitMob();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void stopPathfinding() {
|
|
+ entity.getNavigation().stop();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean hasPath() {
|
|
+ return entity.getNavigation().getPath() != null;
|
|
+ }
|
|
+
|
|
+ @Nullable
|
|
+ @Override
|
|
+ public PathResult getCurrentPath() {
|
|
+ Path path = entity.getNavigation().getPath();
|
|
+ return path != null ? new PaperPathResult(path) : null;
|
|
+ }
|
|
+
|
|
+ @Nullable
|
|
+ @Override
|
|
+ public PathResult findPath(Location loc) {
|
|
+ Validate.notNull(loc, "Location can not be null");
|
|
+ Path path = entity.getNavigation().createPath(loc.getX(), loc.getY(), loc.getZ(), 0);
|
|
+ return path != null ? new PaperPathResult(path) : null;
|
|
+ }
|
|
+
|
|
+ @Nullable
|
|
+ @Override
|
|
+ public PathResult findPath(LivingEntity target) {
|
|
+ Validate.notNull(target, "Target can not be null");
|
|
+ Path path = entity.getNavigation().createPath(((CraftLivingEntity) target).getHandle(), 0);
|
|
+ return path != null ? new PaperPathResult(path) : null;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean moveTo(@Nonnull PathResult path, double speed) {
|
|
+ Validate.notNull(path, "PathResult can not be null");
|
|
+ Path pathEntity = ((PaperPathResult) path).path;
|
|
+ return entity.getNavigation().moveTo(pathEntity, speed);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean canOpenDoors() {
|
|
+ return entity.getNavigation().pathFinder.nodeEvaluator.canOpenDoors();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void setCanOpenDoors(boolean canOpenDoors) {
|
|
+ entity.getNavigation().pathFinder.nodeEvaluator.setCanOpenDoors(canOpenDoors);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean canPassDoors() {
|
|
+ return entity.getNavigation().pathFinder.nodeEvaluator.canPassDoors();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void setCanPassDoors(boolean canPassDoors) {
|
|
+ entity.getNavigation().pathFinder.nodeEvaluator.setCanPassDoors(canPassDoors);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean canFloat() {
|
|
+ return entity.getNavigation().pathFinder.nodeEvaluator.canFloat();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void setCanFloat(boolean canFloat) {
|
|
+ entity.getNavigation().pathFinder.nodeEvaluator.setCanFloat(canFloat);
|
|
+ }
|
|
+
|
|
+ public class PaperPathResult implements com.destroystokyo.paper.entity.PaperPathfinder.PathResult {
|
|
+
|
|
+ private final Path path;
|
|
+ PaperPathResult(Path path) {
|
|
+ this.path = path;
|
|
+ }
|
|
+
|
|
+ @Nullable
|
|
+ @Override
|
|
+ public Location getFinalPoint() {
|
|
+ Node point = path.getEndNode();
|
|
+ return point != null ? toLoc(point) : null;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public List<Location> getPoints() {
|
|
+ List<Location> points = new ArrayList<>();
|
|
+ for (Node point : path.nodes) {
|
|
+ points.add(toLoc(point));
|
|
+ }
|
|
+ return points;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public int getNextPointIndex() {
|
|
+ return path.getNextNodeIndex();
|
|
+ }
|
|
+
|
|
+ @Nullable
|
|
+ @Override
|
|
+ public Location getNextPoint() {
|
|
+ if (!path.hasNext()) {
|
|
+ return null;
|
|
+ }
|
|
+ return toLoc(path.nodes.get(path.getNextNodeIndex()));
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private Location toLoc(Node point) {
|
|
+ return new Location(entity.level.getWorld(), point.x, point.y, point.z);
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/net/minecraft/world/level/pathfinder/Path.java b/src/main/java/net/minecraft/world/level/pathfinder/Path.java
|
|
index 31d4431a60e742e2ca3b1a2abcce33954f599488..f4b6c2bf74884c0b53956788dcfcca784cfafca2 100644
|
|
--- a/src/main/java/net/minecraft/world/level/pathfinder/Path.java
|
|
+++ b/src/main/java/net/minecraft/world/level/pathfinder/Path.java
|
|
@@ -20,6 +20,7 @@ public class Path {
|
|
private final BlockPos target;
|
|
private final float distToTarget;
|
|
private final boolean reached;
|
|
+ public boolean hasNext() { return getNextNodeIndex() < this.nodes.size(); } // Paper
|
|
|
|
public Path(List<Node> nodes, BlockPos target, boolean reachesTarget) {
|
|
this.nodes = nodes;
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java
|
|
index ee84ae1baf959a496a4228edab89b9c0079bc615..140672d03dd2563d2b1fb905d79164ff53cf0b76 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java
|
|
@@ -12,8 +12,11 @@ import org.bukkit.loot.LootTable;
|
|
public abstract class CraftMob extends CraftLivingEntity implements Mob {
|
|
public CraftMob(CraftServer server, net.minecraft.world.entity.Mob entity) {
|
|
super(server, entity);
|
|
+ paperPathfinder = new com.destroystokyo.paper.entity.PaperPathfinder(entity); // Paper
|
|
}
|
|
|
|
+ private final com.destroystokyo.paper.entity.PaperPathfinder paperPathfinder; // Paper
|
|
+ @Override public com.destroystokyo.paper.entity.Pathfinder getPathfinder() { return paperPathfinder; } // Paper
|
|
@Override
|
|
public void setTarget(LivingEntity target) {
|
|
Preconditions.checkState(!this.getHandle().generation, "Cannot set target during world generation");
|