From e610b778a9dfea653d7351f3fc6381b471aa7273 Mon Sep 17 00:00:00 2001 From: Sergwest Date: Fri, 8 Mar 2024 23:35:26 +0300 Subject: [PATCH 1/5] save from pulling all content-pack except base --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 2487d29e..606033f3 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,6 @@ appimage-build/ *.DS_Store *~ + +/res/content/* +!/res/content/base \ No newline at end of file From c6ed28d2508e181fd32bb16a8ad8f31927f4dcb1 Mon Sep 17 00:00:00 2001 From: Sergwest Date: Fri, 8 Mar 2024 23:39:05 +0300 Subject: [PATCH 2/5] add necessary-optional libraries --- src/interfaces/Object.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/interfaces/Object.h b/src/interfaces/Object.h index 5ffe1cb6..220d3253 100644 --- a/src/interfaces/Object.h +++ b/src/interfaces/Object.h @@ -1,7 +1,8 @@ #ifndef OBJECT_H #define OBJECT_H -#include "stdlib.h" +#include +#include #include class Level; From 212c30c866127c9b02870b5d83db1111ece3054d Mon Sep 17 00:00:00 2001 From: Sergwest Date: Fri, 8 Mar 2024 23:40:53 +0300 Subject: [PATCH 3/5] block on_item_use when activating on_item_use_on_block --- src/logic/PlayerController.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/logic/PlayerController.cpp b/src/logic/PlayerController.cpp index 1ebe8d0a..78e36273 100644 --- a/src/logic/PlayerController.cpp +++ b/src/logic/PlayerController.cpp @@ -298,17 +298,12 @@ void PlayerController::updateInteraction(){ blocksController->breakBlock(player.get(), target, x, y, z); } if (rclick && !input.shift) { - bool preventDefault = false; - - if (item->rt.funcsset.on_use) { - preventDefault |= scripting::on_item_use(player.get(), item); - } if (item->rt.funcsset.on_use_on_block) { - preventDefault |= scripting::on_item_use_on_block(player.get(), item, x, y, z); - } - if (preventDefault) { - return; - } + scripting::on_item_use_on_block(player.get(), item, x, y, z); + } else + if (item->rt.funcsset.on_use) { + scripting::on_item_use(player.get(), item); + } else return; } if (def && rclick){ if (!input.shift && target->rt.funcsset.oninteract) { From 3ac32b6696cd0b3c1395a404f4e06d1fe69bfead Mon Sep 17 00:00:00 2001 From: Sergwest Date: Sat, 9 Mar 2024 00:05:02 +0300 Subject: [PATCH 4/5] add updatefunc to slot, which will be emited every interaction with it --- src/frontend/InventoryView.cpp | 21 +++++++++++++++++++-- src/frontend/InventoryView.h | 2 ++ src/frontend/hud.cpp | 6 +++--- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/frontend/InventoryView.cpp b/src/frontend/InventoryView.cpp index 05fb768e..332cab33 100644 --- a/src/frontend/InventoryView.cpp +++ b/src/frontend/InventoryView.cpp @@ -31,6 +31,7 @@ SlotLayout::SlotLayout( glm::vec2 position, bool background, bool itemSource, + slotcallback updateFunc, slotcallback shareFunc, slotcallback rightClick ) @@ -38,6 +39,7 @@ SlotLayout::SlotLayout( position(position), background(background), itemSource(itemSource), + updateFunc(updateFunc), shareFunc(shareFunc), rightClick(rightClick) {} @@ -218,6 +220,9 @@ void SlotView::clicked(gui::GUI* gui, mousecode button) { if (layout.shareFunc) { layout.shareFunc(layout.index, stack); } + if (layout.updateFunc) { + layout.updateFunc(layout.index, stack); + } return; } if (!layout.itemSource && stack.accepts(grabbed)) { @@ -236,6 +241,9 @@ void SlotView::clicked(gui::GUI* gui, mousecode button) { } else if (button == mousecode::BUTTON_2) { if (layout.rightClick) { layout.rightClick(inventoryid, stack); + if (layout.updateFunc) { + layout.updateFunc(layout.index, stack); + } return; } if (layout.itemSource) @@ -258,6 +266,9 @@ void SlotView::clicked(gui::GUI* gui, mousecode button) { } } } + if (layout.updateFunc) { + layout.updateFunc(layout.index, stack); + } } void SlotView::onFocus(gui::GUI* gui) { @@ -384,10 +395,13 @@ static slotcallback readSlotFunc(InventoryView* view, gui::UiXmlReader& reader, static void readSlot(InventoryView* view, gui::UiXmlReader& reader, xml::xmlelement element) { int index = element->attr("index", "0").asInt(); bool itemSource = element->attr("item-source", "false").asBool(); - SlotLayout layout(index, glm::vec2(), true, itemSource, nullptr, nullptr); + SlotLayout layout(index, glm::vec2(), true, itemSource, nullptr, nullptr, nullptr); if (element->has("pos")) { layout.position = element->attr("pos").asVec2(); } + if (element->has("updatefunc")) { + layout.updateFunc = readSlotFunc(view, reader, element, "updatefunc"); + } if (element->has("sharefunc")) { layout.shareFunc = readSlotFunc(view, reader, element, "sharefunc"); } @@ -421,10 +435,13 @@ static void readSlotsGrid(InventoryView* view, gui::UiXmlReader& reader, xml::xm count = rows * cols; } bool itemSource = element->attr("item-source", "false").asBool(); - SlotLayout layout(-1, glm::vec2(), true, itemSource, nullptr, nullptr); + SlotLayout layout(-1, glm::vec2(), true, itemSource, nullptr, nullptr, nullptr); if (element->has("pos")) { layout.position = element->attr("pos").asVec2(); } + if (element->has("updatefunc")) { + layout.updateFunc = readSlotFunc(view, reader, element, "updatefunc"); + } if (element->has("sharefunc")) { layout.shareFunc = readSlotFunc(view, reader, element, "sharefunc"); } diff --git a/src/frontend/InventoryView.h b/src/frontend/InventoryView.h index 6124eccf..81e8a4e8 100644 --- a/src/frontend/InventoryView.h +++ b/src/frontend/InventoryView.h @@ -43,6 +43,7 @@ struct SlotLayout { glm::vec2 position; bool background; bool itemSource; + slotcallback updateFunc; slotcallback shareFunc; slotcallback rightClick; int padding = 0; @@ -51,6 +52,7 @@ struct SlotLayout { glm::vec2 position, bool background, bool itemSource, + slotcallback updateFunc, slotcallback shareFunc, slotcallback rightClick); }; diff --git a/src/frontend/hud.cpp b/src/frontend/hud.cpp index 3215980f..21800a22 100644 --- a/src/frontend/hud.cpp +++ b/src/frontend/hud.cpp @@ -145,7 +145,7 @@ std::shared_ptr Hud::createContentAccess() { accessInventory->getSlot(id-1).set(ItemStack(id, 1)); } - SlotLayout slotLayout(-1, glm::vec2(), false, true, + SlotLayout slotLayout(-1, glm::vec2(), false, true, nullptr, [=](uint, ItemStack& item) { auto copy = ItemStack(item); inventory->move(copy, indices); @@ -165,7 +165,7 @@ std::shared_ptr Hud::createContentAccess() { std::shared_ptr Hud::createHotbar() { auto inventory = player->getInventory(); - SlotLayout slotLayout(-1, glm::vec2(), false, false, nullptr, nullptr); + SlotLayout slotLayout(-1, glm::vec2(), false, false, nullptr, nullptr, nullptr); InventoryBuilder builder; builder.addGrid(10, 10, glm::vec2(), 4, true, slotLayout); auto view = builder.build(); @@ -185,7 +185,7 @@ Hud::Hud(Engine* engine, LevelFrontend* frontend, Player* player) { interaction = std::make_unique(); grabbedItemView = std::make_shared( - SlotLayout(-1, glm::vec2(), false, false, nullptr, nullptr) + SlotLayout(-1, glm::vec2(), false, false, nullptr, nullptr, nullptr) ); grabbedItemView->bind( 0, From 24dc38c7809b58e71fec23468e91469a13a9f0fe Mon Sep 17 00:00:00 2001 From: Sergwest Date: Sat, 9 Mar 2024 00:09:10 +0300 Subject: [PATCH 5/5] fixed block rclick function (error 2 commits ago) --- src/logic/PlayerController.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/logic/PlayerController.cpp b/src/logic/PlayerController.cpp index 78e36273..5d1ba910 100644 --- a/src/logic/PlayerController.cpp +++ b/src/logic/PlayerController.cpp @@ -298,12 +298,15 @@ void PlayerController::updateInteraction(){ blocksController->breakBlock(player.get(), target, x, y, z); } if (rclick && !input.shift) { + bool preventDefault = false; if (item->rt.funcsset.on_use_on_block) { - scripting::on_item_use_on_block(player.get(), item, x, y, z); - } else - if (item->rt.funcsset.on_use) { - scripting::on_item_use(player.get(), item); - } else return; + preventDefault = scripting::on_item_use_on_block(player.get(), item, x, y, z); + } else if (item->rt.funcsset.on_use) { + preventDefault = scripting::on_item_use(player.get(), item); + } + if (preventDefault) { + return; + } } if (def && rclick){ if (!input.shift && target->rt.funcsset.oninteract) {