feat: world spawn api

This commit is contained in:
Tsubasa6848
2024-03-23 19:42:59 +08:00
Unverified
parent a82a8cfb94
commit 35fc8a7a4f
3 changed files with 54 additions and 5 deletions
+28 -3
View File
@@ -82,7 +82,12 @@ const GMLIB_API = {
getAllScoreboardEntities: ll.import("GMLIB_API", "getAllScoreboardEntities"), getAllScoreboardEntities: ll.import("GMLIB_API", "getAllScoreboardEntities"),
getPlayerFromUuid: ll.import("GMLIB_API", "getPlayerFromUuid"), getPlayerFromUuid: ll.import("GMLIB_API", "getPlayerFromUuid"),
getPlayerFromUniqueId: ll.import("GMLIB_API", "getPlayerFromUniqueId"), getPlayerFromUniqueId: ll.import("GMLIB_API", "getPlayerFromUniqueId"),
getEntityFromUniqueId: ll.import("GMLIB_API", "getEntityFromUniqueId") getEntityFromUniqueId: ll.import("GMLIB_API", "getEntityFromUniqueId"),
getWorldSpawn: ll.import("GMLIB_API", "getWorldSpawn"),
setWorldSpawn: ll.import("GMLIB_API", "setWorldSpawn"),
getPlayerSpawnPoint: ll.import("GMLIB_API", "getPlayerSpawnPoint"),
setPlayerSpawnPoint: ll.import("GMLIB_API", "setPlayerSpawnPoint"),
clearPlayerSpawnPoint: ll.import("GMLIB_API", "clearPlayerSpawnPoint")
} }
const FloatingTextList = []; const FloatingTextList = [];
@@ -281,9 +286,9 @@ class Minecraft {
return nbt; return nbt;
} }
static setPlayerNbt(uuid, nbt) { static setPlayerNbt(uuid, nbt, forceCreate = true) {
let snbt = nbt.toSNBT(); let snbt = nbt.toSNBT();
return GMLIB_API.setPlayerNbt(uuid, snbt); return GMLIB_API.setPlayerNbt(uuid, snbt, forceCreate);
} }
static setPlayerNbtTags(uuid, nbt, tags) { static setPlayerNbtTags(uuid, nbt, tags) {
@@ -303,6 +308,26 @@ class Minecraft {
return GMLIB_API.setPlayerPosition(uuid, pos); return GMLIB_API.setPlayerPosition(uuid, pos);
} }
static getWorldSpawn() {
return GMLIB_API.getWorldSpawn();
}
static setWorldSpawn(pos) {
return GMLIB_API.setWorldSpawn(pos);
}
static getPlayerSpawnPoint() {
return GMLIB_API.getPlayerSpawnPoint();
}
static setPlayerSpawnPoint(pos) {
GMLIB_API.setPlayerSpawnPoint(pos);
}
static clearPlayerSpawnPoint() {
GMLIB_API.clearPlayerSpawnPoint();
}
static setEducationFeatureEnabled() { static setEducationFeatureEnabled() {
return GMLIB_API.setEducationFeatureEnabled(); return GMLIB_API.setEducationFeatureEnabled();
} }
+1
View File
@@ -1,6 +1,7 @@
{ {
"name": "${pluginName}", "name": "${pluginName}",
"entry": "${pluginFile}", "entry": "${pluginFile}",
"version": "0.9.3",
"type": "native", "type": "native",
"dependencies": [ "dependencies": [
{ {
+25 -2
View File
@@ -51,10 +51,10 @@ void Export_Compatibility_API() {
} }
return "null"; return "null";
}); });
RemoteCall::exportAs("GMLIB_API", "setPlayerNbt", [](std::string uuid, std::string snbt) -> bool { RemoteCall::exportAs("GMLIB_API", "setPlayerNbt", [](std::string uuid, std::string snbt, bool forceCreate) -> bool {
auto uid = mce::UUID::fromString(uuid); auto uid = mce::UUID::fromString(uuid);
auto nbt = CompoundTag::fromSnbt(snbt); auto nbt = CompoundTag::fromSnbt(snbt);
return GMLIB_Player::setPlayerNbt(uid, *nbt); return GMLIB_Player::setPlayerNbt(uid, *nbt, forceCreate);
}); });
RemoteCall::exportAs( RemoteCall::exportAs(
"GMLIB_API", "GMLIB_API",
@@ -392,4 +392,27 @@ void Export_Compatibility_API() {
auto auid = parseScriptUniqueID(uniqueId); auto auid = parseScriptUniqueID(uniqueId);
return ll::service::getLevel()->fetchEntity(auid); return ll::service::getLevel()->fetchEntity(auid);
}); });
RemoteCall::exportAs("GMLIB_API", "getWorldSpawn", []() -> std::pair<BlockPos, int> {
return {GMLIB_Level::getInstance()->getWorldSpawn(), 0};
});
RemoteCall::exportAs("GMLIB_API", "setWorldSpawn", [](std::pair<BlockPos, int> pos) -> bool {
if (pos.second != 0) {
return false;
}
GMLIB_Level::getInstance()->setWorldSpawn(pos.first);
return true;
});
RemoteCall::exportAs("GMLIB_API", "getPlayerSpawnPoint", [](Player* pl) -> std::pair<BlockPos, int> {
auto player = (GMLIB_Player*)pl;
auto res = player->getSpawnPoint();
return {res.first, res.second};
});
RemoteCall::exportAs("GMLIB_API", "setPlayerSpawnPoint", [](Player* pl, std::pair<BlockPos, int> pos) -> void {
auto player = (GMLIB_Player*)pl;
player->setSpawnPoint(pos.first, pos.second);
});
RemoteCall::exportAs("GMLIB_API", "clearPlayerSpawnPoint", [](Player* pl) -> void {
auto player = (GMLIB_Player*)pl;
player->clearSpawnPoint();
});
} }