mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-29 19:41:50 +01:00
Add setting for opening doors with the new pathfinder
This commit is contained in:
parent
d5dcd11d19
commit
cbd561b089
@ -58,27 +58,27 @@ public class Settings {
|
||||
CHAT_FORMAT_TO_TARGET("npc.chat.format.to-target", "[<npc>] -> You: <text>"),
|
||||
CHAT_FORMAT_WITH_TARGETS_TO_BYSTANDERS("npc.chat.format.with-targets-to-bystanders",
|
||||
"[<npc>] -> [<targets>]: <text>"),
|
||||
CHAT_MAX_NUMBER_OF_TARGETS("npc.chat.options.max-number-of-targets-to-show", 2),
|
||||
CHAT_MULTIPLE_TARGETS_FORMAT("npc.chat.options.multiple-targets-format",
|
||||
"<target>|, <target>| & <target>| & others"),
|
||||
CHAT_RANGE("npc.chat.options.range", 5),
|
||||
CHECK_MINECRAFT_VERSION("advanced.check-minecraft-version", true),
|
||||
DATABASE_DRIVER("storage.database.driver", ""),
|
||||
DATABASE_PASSWORD("storage.database.password", ""),
|
||||
DATABASE_URL("storage.database.url", ""),
|
||||
DATABASE_USERNAME("storage.database.username", ""),
|
||||
DEBUG_MODE("general.debug-mode", false),
|
||||
DEBUG_PATHFINDING("general.debug-pathfinding", false),
|
||||
DEFAULT_LOOK_CLOSE("npc.default.look-close.enabled", false),
|
||||
DEFAULT_LOOK_CLOSE_RANGE("npc.default.look-close.range", 5),
|
||||
DEFAULT_NPC_LIMIT("npc.limits.default-limit", 10),
|
||||
DEFAULT_PATHFINDING_RANGE("npc.default.pathfinding.range", 25F),
|
||||
DEFAULT_RANDOM_TALKER("npc.default.random-talker", true),
|
||||
DEFAULT_REALISTIC_LOOKING("npc.default.realistic-looking", false),
|
||||
DEFAULT_STATIONARY_TICKS("npc.default.stationary-ticks", -1),
|
||||
DEFAULT_TALK_CLOSE("npc.default.talk-close.enabled", false),
|
||||
DEFAULT_TALK_CLOSE_RANGE("npc.default.talk-close.range", 5),
|
||||
DEFAULT_TEXT("npc.default.text.0", "Hi, I'm <npc>!") {
|
||||
CHAT_MAX_NUMBER_OF_TARGETS("npc.chat.options.max-number-of-targets-to-show", 2),
|
||||
CHAT_MULTIPLE_TARGETS_FORMAT("npc.chat.options.multiple-targets-format",
|
||||
"<target>|, <target>| & <target>| & others"),
|
||||
CHAT_RANGE("npc.chat.options.range", 5),
|
||||
CHECK_MINECRAFT_VERSION("advanced.check-minecraft-version", true),
|
||||
DATABASE_DRIVER("storage.database.driver", ""),
|
||||
DATABASE_PASSWORD("storage.database.password", ""),
|
||||
DATABASE_URL("storage.database.url", ""),
|
||||
DATABASE_USERNAME("storage.database.username", ""),
|
||||
DEBUG_MODE("general.debug-mode", false),
|
||||
DEBUG_PATHFINDING("general.debug-pathfinding", false),
|
||||
DEFAULT_LOOK_CLOSE("npc.default.look-close.enabled", false),
|
||||
DEFAULT_LOOK_CLOSE_RANGE("npc.default.look-close.range", 5),
|
||||
DEFAULT_NPC_LIMIT("npc.limits.default-limit", 10),
|
||||
DEFAULT_PATHFINDING_RANGE("npc.default.pathfinding.range", 25F),
|
||||
DEFAULT_RANDOM_TALKER("npc.default.random-talker", true),
|
||||
DEFAULT_REALISTIC_LOOKING("npc.default.realistic-looking", false),
|
||||
DEFAULT_STATIONARY_TICKS("npc.default.stationary-ticks", -1),
|
||||
DEFAULT_TALK_CLOSE("npc.default.talk-close.enabled", false),
|
||||
DEFAULT_TALK_CLOSE_RANGE("npc.default.talk-close.range", 5),
|
||||
DEFAULT_TEXT("npc.default.text.0", "Hi, I'm <npc>!") {
|
||||
@Override
|
||||
public void loadFromKey(DataKey root) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
@ -94,6 +94,7 @@ public class Settings {
|
||||
MAX_SPEED("npc.limits.max-speed", 100),
|
||||
MAX_TEXT_RANGE("npc.chat.options.max-text-range", 500),
|
||||
MESSAGE_COLOUR("general.color-scheme.message", "<a>"),
|
||||
NEW_PATHFINDER_OPENS_DOORS("npc.pathfinding.new-finder-open-doors", false),
|
||||
NPC_ATTACK_DISTANCE("npc.pathfinding.attack-range", 1.75 * 1.75),
|
||||
NPC_COST("economy.npc.cost", 100D),
|
||||
PACKET_UPDATE_DELAY("npc.packets.update-delay", 30),
|
||||
|
@ -15,13 +15,20 @@ import net.citizensnpcs.api.ai.event.NavigationCancelEvent;
|
||||
import net.citizensnpcs.api.ai.event.NavigationCompleteEvent;
|
||||
import net.citizensnpcs.api.ai.event.NavigationReplaceEvent;
|
||||
import net.citizensnpcs.api.ai.event.NavigatorCallback;
|
||||
import net.citizensnpcs.api.astar.pathfinder.BlockExaminer;
|
||||
import net.citizensnpcs.api.astar.pathfinder.BlockSource;
|
||||
import net.citizensnpcs.api.astar.pathfinder.MinecraftBlockExaminer;
|
||||
import net.citizensnpcs.api.astar.pathfinder.PathPoint;
|
||||
import net.citizensnpcs.api.astar.pathfinder.PathPoint.PathCallback;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.util.Vector;
|
||||
@ -42,6 +49,9 @@ public class CitizensNavigator implements Navigator, Runnable {
|
||||
|
||||
public CitizensNavigator(NPC npc) {
|
||||
this.npc = npc;
|
||||
if (Setting.NEW_PATHFINDER_OPENS_DOORS.asBoolean()) {
|
||||
defaultParams.examiner(new DoorExaminer());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -272,6 +282,35 @@ public class CitizensNavigator implements Navigator, Runnable {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static class DoorExaminer implements BlockExaminer {
|
||||
@Override
|
||||
public float getCost(BlockSource source, PathPoint point) {
|
||||
return 0F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PassableState isPassable(BlockSource source, PathPoint point) {
|
||||
Material in = source.getMaterialAt(point.getVector());
|
||||
if (MinecraftBlockExaminer.isDoor(in)) {
|
||||
point.addCallback(new DoorOpener());
|
||||
return PassableState.PASSABLE;
|
||||
}
|
||||
return PassableState.IGNORE;
|
||||
}
|
||||
}
|
||||
|
||||
private static class DoorOpener implements PathCallback {
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void run(NPC npc, Block point, double radius) {
|
||||
if (radius < 2) {
|
||||
boolean bottom = (point.getData() & 8) == 0;
|
||||
Block set = bottom ? point : point.getRelative(BlockFace.DOWN);
|
||||
set.setData((byte) ((set.getData() & 7) | 4));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final Location STATIONARY_LOCATION = new Location(null, 0, 0, 0);
|
||||
private static int UNINITIALISED_SPEED = Integer.MIN_VALUE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user