Skip to content

Commit df80343

Browse files
committed
Add path-find speed to raiderconfig
And code cleanup/fixes
1 parent 43e02ed commit df80343

9 files changed

Lines changed: 68 additions & 37 deletions

File tree

docs/user-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Refer to the [Configuration Guide](configurations.html).
1919
- `/lrshow` - displays the current wave
2020
- `/lrattack [prio] [target_thru_walls] [entity_class]` - makes all raiders of the current wave attack an entity type
2121
- `/lrconfig spawn <x> <y> <z>` - for the current large raid, make all future waves spawn from this location
22-
- `/lrconfig target <x> <y> <z> <radius>` - for the current large raid, make raiders path-find to this location within range of this radius
22+
- `/lrconfig target <x> <y> <z> <radius> <navSpeed>` - for the current large raid, make raiders path-find to this location within range of this radius
2323

2424
## Placeholders
2525

src/main/java/com/solarrabbit/largeraids/command/RaidConfigCommand.java

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
5050
sender.sendMessage(ChatColor.YELLOW + this.plugin.getMessage("raid-config.no-custom-spawn"));
5151
} else {
5252
sender.sendMessage(ChatColor.GREEN + String.format(this.plugin.getMessage("raid-config.current-custom-spawn"),
53-
Math.round(spawn.getX()), Math.round(spawn.getY()), Math.round(spawn.getZ())));
53+
(int)Math.floor(spawn.getX()), (int)Math.floor(spawn.getY()), (int)Math.floor(spawn.getZ())));
5454
}
5555
return true;
5656
}
@@ -60,7 +60,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
6060
sender.sendMessage(ChatColor.GREEN + this.plugin.getMessage("raid-config.custom-spawn-cleared"));
6161
return true;
6262
}
63-
if (args.length < 4)
63+
if (args.length != 4)
6464
return false;
6565

6666
try {
@@ -70,7 +70,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
7070
Location spawn = new Location(location.getWorld(), x, y, z);
7171
largeRaid.get().setSpawnLocation(spawn);
7272
sender.sendMessage(ChatColor.GREEN + String.format(this.plugin.getMessage("raid-config.custom-spawn-set"),
73-
Math.round(spawn.getX()), Math.round(spawn.getY()), Math.round(spawn.getZ())));
73+
(int)Math.floor(spawn.getX()), (int)Math.floor(spawn.getY()), (int)Math.floor(spawn.getZ())));
7474
return true;
7575
} catch (NumberFormatException e) {
7676
sender.sendMessage(ChatColor.RED + this.plugin.getMessage("raid-config.invalid-coordinates"));
@@ -83,18 +83,18 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
8383
sender.sendMessage(ChatColor.YELLOW + this.plugin.getMessage("raid-config.no-target"));
8484
} else {
8585
sender.sendMessage(ChatColor.GREEN + String.format(this.plugin.getMessage("raid-config.current-target"),
86-
Math.round(target.getX()), Math.round(target.getY()), Math.round(target.getZ()),
87-
largeRaid.get().getRaidTargetRadius()));
86+
(int)Math.floor(target.getX()), (int)Math.floor(target.getY()), (int)Math.floor(target.getZ()),
87+
largeRaid.get().getRaidTargetRadius(), largeRaid.get().getRaidTargetNavSpeed()));
8888
}
8989
return true;
9090
}
9191

9292
if (args.length == 2 && args[1].equals("clear")) {
93-
largeRaid.get().setRaidTarget(null, 0);
93+
largeRaid.get().setRaidTarget(null, 0, 0);
9494
sender.sendMessage(ChatColor.GREEN + this.plugin.getMessage("raid-config.target-cleared"));
9595
return true;
9696
}
97-
if (args.length < 5)
97+
if (args.length != 6)
9898
return false;
9999

100100
double x;
@@ -109,21 +109,35 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
109109
return false;
110110
}
111111

112+
double radius;
112113
try {
113-
double radius = Double.parseDouble(args[4]);
114+
radius = Double.parseDouble(args[4]);
114115
if (radius < 0) {
115116
sender.sendMessage(ChatColor.RED + this.plugin.getMessage("raid-config.invalid-radius"));
116117
return false;
117118
}
118-
Location target = new Location(location.getWorld(), x, y, z);
119-
largeRaid.get().setRaidTarget(target, radius);
120-
sender.sendMessage(ChatColor.GREEN + String.format(this.plugin.getMessage("raid-config.target-set"),
121-
Math.round(target.getX()), Math.round(target.getY()), Math.round(target.getZ()), radius));
122-
return true;
123119
} catch (NumberFormatException e) {
124120
sender.sendMessage(ChatColor.RED + this.plugin.getMessage("raid-config.invalid-radius"));
125121
return false;
126122
}
123+
124+
double navSpeed;
125+
try {
126+
navSpeed = Double.parseDouble(args[5]);
127+
if (navSpeed <= 0) {
128+
sender.sendMessage(ChatColor.RED + this.plugin.getMessage("raid-config.invalid-navspeed"));
129+
return false;
130+
}
131+
} catch (NumberFormatException e) {
132+
sender.sendMessage(ChatColor.RED + this.plugin.getMessage("raid-config.invalid-navspeed"));
133+
return false;
134+
}
135+
136+
Location target = new Location(location.getWorld(), x, y, z);
137+
largeRaid.get().setRaidTarget(target, radius, navSpeed);
138+
sender.sendMessage(ChatColor.GREEN + String.format(this.plugin.getMessage("raid-config.target-set"),
139+
(int)Math.floor(target.getX()), (int)Math.floor(target.getY()), (int)Math.floor(target.getZ()), radius, navSpeed));
140+
return true;
127141
default:
128142
return false;
129143
}
@@ -135,11 +149,11 @@ private double parseDoubleOrRelative(String pos, Location loc, int type) {
135149
double relative = pos.length() == 1 ? 0 : Double.parseDouble(pos.substring(1));
136150
switch (type) {
137151
case 0:
138-
return relative + Math.round(loc.getX() * 1000) / 1000D;
152+
return relative + loc.getX();
139153
case 1:
140-
return relative + Math.round(loc.getY() * 1000) / 1000D;
154+
return relative + loc.getY();
141155
case 2:
142-
return relative + Math.round(loc.getZ() * 1000) / 1000D;
156+
return relative + loc.getZ();
143157
default:
144158
return 0;
145159
}

src/main/java/com/solarrabbit/largeraids/command/RaiderAttackCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public RaiderAttackCommand(LargeRaids plugin) {
2727

2828
@Override
2929
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
30-
if (args.length < 3)
30+
if (args.length != 3)
3131
return false;
3232

3333
if (!(sender instanceof Player)) {

src/main/java/com/solarrabbit/largeraids/nms/AbstractRaiderWrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
public interface AbstractRaiderWrapper {
44
AbstractRaidWrapper getCurrentRaid();
55

6-
void setRaiderTarget(AbstractBlockPositionWrapper pos, double radius);
6+
void setRaiderTarget(AbstractBlockPositionWrapper pos, double radius, double navSpeed);
77

88
boolean addAttackGoal(int prio, boolean mustSee, Class<?> entityClass);
99
}

src/main/java/com/solarrabbit/largeraids/raid/LargeRaid.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public class LargeRaid {
6363
private Location raidSpawn;
6464
private Location raidTarget;
6565
private double raidTargetRadius;
66+
private double raidTargetNavSpeed;
6667

6768
/**
6869
* Constructs a large raid object.
@@ -465,18 +466,25 @@ public double getRaidTargetRadius() {
465466
return raidTargetRadius;
466467
}
467468

468-
public void setRaidTarget(Location target, double radius) {
469+
public double getRaidTargetNavSpeed() {
470+
return raidTargetNavSpeed;
471+
}
472+
473+
public void setRaidTarget(Location target, double radius, double navSpeed) {
469474
this.raidTarget = target;
470475
this.raidTargetRadius = radius;
476+
this.raidTargetNavSpeed = navSpeed;
471477
if (currentRaid != null) {
472478
setRaiderTarget();
473479
}
474480
}
475481

476482
private void setRaiderTarget() {
483+
AbstractBlockPositionWrapper target = raidTarget == null ? null
484+
: VersionUtil.getBlockPositionWrapper(raidTarget);
477485
for (Raider raider : currentRaid.getRaiders()) {
478486
AbstractRaiderWrapper wrapper = VersionUtil.getCraftRaiderWrapper(raider).getHandle();
479-
wrapper.setRaiderTarget(raidTarget == null ? null : VersionUtil.getBlockPositionWrapper(raidTarget), raidTargetRadius);
487+
wrapper.setRaiderTarget(target, raidTargetRadius, raidTargetNavSpeed);
480488
}
481489
}
482490

src/main/java/com/solarrabbit/largeraids/versioned/nms/PathfindToTargetGoal.java renamed to src/main/java/com/solarrabbit/largeraids/versioned/nms/RaiderPathfindToTargetGoal.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,26 @@
1616
import net.minecraft.world.entity.raid.Raids;
1717
import net.minecraft.world.phys.Vec3;
1818

19-
public class PathfindToTargetGoal<T extends Raider> extends PathfindToRaidGoal<T> {
19+
public class RaiderPathfindToTargetGoal<T extends Raider> extends PathfindToRaidGoal<T> {
2020
private static final int RECRUITMENT_SEARCH_TICK_DELAY = 20;
21-
private static final float SPEED_MODIFIER = 1.0F;
2221
private final T mob;
2322
private int recruitmentTick;
2423
private BlockPos targetPos;
2524
private double targetRadius;
25+
private double navSpeed;
26+
private boolean changed;
2627

27-
public PathfindToTargetGoal(T mob) {
28+
public RaiderPathfindToTargetGoal(T mob) {
2829
super(mob);
2930
this.mob = mob;
3031
this.setFlags(EnumSet.of(Goal.Flag.MOVE));
3132
}
3233

33-
public void setTargetPos(BlockPos pos, double radius) {
34+
public void setTargetPos(BlockPos pos, double radius, double navSpeed) {
3435
this.targetPos = pos;
3536
this.targetRadius = radius;
37+
this.navSpeed = pos == null ? 1 : navSpeed;
38+
this.changed = true;
3639
}
3740

3841
private boolean isCloseToGoal() {
@@ -65,11 +68,16 @@ public void tick() {
6568
this.recruitNearby(currentRaid);
6669
}
6770

68-
if (!this.mob.isPathFinding() || targetPos != null) {
69-
Vec3 posTowards = DefaultRandomPos.getPosTowards(this.mob, 15, 4, Vec3.atBottomCenterOf(
70-
targetPos != null ? targetPos : currentRaid.getCenter()), (float) (Math.PI / 2));
71+
if (this.changed) {
72+
this.mob.getNavigation().stop();
73+
this.changed = false;
74+
}
75+
if (!this.mob.isPathFinding()) {
76+
Vec3 posTowards = targetPos != null ? targetPos.getBottomCenter()
77+
: DefaultRandomPos.getPosTowards(this.mob, 15, 4, Vec3.atBottomCenterOf(
78+
currentRaid.getCenter()), (float) (Math.PI / 2));
7179
if (posTowards != null) {
72-
this.mob.getNavigation().moveTo(posTowards.x, posTowards.y, posTowards.z, SPEED_MODIFIER);
80+
this.mob.getNavigation().moveTo(posTowards.x, posTowards.y, posTowards.z, navSpeed);
7381
}
7482
}
7583
}

src/main/java/com/solarrabbit/largeraids/versioned/nms/RaiderWrapper.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ public RaidWrapper getCurrentRaid() {
2424
}
2525

2626
@Override
27-
public void setRaiderTarget(AbstractBlockPositionWrapper pos, double radius) {
27+
public void setRaiderTarget(AbstractBlockPositionWrapper pos, double radius, double navSpeed) {
2828
BlockPos blockPos = pos == null ? null : ((BlockPositionWrapper) pos).blockPos;
2929

3030
for (WrappedGoal goal : raider.goalSelector.getAvailableGoals()) {
3131
if (goal.getGoal().getClass() == PathfindToRaidGoal.class) {
3232
int prio = goal.getPriority();
3333
raider.goalSelector.removeGoal(goal.getGoal());
34-
PathfindToTargetGoal<Raider> newGoal = new PathfindToTargetGoal<>(raider);
35-
newGoal.setTargetPos(blockPos, radius);
34+
RaiderPathfindToTargetGoal<Raider> newGoal = new RaiderPathfindToTargetGoal<>(raider);
35+
newGoal.setTargetPos(blockPos, radius, navSpeed);
3636
raider.goalSelector.addGoal(prio, newGoal);
3737
break;
38-
} else if (goal.getGoal() instanceof PathfindToTargetGoal pathfindGoal) {
39-
pathfindGoal.setTargetPos(blockPos, radius);
38+
} else if (goal.getGoal() instanceof RaiderPathfindToTargetGoal raiderGoal) {
39+
raiderGoal.setTargetPos(blockPos, radius, navSpeed);
4040
break;
4141
}
4242
}

src/main/resources/messages.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ raid-config:
8484
current-custom-spawn: The wave spawn point is currently set to (%d, %d, %d).
8585
no-custom-spawn: This large raid is not using a specified spawn point.
8686
target-cleared: The raiders will no longer path-find to a specified target.
87-
target-set: The raiders will now target (%d, %d, %d) with a range of %.1f blocks.
88-
current-target: The raiders are targeting (%d, %d, %d) with a range of %.1f blocks.
87+
target-set: The raiders will now target (%d, %d, %d) with a range of %.1f blocks, with a path-find speed of %.1f.
88+
current-target: The raiders are targeting (%d, %d, %d) with a range of %.1f blocks, with a path-find speed of %.1f.
8989
no-target: The raiders do not have a specified target.
9090
invalid-radius: Radius must be a positive number!
91+
invalid-navspeed: Path-find navigation speed must be a positive number!
9192
invalid-coordinates: Invalid coordinates entered!

src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ commands:
4242
permission: largeraids.attack
4343
lrconfig:
4444
description: Configures some settings of the current large raid.
45-
usage: /<command> spawn <x> <y> <z>, /<command> target <x> <y> <z> <radius>, /<command> [spawn | target] clear
45+
usage: /<command> spawn <x> <y> <z>, /<command> target <x> <y> <z> <radius> <navSpeed>, /<command> [spawn | target] clear
4646
permission: largeraids.config
4747

4848
permissions:

0 commit comments

Comments
 (0)