From 78721df3f0069725b9211ce9d8a32c5cab26c96c 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: Tue, 28 May 2024 17:36:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=87=BAcanDestroy=EF=BC=8CplayerDest?= =?UTF-8?q?roy=EF=BC=8CcanDestroyInCreative=EF=BC=8CcanDestroySpecial?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/GMLIB_API-JS.js | 22 +++++++++++++++++++++- src/CompatibilityApi.cpp | 19 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/lib/GMLIB_API-JS.js b/lib/GMLIB_API-JS.js index fc2c748..3c410e3 100644 --- a/lib/GMLIB_API-JS.js +++ b/lib/GMLIB_API-JS.js @@ -117,7 +117,11 @@ const GMLIB_API = { readNbtFromFile: ll.import("GMLIB_API", "readNbtFromFile"), saveNbtToFile: ll.import("GMLIB_API", "saveNbtToFile"), getBlockDestroySpeed: ll.import("GMLIB_API", "getBlockDestroySpeed"), - getDestroyBlockSpeed: ll.import("GMLIB_API", "getDestroyBlockSpeed") + getDestroyBlockSpeed: ll.import("GMLIB_API", "getDestroyBlockSpeed"), + playerDestroyBlock: ll.import("GMLIB_API", "playerDestroyBlock"), + itemCanDestroyBlock: ll.import("GMLIB_API", "itemCanDestroyBlock"), + itemCanDestroyInCreative: ll.import("GMLIB_API", "itemCanDestroyInCreative"), + itemCanDestroySpecial: ll.import("GMLIB_API", "itemCanDestroySpecial") } const FloatingTextList = []; @@ -973,6 +977,22 @@ LLSE_Item.prototype.getDestroyBlockSpeed = function (block) { return GMLIB_API.getDestroyBlockSpeed(this, block); } +LLSE_Block.prototype.playerDestroy = function (player) { + GMLIB_API.playerDestroyBlock(this, this.pos, player); +} + +LLSE_Item.prototype.canDestroy = function (block) { + return GMLIB_API.itemCanDestroyBlock(this, block); +} + +LLSE_Item.prototype.canDestroyInCreative = function () { + return GMLIB_API.itemCanDestroyInCreative(this); +} + +LLSE_Item.prototype.canDestroySpecial = function (block) { + return GMLIB_API.itemCanDestroySpecial(this, block); +} + module.exports = { StaticFloatingText, DynamicFloatingText, diff --git a/src/CompatibilityApi.cpp b/src/CompatibilityApi.cpp index b3e82e0..95f6e82 100644 --- a/src/CompatibilityApi.cpp +++ b/src/CompatibilityApi.cpp @@ -1,4 +1,7 @@ #include "Global.h" +#include "mc/world/Pos.h" +#include "mc/world/level/BlockPos.h" +#include "mc/world/level/BlockSource.h" #include bool isInteger(const std::string& str) { @@ -636,4 +639,20 @@ void Export_Compatibility_API() { RemoteCall::exportAs("GMLIB_API", "getDestroyBlockSpeed", [](ItemStack const* item, Block const* block) -> float { return item->getDestroySpeed(*block); }); + RemoteCall::exportAs( + "GMLIB_API", + "playerDestroyBlock", + [](Block const* block, std::pair pos, Player* player) -> void { + return block->playerDestroy(*player, pos.first); + } + ); + RemoteCall::exportAs("GMLIB_API", "itemCanDestroyBlock", [](ItemStack const* item, Block const* block) -> bool { + return item->canDestroy(block); + }); + RemoteCall::exportAs("GMLIB_API", "itemCanDestroyInCreative", [](ItemStack const* item) -> bool { + return item->getItem()->canDestroyInCreative(); + }); + RemoteCall::exportAs("GMLIB_API", "itemCanDestroySpecial", [](ItemStack const* item, Block const* block) -> bool { + return item->canDestroySpecial(*block); + }); } \ No newline at end of file