Skip to content

Commit

Permalink
[LuaMod] 'giveItemStack' now tries to use inventory before hotbar.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unarelith committed Jul 17, 2020
1 parent 7eaac50 commit 103127e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions source/common/inventory/Inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ void Inventory::setStack(u16 x, u16 y, const std::string &stringID, u16 amount)
m_hasChanged = true;
}

bool Inventory::addStack(const std::string &stringID, u16 amount, u16 offset, u16 size) {
bool Inventory::addStack(const std::string &stringID, u16 amount, u16 offset, u16 size, bool mergeOnly) {
for (std::size_t i = offset ; i < (size ? offset + size : m_items.size()) ; ++i) {
if (m_items[i].item().id() == 0) {
if (m_items[i].item().id() == 0 && !mergeOnly) {
m_items[i] = ItemStack(stringID, amount);
m_hasChanged = true;
return true;
Expand Down
2 changes: 1 addition & 1 deletion source/common/inventory/Inventory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Inventory : public gk::ISerializable {
const ItemStack &getStack(u16 x, u16 y) const { return m_items.at(x + y * m_width); }
ItemStack &getStackRef(u16 x, u16 y) { return m_items.at(x + y * m_width); }
void setStack(u16 x, u16 y, const std::string &stringID, u16 amount = 1);
bool addStack(const std::string &stringID, u16 amount = 1, u16 offset = 0, u16 size = 0);
bool addStack(const std::string &stringID, u16 amount = 1, u16 offset = 0, u16 size = 0, bool mergeOnly = false);
bool addStack2(const std::string &stringID, u16 amount = 1); // Needed for Lua
void clearStack(u16 x, u16 y);

Expand Down
5 changes: 4 additions & 1 deletion source/server/lua/LuaMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ void LuaMod::despawnEntity(EntityWrapper &entity) {

void LuaMod::giveItemStack(ServerPlayer &player, ItemStack *itemStack) {
if (itemStack) {
player.inventory().addStack(itemStack->item().stringID(), itemStack->amount());
// FIXME: This should probably be moved to a mod
if (!player.inventory().addStack(itemStack->item().stringID(), itemStack->amount(), 9, 24, true))
player.inventory().addStack(itemStack->item().stringID(), itemStack->amount(), 0, 9);

m_worldController.server()->sendPlayerInvUpdate(player.clientID(), player.client());
}
else
Expand Down

0 comments on commit 103127e

Please sign in to comment.