导出canDestroy,playerDestroy,canDestroyInCreative,canDestroySpecial接口

This commit is contained in:
子沐呀
2024-05-28 17:36:43 +08:00
Unverified
parent 8f9447bcdb
commit 78721df3f0
2 changed files with 40 additions and 1 deletions
+21 -1
View File
@@ -117,7 +117,11 @@ const GMLIB_API = {
readNbtFromFile: ll.import("GMLIB_API", "readNbtFromFile"), readNbtFromFile: ll.import("GMLIB_API", "readNbtFromFile"),
saveNbtToFile: ll.import("GMLIB_API", "saveNbtToFile"), saveNbtToFile: ll.import("GMLIB_API", "saveNbtToFile"),
getBlockDestroySpeed: ll.import("GMLIB_API", "getBlockDestroySpeed"), 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 = []; const FloatingTextList = [];
@@ -973,6 +977,22 @@ LLSE_Item.prototype.getDestroyBlockSpeed = function (block) {
return GMLIB_API.getDestroyBlockSpeed(this, 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 = { module.exports = {
StaticFloatingText, StaticFloatingText,
DynamicFloatingText, DynamicFloatingText,
+19
View File
@@ -1,4 +1,7 @@
#include "Global.h" #include "Global.h"
#include "mc/world/Pos.h"
#include "mc/world/level/BlockPos.h"
#include "mc/world/level/BlockSource.h"
#include <regex> #include <regex>
bool isInteger(const std::string& str) { 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 { RemoteCall::exportAs("GMLIB_API", "getDestroyBlockSpeed", [](ItemStack const* item, Block const* block) -> float {
return item->getDestroySpeed(*block); return item->getDestroySpeed(*block);
}); });
RemoteCall::exportAs(
"GMLIB_API",
"playerDestroyBlock",
[](Block const* block, std::pair<BlockPos, int> 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);
});
} }