Commit 4119f8b7 authored by Paimon2022's avatar Paimon2022 Committed by Melledy
Browse files

Add coordinate support for spawn command (monster only)

Now the spawn command is: spawn <entityID> [amount] [level(monster only)] <x> <y> <z>(monster only, optional)
The coordinate is optional
parent 73a1c576
......@@ -23,7 +23,7 @@ import java.util.Random;
import static emu.grasscutter.Configuration.*;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "spawn", usage = "spawn <entityId> [amount] [level(monster only)]", permission = "server.spawn", permissionTargeted = "server.spawn.others", description = "commands.spawn.description")
@Command(label = "spawn", usage = "spawn <entityId> [amount] [level(monster only)] <x> <y> <z>(monster only, optional)", permission = "server.spawn", permissionTargeted = "server.spawn.others", description = "commands.spawn.description")
public final class SpawnCommand implements CommandHandler {
@Override
......@@ -31,7 +31,16 @@ public final class SpawnCommand implements CommandHandler {
int id = 0; // This is just to shut up the linter, it's not a real default
int amount = 1;
int level = 1;
float x = 0, y = 0, z = 0;
switch (args.size()) {
case 6:
try {
x = Float.parseFloat(args.get(3));
y = Float.parseFloat(args.get(4));
z = Float.parseFloat(args.get(5));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, translate(sender, "commands.execution.argument_error"));
} // Fallthrough
case 3:
try {
level = Integer.parseInt(args.get(2));
......@@ -77,6 +86,9 @@ public final class SpawnCommand implements CommandHandler {
double maxRadius = Math.sqrt(amount * 0.2 / Math.PI);
for (int i = 0; i < amount; i++) {
Position pos = GetRandomPositionInCircle(targetPlayer.getPos(), maxRadius).addY(3);
if(x != 0 && y != 0 && z != 0) {
pos = GetRandomPositionInCircle(new Position(x, y, z), maxRadius).addY(3);
}
GameEntity entity = null;
if (itemData != null) {
entity = new EntityItem(scene, null, itemData, pos, 1, true);
......
......@@ -304,7 +304,7 @@
"description": "Sets your world level (Relog to see proper effects)"
},
"spawn": {
"usage": "Usage: spawn <entityID> [amount] [level(monster only)]",
"usage": "Usage: spawn <entityID> [amount] [level(monster only)] <x> <y> <z>(monster only, optional)",
"success": "Spawned %s of %s.",
"limit_reached": "Scene spawn limit reached. Spawning %s entities instead.",
"description": "Spawns an entity near you"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment