add function inventory.move_range
This commit is contained in:
parent
f6ab0de5af
commit
0ba0584c5d
@ -55,8 +55,21 @@ inventory.create(size: int) -> int
|
|||||||
-- Create inventory copy. Returns the created copy ID.
|
-- Create inventory copy. Returns the created copy ID.
|
||||||
inventory.clone(invid: int) -> int
|
inventory.clone(invid: int) -> int
|
||||||
|
|
||||||
-- Move item from slotA of invA to slotB of invB.
|
-- Move an item from slotA of invA to slotB of invB.
|
||||||
-- invA may be the same as invB.
|
-- invA may be the same as invB.
|
||||||
-- If slotB will be chosen automaticly if argument is not specified.
|
-- If slotB will be chosen automaticly if argument is not specified.
|
||||||
|
-- The move may be incomplete if the available slot has no enough stack space.
|
||||||
inventory.move(invA: int, slotA: int, invB: int, slotB: int)
|
inventory.move(invA: int, slotA: int, invB: int, slotB: int)
|
||||||
|
|
||||||
|
-- Moves an item from slotA of inventory invA to a suitable slot(s)
|
||||||
|
-- in the specified range of inventory invB.
|
||||||
|
-- invA may be the same as invB.
|
||||||
|
-- The move may be incomplete if the available slots are filled.
|
||||||
|
inventory.move(
|
||||||
|
invA: int,
|
||||||
|
slotA: int,
|
||||||
|
invB: int,
|
||||||
|
rangeBegin: int,
|
||||||
|
[optional] rangeEnd: int
|
||||||
|
)
|
||||||
```
|
```
|
||||||
|
|||||||
@ -66,5 +66,20 @@ inventory.clone(invid: int) -> int
|
|||||||
-- Перемещает предмет из slotA инвентаря invA в slotB инвентаря invB.
|
-- Перемещает предмет из slotA инвентаря invA в slotB инвентаря invB.
|
||||||
-- invA и invB могут указывать на один инвентарь.
|
-- invA и invB могут указывать на один инвентарь.
|
||||||
-- slotB будет выбран автоматически, если не указывать явно.
|
-- slotB будет выбран автоматически, если не указывать явно.
|
||||||
|
-- Перемещение может быть неполным, если стек слота заполнится.
|
||||||
inventory.move(invA: int, slotA: int, invB: int, slotB: int)
|
inventory.move(invA: int, slotA: int, invB: int, slotB: int)
|
||||||
|
|
||||||
|
-- Перемещает предмет из slotA инвентаря invA в подходящий слот, находящийся в
|
||||||
|
-- указанном отрезке инвентаря invB.
|
||||||
|
-- invA и invB могут указывать на один инвентарь.
|
||||||
|
-- rangeBegin - начало отрезка.
|
||||||
|
-- rangeEnd - конец отрезка.
|
||||||
|
-- Перемещение может быть неполным, если доступные слоты будут заполнены.
|
||||||
|
inventory.move_range(
|
||||||
|
invA: int,
|
||||||
|
slotA: int,
|
||||||
|
invB: int,
|
||||||
|
rangeBegin: int,
|
||||||
|
[опционально] rangeEnd: int
|
||||||
|
)
|
||||||
```
|
```
|
||||||
|
|||||||
@ -4,7 +4,9 @@ function inventory_share_func(invid, slotid)
|
|||||||
inventory.move(invid, slotid, blockinv)
|
inventory.move(invid, slotid, blockinv)
|
||||||
elseif rules.get("allow-content-access") then
|
elseif rules.get("allow-content-access") then
|
||||||
inventory.set(invid, slotid, 0, 0)
|
inventory.set(invid, slotid, 0, 0)
|
||||||
|
elseif slotid < 10 then
|
||||||
|
inventory.move_range(invid, slotid, invid, 10)
|
||||||
else
|
else
|
||||||
inventory.move(invid, slotid, invid)
|
inventory.move_range(invid, slotid, invid, 0, 9)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -156,12 +156,32 @@ static int l_inventory_move(lua::State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_inventory_move_range(lua::State* L) {
|
||||||
|
auto invAid = lua::tointeger(L, 1);
|
||||||
|
auto slotAid = lua::tointeger(L, 2);
|
||||||
|
auto invA = get_inventory(invAid, 1);
|
||||||
|
validate_slotid(slotAid, invA.get());
|
||||||
|
|
||||||
|
auto invBid = lua::tointeger(L, 3);
|
||||||
|
auto slotBegin = lua::isnoneornil(L, 4) ? -1 : lua::tointeger(L, 4);
|
||||||
|
auto slotEnd = lua::isnoneornil(L, 5) ? -1 : lua::tointeger(L, 5);
|
||||||
|
auto invB = get_inventory(invBid, 3);
|
||||||
|
auto& slot = invA->getSlot(slotAid);
|
||||||
|
if (slotBegin == -1) {
|
||||||
|
invB->move(slot, content->getIndices());
|
||||||
|
} else {
|
||||||
|
invB->move(slot, content->getIndices(), slotBegin, slotEnd);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const luaL_Reg inventorylib[] = {
|
const luaL_Reg inventorylib[] = {
|
||||||
{"get", lua::wrap<l_inventory_get>},
|
{"get", lua::wrap<l_inventory_get>},
|
||||||
{"set", lua::wrap<l_inventory_set>},
|
{"set", lua::wrap<l_inventory_set>},
|
||||||
{"size", lua::wrap<l_inventory_size>},
|
{"size", lua::wrap<l_inventory_size>},
|
||||||
{"add", lua::wrap<l_inventory_add>},
|
{"add", lua::wrap<l_inventory_add>},
|
||||||
{"move", lua::wrap<l_inventory_move>},
|
{"move", lua::wrap<l_inventory_move>},
|
||||||
|
{"move_range", lua::wrap<l_inventory_move_range>},
|
||||||
{"get_block", lua::wrap<l_inventory_get_block>},
|
{"get_block", lua::wrap<l_inventory_get_block>},
|
||||||
{"bind_block", lua::wrap<l_inventory_bind_block>},
|
{"bind_block", lua::wrap<l_inventory_bind_block>},
|
||||||
{"unbind_block", lua::wrap<l_inventory_unbind_block>},
|
{"unbind_block", lua::wrap<l_inventory_unbind_block>},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user