Initial commit
This commit is contained in:
+113
@@ -0,0 +1,113 @@
|
|||||||
|
# User-specific stuff
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
|
||||||
|
# Compiled class file
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# BlueJ files
|
||||||
|
*.ctxt
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.nar
|
||||||
|
*.ear
|
||||||
|
*.zip
|
||||||
|
*.tar.gz
|
||||||
|
*.rar
|
||||||
|
|
||||||
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
hs_err_pid*
|
||||||
|
|
||||||
|
*~
|
||||||
|
|
||||||
|
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||||
|
.fuse_hidden*
|
||||||
|
|
||||||
|
# KDE directory preferences
|
||||||
|
.directory
|
||||||
|
|
||||||
|
# Linux trash folder which might appear on any partition or disk
|
||||||
|
.Trash-*
|
||||||
|
|
||||||
|
# .nfs files are created when an open file is removed but is still being accessed
|
||||||
|
.nfs*
|
||||||
|
|
||||||
|
# General
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# Icon must end with two \r
|
||||||
|
Icon
|
||||||
|
|
||||||
|
# Thumbnails
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Files that might appear in the root of a volume
|
||||||
|
.DocumentRevisions-V100
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
.VolumeIcon.icns
|
||||||
|
.com.apple.timemachine.donotpresent
|
||||||
|
|
||||||
|
# Directories potentially created on remote AFP share
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
||||||
|
Network Trash Folder
|
||||||
|
Temporary Items
|
||||||
|
.apdisk
|
||||||
|
|
||||||
|
# Windows thumbnail cache files
|
||||||
|
Thumbs.db
|
||||||
|
Thumbs.db:encryptable
|
||||||
|
ehthumbs.db
|
||||||
|
ehthumbs_vista.db
|
||||||
|
|
||||||
|
# Dump file
|
||||||
|
*.stackdump
|
||||||
|
|
||||||
|
# Folder config file
|
||||||
|
[Dd]esktop.ini
|
||||||
|
|
||||||
|
# Recycle Bin used on file shares
|
||||||
|
$RECYCLE.BIN/
|
||||||
|
|
||||||
|
# Windows Installer files
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msix
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
|
||||||
|
# Windows shortcuts
|
||||||
|
*.lnk
|
||||||
|
|
||||||
|
target/
|
||||||
|
|
||||||
|
pom.xml.tag
|
||||||
|
pom.xml.releaseBackup
|
||||||
|
pom.xml.versionsBackup
|
||||||
|
pom.xml.next
|
||||||
|
|
||||||
|
release.properties
|
||||||
|
dependency-reduced-pom.xml
|
||||||
|
buildNumber.properties
|
||||||
|
.mvn/timing.properties
|
||||||
|
.mvn/wrapper/maven-wrapper.jar
|
||||||
|
.flattened-pom.xml
|
||||||
|
|
||||||
|
# Common working directory
|
||||||
|
run/
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
# PathfinderPath
|
||||||
|
|
||||||
|
PathfinderPath is an API that allows you to use minecraft pathfinder to get a list of locations from the starting point
|
||||||
|
up until the goal.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
This will initialize the path from location1 to location2 with pathfinder limit of 120 steps.
|
||||||
|
```java
|
||||||
|
Path path = new Path(location1, location2, 120);
|
||||||
|
```
|
||||||
|
|
||||||
|
This snippet demonstrates how to calculate path between the locations. Only result of SUCCESS will update the path list.
|
||||||
|
```java
|
||||||
|
PathCalculationResult result = path.recalculatePath();
|
||||||
|
|
||||||
|
if (result.equals(PathCalculationResult.SUCCESS)) {
|
||||||
|
List<Location> locations = path.getPath();
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>me.youhavetrouble</groupId>
|
||||||
|
<artifactId>ParticlePathfinder</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>ParticlePathfinder</name>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>${java.version}</source>
|
||||||
|
<target>${java.version}</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>papermc-repo</id>
|
||||||
|
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>sonatype</id>
|
||||||
|
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.destroystokyo.paper</groupId>
|
||||||
|
<artifactId>paper-api</artifactId>
|
||||||
|
<version>1.16.5-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot</artifactId>
|
||||||
|
<version>1.16.5-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
package me.youhavetrouble.pathfinderpath;
|
||||||
|
|
||||||
|
import com.destroystokyo.paper.entity.Pathfinder;
|
||||||
|
import net.minecraft.server.v1_16_R3.*;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.attribute.Attribute;
|
||||||
|
import org.bukkit.attribute.AttributeInstance;
|
||||||
|
import org.bukkit.craftbukkit.v1_16_R3.CraftWorld;
|
||||||
|
import org.bukkit.entity.Mob;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Path {
|
||||||
|
|
||||||
|
List<Location> path = new ArrayList<>();
|
||||||
|
Location startLocation, endLocation;
|
||||||
|
int pointLimit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param startLocation Location to start pathfinding from
|
||||||
|
* @param endLocation Location that pathfinder is trying to reach
|
||||||
|
* @param stepLimit Limit on how many maximum steps pathfinder will take
|
||||||
|
*/
|
||||||
|
public Path(Location startLocation, Location endLocation, int stepLimit) {
|
||||||
|
this.startLocation = startLocation;
|
||||||
|
this.endLocation = endLocation;
|
||||||
|
this.pointLimit = stepLimit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates path Location list for getPath(). Calling this from any other thread than primary will result in ASYNC_ERROR result.
|
||||||
|
*
|
||||||
|
* @return Result of calculating path
|
||||||
|
*/
|
||||||
|
public PathCalculationResult recalculatePath() {
|
||||||
|
|
||||||
|
if (!Bukkit.isPrimaryThread()) {
|
||||||
|
return PathCalculationResult.ASYNC_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear all current points
|
||||||
|
path.clear();
|
||||||
|
|
||||||
|
if (startLocation.getWorld() != endLocation.getWorld())
|
||||||
|
return PathCalculationResult.DIFFERENT_WORLD;
|
||||||
|
|
||||||
|
Mob mob = spawnMob(startLocation, pointLimit);
|
||||||
|
|
||||||
|
if (mob == null)
|
||||||
|
return PathCalculationResult.FAILED_TO_SPAWN_MOB;
|
||||||
|
|
||||||
|
Pathfinder.PathResult pathResult = mob.getPathfinder().findPath(endLocation);
|
||||||
|
|
||||||
|
if (pathResult == null)
|
||||||
|
return PathCalculationResult.PATH_NULL;
|
||||||
|
|
||||||
|
for (Location point : pathResult.getPoints()) {
|
||||||
|
// add the offset, so location points to the center of a block
|
||||||
|
point.add(0.5, 0.25, 0.5);
|
||||||
|
path.add(point);
|
||||||
|
}
|
||||||
|
mob.remove();
|
||||||
|
return PathCalculationResult.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStartLocation(Location startLocation) {
|
||||||
|
this.startLocation = startLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getStartLocation() {
|
||||||
|
return startLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndLocation(Location endLocation) {
|
||||||
|
this.endLocation = endLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getEndLocation() {
|
||||||
|
return endLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getDistance() {
|
||||||
|
return startLocation.distance(endLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getDistanceSquared() {
|
||||||
|
return startLocation.distanceSquared(endLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Location> getPath() {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Mob spawnMob(Location loc, int range) {
|
||||||
|
// Create an NMS entity without adding it to the world to prevent clients from rendering it
|
||||||
|
WorldServer nmsWorld = ((CraftWorld) loc.getWorld()).getHandle();
|
||||||
|
EntityInsentient nmsEntity = EntityTypes.EVOKER.createCreature(nmsWorld, null, null, null, BlockPosition.ZERO, EnumMobSpawn.TRIGGERED, false, false);
|
||||||
|
|
||||||
|
// If failed to spawn mob, return null
|
||||||
|
if (nmsEntity == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
nmsEntity.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
|
||||||
|
|
||||||
|
// Convert nms entity to bukkit entity
|
||||||
|
Mob mob = (Mob) nmsEntity.getBukkitEntity();
|
||||||
|
|
||||||
|
// This is for setting pathfinder range
|
||||||
|
AttributeInstance followRange = mob.getAttribute(Attribute.GENERIC_FOLLOW_RANGE);
|
||||||
|
if (followRange != null) {
|
||||||
|
followRange.setBaseValue(range);
|
||||||
|
}
|
||||||
|
return mob;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package me.youhavetrouble.pathfinderpath;
|
||||||
|
|
||||||
|
public enum PathCalculationResult {
|
||||||
|
|
||||||
|
SUCCESS, DIFFERENT_WORLD, FAILED_TO_SPAWN_MOB, PATH_NULL, ASYNC_ERROR
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user