Add entity.get/setAbsPos
This commit is contained in:
parent
8bc143db17
commit
ae359de188
@ -103,7 +103,10 @@ Egdecases:
|
|||||||
|
|
||||||
Extras:
|
Extras:
|
||||||
- Compatibility mode, this is enabled by default, and can be changed with `reborn.disableCompatMode` or `reborn.enableCompatMode`.
|
- Compatibility mode, this is enabled by default, and can be changed with `reborn.disableCompatMode` or `reborn.enableCompatMode`.
|
||||||
- `events.clear`
|
- `entity.getAbsPos(id: int) -> {x: int, y: int, z: int}`
|
||||||
|
- Same as `player.getAbsPos`, but for the entity
|
||||||
|
- `entity.setAbsPos(id: int, x: int, y: int, z: int)`
|
||||||
|
- Same as `player.setAbsPos`, but for the entity
|
||||||
|
|
||||||
## How does it work?
|
## How does it work?
|
||||||
|
|
||||||
|
@ -257,7 +257,7 @@ std::string CommandServer_parse_injection(CommandServer_parse_t old, CommandServ
|
|||||||
|
|
||||||
// Redirect player commands to the entity command
|
// Redirect player commands to the entity command
|
||||||
if (commandserver->minecraft->player != NULL) {
|
if (commandserver->minecraft->player != NULL) {
|
||||||
if (cmd.starts_with(player_namespace) && cmd != "player.setting" && command != "player.getAbsPos" && command != "player.setAbsPos") {
|
if (cmd.starts_with(player_namespace) && cmd != "player.setting") {
|
||||||
cmd = "entity." + cmd.substr(player_namespace.size());
|
cmd = "entity." + cmd.substr(player_namespace.size());
|
||||||
args = std::to_string(commandserver->minecraft->player->id) + "," + args;
|
args = std::to_string(commandserver->minecraft->player->id) + "," + args;
|
||||||
}
|
}
|
||||||
@ -521,15 +521,21 @@ std::string CommandServer_parse_injection(CommandServer_parse_t old, CommandServ
|
|||||||
if (result.size() > 1) result.pop_back();
|
if (result.size() > 1) result.pop_back();
|
||||||
for (auto &c : result) c = toupper(c);
|
for (auto &c : result) c = toupper(c);
|
||||||
return result + "\n";
|
return result + "\n";
|
||||||
} else if (cmd == "player.setAbsPos" && commandserver->minecraft->player) {
|
} else if (cmd == "entity.setAbsPos") {
|
||||||
|
int id;
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
int ret = sscanf(args.c_str(), "%f,%f,%f", &x, &y, &z);
|
int ret = sscanf(args.c_str(), "%d,%f,%f,%f", &id, &x, &y, &z);
|
||||||
if (ret != 3) return fail;
|
Entity *entity = commandserver->minecraft->level->getEntity(id);
|
||||||
commandserver->minecraft->player->moveTo(x, y, z, commandserver->minecraft->player->yaw, commandserver->minecraft->player->pitch);
|
if (ret != 4 || entity == NULL) return fail;
|
||||||
} else if (cmd == "player.getAbsPos" && commandserver->minecraft->player) {
|
entity->moveTo(x, y, z, entity->yaw, entity->pitch);
|
||||||
return std::to_string(commandserver->minecraft->player->x) + ","
|
} else if (cmd == "entity.getAbsPos") {
|
||||||
+ std::to_string(commandserver->minecraft->player->y) + ","
|
int id;
|
||||||
+ std::to_string(commandserver->minecraft->player->z) + "\n";
|
int ret = sscanf(args.c_str(), "%d", &id);
|
||||||
|
Entity *entity = commandserver->minecraft->level->getEntity(id);
|
||||||
|
if (ret != 1 || entity == NULL) return fail;
|
||||||
|
return std::to_string(entity->x) + ","
|
||||||
|
+ std::to_string(entity->y) + ","
|
||||||
|
+ std::to_string(entity->z) + "\n";
|
||||||
} else if (cmd == "entity.events.clear") {
|
} else if (cmd == "entity.events.clear") {
|
||||||
int id;
|
int id;
|
||||||
int ret = sscanf(args.c_str(), "%d", &id);
|
int ret = sscanf(args.c_str(), "%d", &id);
|
||||||
|
Loading…
Reference in New Issue
Block a user