mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-08 12:31:51 +00:00
move 'player.pick' binding handler to Lua
This commit is contained in:
parent
22d207ba28
commit
9164edf971
6 changed files with 34 additions and 31 deletions
|
|
@ -26,7 +26,6 @@ inline const std::string BIND_PLAYER_FLIGHT = "player.flight";
|
|||
inline const std::string BIND_PLAYER_ATTACK = "player.attack";
|
||||
inline const std::string BIND_PLAYER_DESTROY = "player.destroy";
|
||||
inline const std::string BIND_PLAYER_BUILD = "player.build";
|
||||
inline const std::string BIND_PLAYER_PICK = "player.pick";
|
||||
inline const std::string BIND_PLAYER_FAST_INTERACTOIN =
|
||||
"player.fast_interaction";
|
||||
inline const std::string BIND_HUD_INVENTORY = "hud.inventory";
|
||||
|
|
|
|||
|
|
@ -23,10 +23,13 @@ size_t Inventory::findEmptySlot(size_t begin, size_t end) const {
|
|||
return npos;
|
||||
}
|
||||
|
||||
size_t Inventory::findSlotByItem(itemid_t id, size_t begin, size_t end) {
|
||||
size_t Inventory::findSlotByItem(
|
||||
itemid_t id, size_t begin, size_t end, size_t minCount
|
||||
) {
|
||||
end = std::min(slots.size(), end);
|
||||
for (size_t i = begin; i < end; i++) {
|
||||
if (slots[i].getItemId() == id) {
|
||||
const auto& stack = slots[i];
|
||||
if (stack.getItemId() == id && stack.getCount() >= minCount) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,9 @@ public:
|
|||
|
||||
ItemStack& getSlot(size_t index);
|
||||
size_t findEmptySlot(size_t begin = 0, size_t end = -1) const;
|
||||
size_t findSlotByItem(itemid_t id, size_t begin = 0, size_t end = -1);
|
||||
size_t findSlotByItem(
|
||||
itemid_t id, size_t begin = 0, size_t end = -1, size_t minCount = 1
|
||||
);
|
||||
|
||||
inline size_t size() const {
|
||||
return slots.size();
|
||||
|
|
|
|||
|
|
@ -341,28 +341,6 @@ static int determine_rotation(
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void pick_block(
|
||||
ContentIndices* indices,
|
||||
const Block& block,
|
||||
Player& player,
|
||||
int x,
|
||||
int y,
|
||||
int z
|
||||
) {
|
||||
itemid_t id = block.rt.pickingItem;
|
||||
auto inventory = player.getInventory();
|
||||
size_t slotid = inventory->findSlotByItem(id, 0, 10);
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
voxel* PlayerController::updateSelection(float maxDistance) {
|
||||
auto indices = level.content->getIndices();
|
||||
auto& chunks = *player.chunks;
|
||||
|
|
@ -568,10 +546,6 @@ void PlayerController::updateInteraction(float delta) {
|
|||
if (def && rclick) {
|
||||
processRightClick(*def, target);
|
||||
}
|
||||
if (Events::jactive(BIND_PLAYER_PICK)) {
|
||||
auto coord = selection.actualPosition;
|
||||
pick_block(indices, target, player, coord.x, coord.y, coord.z);
|
||||
}
|
||||
}
|
||||
|
||||
Player* PlayerController::getPlayer() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue