diff --git a/mods/src/api/README.md b/mods/src/api/README.md index 173cab02..4ed4cb38 100644 --- a/mods/src/api/README.md +++ b/mods/src/api/README.md @@ -65,11 +65,11 @@ This includes: - Sets a block of `id:data` at the specified point, if the block is a sign, it will attempt to set lines 1 through 4 of the sign to the given text - For the API, the lines must be below 100 characters, however when loading signs MCPI will cap it at 16 characters (this can be disabled by patching out the call at `0xd1e2c`). - The lines are optional - - The wiki has a list of blocks: https://mcpirevival.miraheze.org/wiki/Minecraft:_Pi_Edition_Complete_Block_List, sign is 63 and wall sign is 68 + - The wiki has a [list of blocks](https://mcpirevival.miraheze.org/wiki/Minecraft:_Pi_Edition_Complete_Block_List), sign is 63 and wall sign is 68 - [x] `world.spawnEntity(x: int, y: int, z: int, type: int) -> int` - Spawns an entity of `type` at the given position - Entities with a type of 0 cannot be spawned - - The list of entity types can be found by running the command below, or on the wiki: https://mcpirevival.miraheze.org/wiki/Minecraft:_Pi_Edition_Complete_Entity_List + - The list of entity types can be found by running the command below, or on the [wiki](https://mcpirevival.miraheze.org/wiki/Minecraft:_Pi_Edition_Complete_Entity_List). - [x] `world.getEntityTypes() -> {type: int, name: str}` - Returns a list of known entity types, if there are modded entities this list may be incorrect - [x] `player.getAbsPos() -> {x: int, y: int, z: int}` @@ -89,8 +89,13 @@ Egdecases: - `world.removeEntities`/`player.removeEntities`/`entity.removeEntities` will not remove players when given 0 or -1 for type. - `entity.getName` will not get the name of non-player entities with a type id of 0 due to ambiguity. - All Raspberry Juice commands/responses involving the player name are designed around the MCJE username restrictions, not the much looser MCPI restrictions. They may cause problems. +- Chat messages will have `|` turned into `\` to prevent bad parsing +Extras: +- [x] `reborn.enableDangerMode` and `reborn.disableDangerMode` + - With "danger mode" enabled, chat messages will have `|` turned into `\` + ## How does it work? ![Reborn-API.png](Reborn-API.png) diff --git a/mods/src/api/Reborn-API.drawio b/mods/src/api/Reborn-API.drawio index df761783..a1fb0851 100644 --- a/mods/src/api/Reborn-API.drawio +++ b/mods/src/api/Reborn-API.drawio @@ -1,79 +1,79 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/mods/src/api/Reborn-API.png b/mods/src/api/Reborn-API.png index 4848bb30..f267d981 100644 Binary files a/mods/src/api/Reborn-API.png and b/mods/src/api/Reborn-API.png differ diff --git a/mods/src/api/api.cpp b/mods/src/api/api.cpp index 8d62a70e..15594985 100644 --- a/mods/src/api/api.cpp +++ b/mods/src/api/api.cpp @@ -122,6 +122,7 @@ static ProjectileHitEvent popProjectile() { } static const std::string fail = "Fail\n"; +bool safe_mode = true; std::string CommandServer_parse_injection(CommandServer_parse_t old, CommandServer *commandserver, ConnectedClient &client, const std::string &command) { size_t arg_start = command.find("("); if (arg_start == std::string::npos) return fail; @@ -178,9 +179,7 @@ std::string CommandServer_parse_injection(CommandServer_parse_t old, CommandServ if (ret != 1) return "0\n"; Entity *entity = commandserver->minecraft->level->getEntity(id); - if (entity != NULL) { - // It may be a good idea to check if the entity is a player before removing - // but it doesn't crash, just lock the player in place until you rejoin the world + if (entity != NULL && !entity->isPlayer()) { entity->remove(); return "1\n"; } @@ -202,7 +201,7 @@ std::string CommandServer_parse_injection(CommandServer_parse_t old, CommandServ std::string ret = ""; for (GuiMessage gm : commandserver->minecraft->gui.messages) { std::string message = gm.message; - std::replace(message.begin(), message.end(), '|', '\\'); + if (safe_mode) std::replace(message.begin(), message.end(), '|', '\\'); ret += "0," + message + "|"; } if (ret.size() > 1) ret.pop_back(); @@ -415,6 +414,10 @@ std::string CommandServer_parse_injection(CommandServer_parse_t old, CommandServ return std::to_string(commandserver->minecraft->player->x) + "," + std::to_string(commandserver->minecraft->player->y) + "," + std::to_string(commandserver->minecraft->player->z) + "\n"; + } else if (cmd == "reborn.enableDangerMode") { + safe_mode = false; + } else if (cmd == "reborn.disableDangerMode") { + safe_mode = true; } else { // Either invalid or a vanilla command, either way hand it off to the orignal handler return old(commandserver, client, command);