mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
added on_inventory_interact
This commit is contained in:
parent
fc04284b34
commit
2cec6c3f9a
4 changed files with 29 additions and 0 deletions
|
|
@ -127,6 +127,7 @@ struct WorldFuncsSet {
|
|||
bool onchunkremove;
|
||||
bool oninventoryopen;
|
||||
bool oninventoryclosed;
|
||||
bool oninventoryinteract;
|
||||
};
|
||||
|
||||
class ContentPackRuntime {
|
||||
|
|
|
|||
|
|
@ -431,14 +431,23 @@ void SlotView::clicked(Mousecode button) {
|
|||
ItemStack& grabbed = exchangeSlot->getStack();
|
||||
ItemStack& stack = *bound;
|
||||
|
||||
int action = -1;
|
||||
|
||||
if (button == Mousecode::BUTTON_1) {
|
||||
performLeftClick(stack, grabbed);
|
||||
action = 0;
|
||||
} else if (button == Mousecode::BUTTON_2) {
|
||||
performRightClick(stack, grabbed);
|
||||
action = 1;
|
||||
}
|
||||
|
||||
if (layout.updateFunc) {
|
||||
layout.updateFunc(layout.index, stack);
|
||||
}
|
||||
|
||||
const auto& input = gui.getInput();
|
||||
action = action | (input.pressed(Keycode::LEFT_SHIFT) ? 2 : 0);
|
||||
scripting::on_inventory_interact(inventoryId, layout.index, action);
|
||||
}
|
||||
|
||||
void SlotView::onFocus() {
|
||||
|
|
|
|||
|
|
@ -540,6 +540,22 @@ void scripting::on_inventory_closed(const Player* player, const Inventory& inven
|
|||
}
|
||||
}
|
||||
|
||||
void scripting::on_inventory_interact(int invid, int slot, int action) {
|
||||
auto args = [invid, slot, action](lua::State* L) {
|
||||
lua::pushinteger(L, invid);
|
||||
lua::pushinteger(L, slot);
|
||||
lua::pushinteger(L, action);
|
||||
return 3;
|
||||
};
|
||||
for (auto& [packid, pack] : content->getPacks()) {
|
||||
if (pack->worldfuncsset.oninventoryinteract) {
|
||||
lua::emit_event(
|
||||
lua::get_main_state(), packid + ":.inventoryinteract", args
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void scripting::on_player_tick(Player* player, int tps) {
|
||||
auto args = [=](lua::State* L) {
|
||||
lua::pushinteger(L, player ? player->getId() : -1);
|
||||
|
|
@ -761,6 +777,8 @@ void scripting::load_world_script(
|
|||
register_event(env, "on_inventory_open", prefix + ":.inventoryopen");
|
||||
funcsset.oninventoryclosed =
|
||||
register_event(env, "on_inventory_closed", prefix + ":.inventoryclosed");
|
||||
funcsset.oninventoryinteract =
|
||||
register_event(env, "on_inventory_interact", prefix + ":.inventoryinteract");
|
||||
}
|
||||
|
||||
void scripting::load_layout_script(
|
||||
|
|
|
|||
|
|
@ -108,6 +108,7 @@ namespace scripting {
|
|||
|
||||
void on_inventory_open(const Player* player, const Inventory& inventory);
|
||||
void on_inventory_closed(const Player* player, const Inventory& inventory);
|
||||
void on_inventory_interact(int invid, int slot, int action);
|
||||
|
||||
void on_player_tick(Player* player, int tps);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue