From 0872c064bb42e5ef7b91eafe2a475a32a410aead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=90=E6=B2=90=E5=91=80?= <163636894+zimuya4153@users.noreply.github.com> Date: Fri, 31 May 2024 18:41:49 +0800 Subject: [PATCH 1/4] feat: add playerWillDestroy,attack,pullInEntity --- lib/GMLIB_API-JS.js | 17 ++++++++++++++++- src/CompatibilityApi.cpp | 10 ++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/GMLIB_API-JS.js b/lib/GMLIB_API-JS.js index b42d52d..c086eb2 100644 --- a/lib/GMLIB_API-JS.js +++ b/lib/GMLIB_API-JS.js @@ -123,7 +123,10 @@ const GMLIB_API = { itemCanDestroyInCreative: ll.import("GMLIB_API", "itemCanDestroyInCreative"), itemCanDestroySpecial: ll.import("GMLIB_API", "itemCanDestroySpecial"), blockCanDropWithAnyTool: ll.import("GMLIB_API", "blockCanDropWithAnyTool"), - blockIsAlwaysDestroyable: ll.import("GMLIB_API", "blockIsAlwaysDestroyable") + blockIsAlwaysDestroyable: ll.import("GMLIB_API", "blockIsAlwaysDestroyable"), + blockPlayerWillDestroy: ll.import("GMLIB_API", "blockPlayerWillDestroy"), + playerAttack: ll.import("GMLIB_API", "playerAttack"), + playerPullInEntity: ll.import("GMLIB_API", "playerPullInEntity") } const FloatingTextList = []; @@ -1003,6 +1006,18 @@ LLSE_Block.prototype.isAlwaysDestroyable = function () { return GMLIB_API.blockIsAlwaysDestroyable(this); } +LLSE_Block.prototype.playerWillDestroy = function (player) { + return GMLIB_API.blockPlayerWillDestroy(this, player, this.pos); +} + +LLSE_Player.prototype.attack = function (entity) { + return GMLIB_API.playerAttack(this, entity); +} + +LLSE_Player.prototype.pullInEntity = function (entity) { + return GMLIB_API.playerPullInEntity(this, entity); +} + module.exports = { StaticFloatingText, DynamicFloatingText, diff --git a/src/CompatibilityApi.cpp b/src/CompatibilityApi.cpp index 3e1da76..94dd3aa 100644 --- a/src/CompatibilityApi.cpp +++ b/src/CompatibilityApi.cpp @@ -658,4 +658,14 @@ void Export_Compatibility_API() { RemoteCall::exportAs("GMLIB_API", "blockIsAlwaysDestroyable", [](Block const* block) -> bool { return block->getMaterial().isAlwaysDestroyable(); }); + RemoteCall::exportAs( + "GMLIB_API", + "blockPlayerWillDestroy", + [](Block const* block, Player* player, std::pair pos) -> bool { + return block->playerWillDestroy(*player, pos.first); + } + ); + RemoteCall::exportAs("GMLIB_API", "playerAttack", [](Player* player, Actor* entity) -> bool { + return player->attack(*entity, ActorDamageCause::EntityAttack); + }); } \ No newline at end of file From a13760c1c2d1d123a1737b8f57b30844dc7b4064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=90=E6=B2=90=E5=91=80?= <163636894+zimuya4153@users.noreply.github.com> Date: Fri, 31 May 2024 20:06:39 +0800 Subject: [PATCH 2/4] feat: add pullInEntity --- src/CompatibilityApi.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/CompatibilityApi.cpp b/src/CompatibilityApi.cpp index 94dd3aa..c8b3fb4 100644 --- a/src/CompatibilityApi.cpp +++ b/src/CompatibilityApi.cpp @@ -1,4 +1,6 @@ #include "Global.h" +#include "mc/world/item/ItemStackBase.h" +#include "mc/world/item/enchanting/Enchant.h" #include bool isInteger(const std::string& str) { @@ -668,4 +670,7 @@ void Export_Compatibility_API() { RemoteCall::exportAs("GMLIB_API", "playerAttack", [](Player* player, Actor* entity) -> bool { return player->attack(*entity, ActorDamageCause::EntityAttack); }); + RemoteCall::exportAs("GMLIB_API", "playerPullInEntity", [](Player* player, Actor* entity) -> bool { + return player->pullInEntity(*entity); + }); } \ No newline at end of file From 436370ddfead5cac0967a1a0d4d9c4559f04909c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=90=E6=B2=90=E5=91=80?= <163636894+zimuya4153@users.noreply.github.com> Date: Fri, 31 May 2024 20:07:29 +0800 Subject: [PATCH 3/4] Delete: Redundant include --- src/CompatibilityApi.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/CompatibilityApi.cpp b/src/CompatibilityApi.cpp index c8b3fb4..b8efc71 100644 --- a/src/CompatibilityApi.cpp +++ b/src/CompatibilityApi.cpp @@ -1,6 +1,4 @@ #include "Global.h" -#include "mc/world/item/ItemStackBase.h" -#include "mc/world/item/enchanting/Enchant.h" #include bool isInteger(const std::string& str) { From e9b4c33a66eb888dc485b9cab344a93d94cddc8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=90=E6=B2=90=E5=91=80?= <163636894+zimuya4153@users.noreply.github.com> Date: Fri, 31 May 2024 20:15:28 +0800 Subject: [PATCH 4/4] feat: add getBlockTranslateKeyFromName --- lib/GMLIB_API-JS.js | 7 ++++++- src/CompatibilityApi.cpp | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/GMLIB_API-JS.js b/lib/GMLIB_API-JS.js index c086eb2..3ceb2c9 100644 --- a/lib/GMLIB_API-JS.js +++ b/lib/GMLIB_API-JS.js @@ -126,7 +126,8 @@ const GMLIB_API = { blockIsAlwaysDestroyable: ll.import("GMLIB_API", "blockIsAlwaysDestroyable"), blockPlayerWillDestroy: ll.import("GMLIB_API", "blockPlayerWillDestroy"), playerAttack: ll.import("GMLIB_API", "playerAttack"), - playerPullInEntity: ll.import("GMLIB_API", "playerPullInEntity") + playerPullInEntity: ll.import("GMLIB_API", "playerPullInEntity"), + getBlockTranslateKeyFromName: ll.import("GMLIB_API", "getBlockTranslateKeyFromName") } const FloatingTextList = []; @@ -451,6 +452,10 @@ class Minecraft { static readNbtFromFile(path, isBinary = true) { return GMLIB_API.readNbtFromFile(path, isBinary); } + + static getBlockTranslateKeyFromName(name) { + return GMLIB_API.getBlockTranslateKeyFromName(name); + } } class Recipes { diff --git a/src/CompatibilityApi.cpp b/src/CompatibilityApi.cpp index b8efc71..83a76d2 100644 --- a/src/CompatibilityApi.cpp +++ b/src/CompatibilityApi.cpp @@ -671,4 +671,10 @@ void Export_Compatibility_API() { RemoteCall::exportAs("GMLIB_API", "playerPullInEntity", [](Player* player, Actor* entity) -> bool { return player->pullInEntity(*entity); }); + RemoteCall::exportAs("GMLIB_API", "getBlockTranslateKeyFromName", [](std::string const& blockName) -> std::string { + if (auto block = Block::tryGetFromRegistry(blockName)) { + return block->buildDescriptionId(); + } + return blockName; + }); } \ No newline at end of file