Skip to content

Commit

Permalink
Add apply range parameter to playerfilter, fix an issue with missing …
Browse files Browse the repository at this point in the history
…translations
  • Loading branch information
fullwall committed Nov 5, 2023
1 parent cd83d25 commit 82304b1
Show file tree
Hide file tree
Showing 62 changed files with 136 additions and 207 deletions.
1 change: 0 additions & 1 deletion src/main/java/net/citizensnpcs/api/LocationLookup.java
Expand Up @@ -92,7 +92,6 @@ private void updateWorld(World world) {
worlds.remove(world.getUID());
return;
}

PhTreeF<Player> tree = worlds.computeIfAbsent(world.getUID(), uid -> PhTreeF.create(3));
tree.clear();
Location loc = new Location(null, 0, 0, 0);
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/net/citizensnpcs/api/ai/SimpleGoalEntry.java
Expand Up @@ -27,9 +27,8 @@ public boolean equals(Object obj) {
if (obj == null || getClass() != obj.getClass())
return false;
SimpleGoalEntry other = (SimpleGoalEntry) obj;
if (!Objects.equals(goal, other.goal)) {
if (!Objects.equals(goal, other.goal))
return false;
}
return priority == other.priority;
}

Expand Down
Expand Up @@ -14,9 +14,9 @@ public HandlerList getHandlers() {
return handlers;
}

private static final HandlerList handlers = new HandlerList();

public static HandlerList getHandlerList() {
return handlers;
}

private static final HandlerList handlers = new HandlerList();
}
Expand Up @@ -24,9 +24,9 @@ public HandlerList getHandlers() {
return handlers;
}

private static final HandlerList handlers = new HandlerList();

public static HandlerList getHandlerList() {
return handlers;
}

private static final HandlerList handlers = new HandlerList();
}
Expand Up @@ -14,9 +14,9 @@ public HandlerList getHandlers() {
return handlers;
}

private static final HandlerList handlers = new HandlerList();

public static HandlerList getHandlerList() {
return handlers;
}

private static final HandlerList handlers = new HandlerList();
}
Expand Up @@ -14,9 +14,9 @@ public HandlerList getHandlers() {
return handlers;
}

private static final HandlerList handlers = new HandlerList();

public static HandlerList getHandlerList() {
return handlers;
}

private static final HandlerList handlers = new HandlerList();
}
Expand Up @@ -24,7 +24,8 @@ public GroupNPCFlock(Iterable<NPC> npcs, double radius) {
public Collection<NPC> getNearby(final NPC npc) {
if (radius < 0)
return npcs;
return npcs.stream().filter(input -> input.getStoredLocation().distance(npc.getStoredLocation()) < radius).collect(Collectors.<NPC> toList());
return npcs.stream().filter(input -> input.getStoredLocation().distance(npc.getStoredLocation()) < radius)
.collect(Collectors.<NPC> toList());
}

public List<NPC> getNPCs() {
Expand Down
Expand Up @@ -143,7 +143,7 @@ public void setXYRange(int xrange, int yrange) {

@Override
public boolean shouldExecute() {
if (!npc.isSpawned() || npc.getNavigator().isNavigating() || paused || (delayedTicks-- > 0))
if (!npc.isSpawned() || npc.getNavigator().isNavigating() || paused || delayedTicks-- > 0)
return false;

Location dest = findRandomPosition();
Expand Down
Expand Up @@ -31,9 +31,10 @@ public int compareTo(Object o) {
if (!(o instanceof Entity))
return -1;
// If NPC and matches, return 0
else if ((CitizensAPI.getNPCRegistry().isNPC((Entity) o) && CitizensAPI.getNPCRegistry().isNPC(entity)
&& CitizensAPI.getNPCRegistry().getNPC((Entity) o).getUniqueId()
.equals(CitizensAPI.getNPCRegistry().getNPC(entity).getUniqueId())) || entity.equals(o))
else if (CitizensAPI.getNPCRegistry().isNPC((Entity) o)
&& CitizensAPI.getNPCRegistry().isNPC(entity) && CitizensAPI.getNPCRegistry().getNPC((Entity) o)
.getUniqueId().equals(CitizensAPI.getNPCRegistry().getNPC(entity).getUniqueId())
|| entity.equals(o))
return 0;
else
return 1;
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/net/citizensnpcs/api/ai/tree/Decorator.java
Expand Up @@ -36,7 +36,6 @@ public void reset() {
for (Runnable runnable : resetCallbacks) {
runnable.run();
}

wrapping.reset();
}

Expand All @@ -45,12 +44,10 @@ public BehaviorStatus run() {
for (Runnable runnable : runCallbacks) {
runnable.run();
}

BehaviorStatus status = wrapping.run();
for (Function<BehaviorStatus, BehaviorStatus> transformer : statusTransformers) {
status = transformer.apply(status);
}

return status;
}

Expand All @@ -60,7 +57,6 @@ public boolean shouldExecute() {
for (Predicate<Boolean> transformer : shouldExecutePredicates) {
shouldExecute = transformer.test(shouldExecute);
}

return shouldExecute;
}

Expand Down
Expand Up @@ -19,9 +19,8 @@ public boolean equals(Object obj) {
if (obj == null || getClass() != obj.getClass())
return false;
ForwardingBehaviorGoalAdapter other = (ForwardingBehaviorGoalAdapter) obj;
if (!Objects.equals(behavior, other.behavior)) {
if (!Objects.equals(behavior, other.behavior))
return false;
}
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/citizensnpcs/api/ai/tree/Selector.java
Expand Up @@ -134,5 +134,6 @@ public static Builder selecting(Collection<Behavior> behaviors) {
}

private static final Random RANDOM = new Random();
private static final Function<List<Behavior>, Behavior> RANDOM_SELECTION = behaviors -> behaviors.get(RANDOM.nextInt(behaviors.size()));
private static final Function<List<Behavior>, Behavior> RANDOM_SELECTION = behaviors -> behaviors
.get(RANDOM.nextInt(behaviors.size()));
}
14 changes: 7 additions & 7 deletions src/main/java/net/citizensnpcs/api/astar/AStarNode.java
Expand Up @@ -30,6 +30,13 @@ protected AStarNode getParent() {
return parent;
}

protected float getPathCost() {
return g + h;
}

@Override
public abstract int hashCode();

@SuppressWarnings("unchecked")
protected <T extends AStarNode> Iterable<T> orderedPath() {
if (parents != null)
Expand All @@ -43,11 +50,4 @@ protected <T extends AStarNode> Iterable<T> orderedPath() {
Collections.reverse(parents);
return (Iterable<T>) parents;
}

protected float getPathCost() {
return g + h;
}

@Override
public abstract int hashCode();
}
Expand Up @@ -60,5 +60,5 @@ public String toString() {
return "SimpleAStarStorage [closed=" + closed + ", open=" + open + "]";
}

public static final Supplier<AStarStorage> FACTORY = () -> new SimpleAStarStorage();
public static final Supplier<AStarStorage> FACTORY = SimpleAStarStorage::new;
}
Expand Up @@ -44,7 +44,6 @@ public PassableState isPassable(BlockSource source, PathPoint point) {
point.addCallback(new DoorOpener());
return PassableState.PASSABLE;
}

return PassableState.IGNORE;
}

Expand Down Expand Up @@ -97,7 +96,6 @@ public void run() {
cancel();
return;
}

if (npc.getStoredLocation().distance(doorCentre) > 1.8) {
close(npc, point);
cancel();
Expand Down Expand Up @@ -151,7 +149,10 @@ private void open(NPC npc, Block point) {

@Override
public void run(NPC npc, Block point, List<Block> path, int index) {
if (opened || (!MinecraftBlockExaminer.isDoor(point.getType()) && !MinecraftBlockExaminer.isGate(point.getType())) || (npc.getStoredLocation().distance(point.getLocation().add(0.5, 0, 0.5)) > 2.5))
if (opened
|| !MinecraftBlockExaminer.isDoor(point.getType())
&& !MinecraftBlockExaminer.isGate(point.getType())
|| npc.getStoredLocation().distance(point.getLocation().add(0.5, 0, 0.5)) > 2.5)
return;
open(npc, point);
opened = true;
Expand Down
Expand Up @@ -60,7 +60,6 @@ public PassableState isPassable(BlockSource source, PathPoint point) {
point.addCallback(new LadderClimber());
} else if (!canStandIn(above) || !canStandIn(in))
return PassableState.UNPASSABLE;

if (!canJumpOn(below)) {
if (point.getParentPoint() == null)
return PassableState.UNPASSABLE;
Expand All @@ -70,7 +69,6 @@ public PassableState isPassable(BlockSource source, PathPoint point) {
&& pos.clone().subtract(point.getParentPoint().getVector()).getY() == 1)
return PassableState.UNPASSABLE;
}

return PassableState.PASSABLE;
}

Expand Down Expand Up @@ -219,7 +217,6 @@ public static Location findValidLocation(Location location, int xradius, int yra
if (!base.getWorld().isChunkLoaded(base.getX() + x >> 4, base.getZ() + z >> 4)) {
continue;
}

Block relative = base.getRelative(x, y, z);
if (filter.apply(relative) && canStandOn(relative.getRelative(BlockFace.DOWN)))
return relative.getLocation();
Expand Down
Expand Up @@ -66,9 +66,8 @@ public boolean equals(Object obj) {
if (obj == null || getClass() != obj.getClass())
return false;
VectorNode other = (VectorNode) obj;
if (!Objects.equals(location, other.location)) {
if (!Objects.equals(location, other.location))
return false;
}
return true;
}

Expand Down
Expand Up @@ -112,7 +112,6 @@ public CommandContext(boolean clearFlags, CommandSender sender, String[] args) {
break;
}
}

if (inner != -1) {
valueFlags.put(args[i].toLowerCase().substring(2), args[inner]);
if (clearFlags) {
Expand Down Expand Up @@ -261,7 +260,6 @@ public Location getSenderLocation() throws CommandException {
} else if (sender instanceof BlockCommandSender) {
base = ((BlockCommandSender) sender).getBlock().getLocation();
}

if (hasValueFlag("location"))
return location = parseLocation(base, getFlag("location"));

Expand All @@ -278,7 +276,6 @@ public Location getSenderTargetBlockLocation() throws CommandException {
} else if (sender instanceof BlockCommandSender) {
base = ((BlockCommandSender) sender).getBlock().getLocation();
}

if (hasValueFlag("location"))
return location = parseLocation(base, getFlag("location"));

Expand Down Expand Up @@ -336,8 +333,7 @@ public boolean matches(String command) {
}

public EulerAngle parseEulerAngle(String input) {
List<Double> pose = Lists
.newArrayList(Iterables.transform(Splitter.on(',').split(input), Double::parseDouble));
List<Double> pose = Lists.newArrayList(Iterables.transform(Splitter.on(',').split(input), Double::parseDouble));
return new EulerAngle(pose.get(0), pose.get(1), pose.get(2));
}

Expand Down

0 comments on commit 82304b1

Please sign in to comment.