Skip to content

Commit

Permalink
feat: add playerWillDestroy,attack,pullInEntity
Browse files Browse the repository at this point in the history
feat: add playerWillDestroy,attack,pullInEntity
  • Loading branch information
KobeBryant114514 authored Jun 4, 2024
2 parents bf84cda + e9b4c33 commit b6c99dd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib/GMLIB_API-JS.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ 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"),
getBlockTranslateKeyFromName: ll.import("GMLIB_API", "getBlockTranslateKeyFromName")
}

const mStaticFloatingTextMap = new Map();
Expand Down Expand Up @@ -431,6 +435,10 @@ class Minecraft {
static readNbtFromFile(path, isBinary = true) {
return GMLIB_API.readNbtFromFile(path, isBinary);
}

static getBlockTranslateKeyFromName(name) {
return GMLIB_API.getBlockTranslateKeyFromName(name);
}
}

class Recipes {
Expand Down Expand Up @@ -990,6 +998,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,
Expand Down
19 changes: 19 additions & 0 deletions src/CompatibilityApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,4 +659,23 @@ 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<BlockPos, int> pos) -> bool {
return block->playerWillDestroy(*player, pos.first);
}
);
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);
});
RemoteCall::exportAs("GMLIB_API", "getBlockTranslateKeyFromName", [](std::string const& blockName) -> std::string {
if (auto block = Block::tryGetFromRegistry(blockName)) {
return block->buildDescriptionId();
}
return blockName;
});
}

0 comments on commit b6c99dd

Please sign in to comment.