Skip to content

Commit

Permalink
addWaypoint method for LWP
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jan 6, 2022
1 parent fdba356 commit e4ca2f2
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 3 deletions.
7 changes: 4 additions & 3 deletions main/src/main/java/net/citizensnpcs/commands/NPCCommands.java
Expand Up @@ -1946,7 +1946,7 @@ public void sheep(CommandContext args, CommandSender sender, NPC npc) throws Com

@Command(
aliases = { "npc" },
usage = "shop (name) (editr)",
usage = "shop (name) (edit|show)",
desc = "NPC shop edit/show",
modifiers = { "shop" },
min = 1,
Expand All @@ -1956,8 +1956,9 @@ public void shop(CommandContext args, Player sender, NPC npc) throws CommandExce
ShopTrait trait = npc.getOrAddTrait(ShopTrait.class);
if (args.argsLength() > 1) {
NPCShop shop = trait.getShop(args.getString(1));
if (args.getString(1).equalsIgnoreCase("edit")) {
} else if (args.getString(1).equalsIgnoreCase("show") && args.argsLength() == 3) {
if (args.getString(2).equalsIgnoreCase("edit")) {
shop.displayEditor(sender);
} else if (args.getString(2).equalsIgnoreCase("show") && args.argsLength() == 3) {
shop.display(sender);
} else {
throw new CommandUsageException();
Expand Down
59 changes: 59 additions & 0 deletions main/src/main/java/net/citizensnpcs/npc/ai/FallingExaminer.java
@@ -0,0 +1,59 @@
package net.citizensnpcs.npc.ai;

import java.util.List;

import org.bukkit.Material;
import org.bukkit.util.Vector;

import net.citizensnpcs.api.astar.pathfinder.BlockSource;
import net.citizensnpcs.api.astar.pathfinder.MinecraftBlockExaminer;
import net.citizensnpcs.api.astar.pathfinder.NeighbourGeneratorBlockExaminer;
import net.citizensnpcs.api.astar.pathfinder.PathPoint;
import net.citizensnpcs.api.astar.pathfinder.VectorNode;

public class FallingExaminer implements NeighbourGeneratorBlockExaminer {
private final int maxFallDistance;

public FallingExaminer(int maxFallDistance) {
this.maxFallDistance = maxFallDistance;
}

@Override
public float getCost(BlockSource source, PathPoint point) {
return 0;
}

@Override
public List<PathPoint> getNeighbours(BlockSource source, PathPoint point) {
Vector pos = point.getVector();
List<PathPoint> neighbours = ((VectorNode) point).getNeighbours(source, point);
if (pos.getBlockY() <= 1)
return neighbours;

Material above = source.getMaterialAt(pos.getBlockX(), pos.getBlockY() + 1, pos.getBlockZ());
Material below = source.getMaterialAt(pos.getBlockX(), pos.getBlockY() - 1, pos.getBlockZ());
Material in = source.getMaterialAt(pos);
if (!MinecraftBlockExaminer.canStandOn(below) && MinecraftBlockExaminer.canStandIn(above, in)) {
if (!point.data().has("fallen")) {
neighbours.add(point);
point.data().set("fallen", 0);
} else if (point.data().<Integer> get("fallen") < maxFallDistance) {
point.data().set("fallen", point.data().get("fallen", 0) + 1);
neighbours.add(point.createAtOffset(new Vector(0, -1, 0)));
}
} else {
if (point.data().has("fallen")) {
point.data().remove("fallen");
}
}
return neighbours;
}

@Override
public PassableState isPassable(BlockSource source, PathPoint point) {
if (point.data().has("fallen")) {
return PassableState.PASSABLE;
}
return PassableState.IGNORE;
}
}
3 changes: 3 additions & 0 deletions main/src/main/java/net/citizensnpcs/trait/ShopTrait.java
Expand Up @@ -37,6 +37,9 @@ private NPCShop(String name) {

public void display(Player sender) {
}

public void displayEditor(Player sender) {
}
}

@Persist(value = "npcShops", namespace = "shopstrait")
Expand Down
Expand Up @@ -69,6 +69,10 @@ public LinearWaypointProvider(NPC npc) {
this.npc = npc;
}

public void addWaypoint(Waypoint waypoint) {
waypoints.add(waypoint);
}

@Override
public WaypointEditor createEditor(CommandSender sender, CommandContext args) {
if (args.hasFlag('h')) {
Expand Down

0 comments on commit e4ca2f2

Please sign in to comment.