Inventory (WIP part I)

This commit is contained in:
MihailRis
2024-01-21 15:23:46 +03:00
parent fe5cab0db0
commit 5142f3b4e7
13 changed files with 864 additions and 175 deletions
+17 -2
View File
@@ -13,6 +13,8 @@
#include "../window/Events.h"
#include "../window/input.h"
#include "../items/ItemDef.h"
#include "../items/ItemStack.h"
#include "../items/Inventory.h"
#include "scripting/scripting.h"
#include "BlocksController.h"
@@ -239,7 +241,9 @@ void PlayerController::updateInteraction(){
int z = iend.z;
uint8_t states = 0;
ItemDef* item = indices->getItemDef(player->getChosenItem());
auto inventory = player->getInventory();
ItemStack& stack = inventory->getSlot(player->getChosenSlot());
ItemDef* item = indices->getItemDef(stack.getItemId());
Block* def = indices->getBlockDef(item->rt.placingBlock);
if (def && def->rotatable){
const std::string& name = def->rotations.name;
@@ -311,7 +315,18 @@ void PlayerController::updateInteraction(){
}
if (Events::jactive(BIND_PLAYER_PICK)){
Block* block = indices->getBlockDef(chunks->get(x,y,z)->id);
player->setChosenItem(block->rt.pickingItem);
itemid_t id = block->rt.pickingItem;
auto inventory = player->getInventory();
size_t slotid = inventory->findSlotByItem(id);
if (slotid == Inventory::npos) {
slotid = player->getChosenSlot();
} else {
player->setChosenSlot(slotid);
}
ItemStack& stack = inventory->getSlot(slotid);
if (stack.getItemId() != id) {
stack.set(ItemStack(id, 1));
}
}
} else {
selectedBlockId = -1;