Added Strip, AutoRefill, indexing for InventoryActions and Wield Index starts at 1 now
This commit is contained in:
parent
f1ff05bf59
commit
ea88dde4be
@ -155,7 +155,7 @@ core.register_chatcommand("place", {
|
||||
func = function(param)
|
||||
local success, pos = core.parse_relative_pos(param)
|
||||
if success then
|
||||
cores.place_node(pos)
|
||||
core.place_node(pos)
|
||||
return true, "Node placed at " .. core.pos_to_string(pos)
|
||||
end
|
||||
return false, pos
|
||||
|
@ -2,7 +2,7 @@ local placed_crystal
|
||||
local switched_to_totem = 0
|
||||
local used_sneak = true
|
||||
local totem_move_action = InventoryAction("move")
|
||||
totem_move_action:to("current_player", "main", 8)
|
||||
totem_move_action:to("current_player", "main", 9)
|
||||
|
||||
core.register_globalstep(function(dtime)
|
||||
local player = core.localplayer
|
||||
@ -48,9 +48,9 @@ core.register_globalstep(function(dtime)
|
||||
if totem_stack and totem_stack:get_name() ~= "mobs_mc:totem" then
|
||||
local totem_index = core.find_item("mobs_mc:totem")
|
||||
if totem_index then
|
||||
totem_move_action:from("current_player", "main", totem_index - 1)
|
||||
totem_move_action:from("current_player", "main", totem_index)
|
||||
totem_move_action:apply()
|
||||
player:set_wield_index(8)
|
||||
player:set_wield_index(9)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -62,6 +62,8 @@ core.cheats = {
|
||||
["Enderchest"] = function() core.open_enderchest() end,
|
||||
["HandSlot"] = function() core.open_handslot() end,
|
||||
["NextItem"] = "next_item",
|
||||
["Strip"] = "strip",
|
||||
["AutoRefill"] = "autorefill",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,15 +2,48 @@ local elapsed_time = 0
|
||||
local tick_time = 0.05
|
||||
local drop_action = InventoryAction("drop")
|
||||
|
||||
local strip_move_act = InventoryAction("move")
|
||||
strip_move_act:to("current_player", "craft", 1)
|
||||
local strip_craft_act = InventoryAction("craft")
|
||||
strip_craft_act:craft("current_player")
|
||||
local strip_move_back_act = InventoryAction("move")
|
||||
strip_move_back_act:from("current_player", "craftresult", 1)
|
||||
|
||||
core.register_globalstep(function(dtime)
|
||||
local player = core.localplayer
|
||||
if not player then return end
|
||||
local item = player:get_wielded_item()
|
||||
local itemdef = core.get_item_def(item:get_name())
|
||||
local wieldindex = player:get_wield_index()
|
||||
-- AutoRefill
|
||||
if core.settings:get_bool("autorefill") and itemdef then
|
||||
local space = item:get_free_space()
|
||||
local i = core.find_item(item:get_name(), wieldindex + 1)
|
||||
if i and space > 0 then
|
||||
local move_act = InventoryAction("move")
|
||||
move_act:to("current_player", "main", wieldindex)
|
||||
move_act:from("current_player", "main", i)
|
||||
move_act:set_count(space)
|
||||
move_act:apply()
|
||||
end
|
||||
end
|
||||
-- Strip
|
||||
if core.settings:get_bool("strip") then
|
||||
if itemdef and itemdef.groups.tree and player:get_control().RMB then
|
||||
strip_move_act:from("current_player", "main", wieldindex)
|
||||
strip_move_back_act:to("current_player", "main", wieldindex)
|
||||
strip_move_act:apply()
|
||||
strip_craft_act:apply()
|
||||
strip_move_back_act:apply()
|
||||
end
|
||||
end
|
||||
-- AutoEject
|
||||
if core.settings:get_bool("autoeject") then
|
||||
local player = core.localplayer
|
||||
local list = (core.settings:get("eject_items") or ""):split(",")
|
||||
local inventory = core.get_inventory("current_player")
|
||||
for index, stack in pairs(inventory.main) do
|
||||
if table.indexof(list, stack:get_name()) ~= -1 then
|
||||
drop_action:from("current_player", "main", index - 1)
|
||||
drop_action:from("current_player", "main", index)
|
||||
drop_action:apply()
|
||||
end
|
||||
end
|
||||
@ -19,12 +52,8 @@ core.register_globalstep(function(dtime)
|
||||
if core.settings:get_bool("next_item") then
|
||||
elapsed_time = elapsed_time + dtime
|
||||
if elapsed_time < tick_time then return end
|
||||
local player = minetest.localplayer
|
||||
if not player then return end
|
||||
local item = player:get_wielded_item()
|
||||
if item:get_count() == 0 then
|
||||
local index = player:get_wield_index()
|
||||
player:set_wield_index(index + 1)
|
||||
player:set_wield_index(wieldindex + 1)
|
||||
end
|
||||
elapsed_time = 0
|
||||
end
|
||||
@ -62,7 +91,7 @@ core.register_on_punchnode(function(pos, node)
|
||||
for index, stack in pairs(inventory.main) do
|
||||
is_better, best_time = check_tool(stack, node_groups, best_time)
|
||||
if is_better then
|
||||
new_index = index - 1
|
||||
new_index = index
|
||||
end
|
||||
end
|
||||
player:set_wield_index(new_index)
|
||||
@ -113,3 +142,6 @@ local hand_formspec = "size[9,8.75]"..
|
||||
function core.open_handslot()
|
||||
minetest.show_formspec("__builtin__:hand", hand_formspec)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
@ -21,9 +21,9 @@ function core.parse_relative_pos(param)
|
||||
return success, pos
|
||||
end
|
||||
|
||||
function core.find_item(item)
|
||||
function core.find_item(item, mini, maxi)
|
||||
for index, stack in ipairs(core.get_inventory("current_player").main) do
|
||||
if stack:get_name() == item then
|
||||
if (not mini or index >= mini) and (not maxi or index <= maxi) and stack:get_name() == item then
|
||||
return index
|
||||
end
|
||||
end
|
||||
@ -32,7 +32,7 @@ end
|
||||
function core.switch_to_item(item)
|
||||
local i = core.find_item(item)
|
||||
if i then
|
||||
core.localplayer:set_wield_index(i - 1)
|
||||
core.localplayer:set_wield_index(i)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
|
@ -2298,3 +2298,11 @@ autotnt (PlaceOnTop) bool false
|
||||
replace (Replace) bool false
|
||||
|
||||
crystal_pvp (CrystalPvP) bool false
|
||||
|
||||
autototem (AutoTotem) bool false
|
||||
|
||||
dont_point_nodes (ThroughWalls) bool false
|
||||
|
||||
strip (Strip) bool false
|
||||
|
||||
autorefill (AutoRefill) bool false
|
||||
|
@ -1184,9 +1184,9 @@ Methods:
|
||||
* `get_name()`
|
||||
* returns player name
|
||||
* `get_wield_index()`
|
||||
* returns the index of the wielded item
|
||||
* returns the index of the wielded item (starts at 1)
|
||||
* `set_wield_index()`
|
||||
* sets the index
|
||||
* sets the index (starts at 1)
|
||||
* `get_wielded_item()`
|
||||
* returns the itemstack the player is holding
|
||||
* `is_attached()`
|
||||
@ -1717,6 +1717,7 @@ A reference to a C++ InventoryAction. You can move, drop and craft items in all
|
||||
* `InventoryAction(type)`:
|
||||
* creates a new InventoryAction
|
||||
* type is on of "move", "drop", or "craft", else returns nil
|
||||
* indexing starts at 1
|
||||
* `apply()`:
|
||||
* applies the InventoryAction (InventoryActions can be applied multible times)
|
||||
* `from(inventorylocation, listname, stack)`
|
||||
@ -1736,13 +1737,13 @@ A reference to a C++ InventoryAction. You can move, drop and craft items in all
|
||||
|
||||
#### example
|
||||
`local move_act = InventoryAction("move")
|
||||
move_act:from("current_player", "main", 0)
|
||||
move_act:to("current_player", "craft", 0)
|
||||
move_act:from("current_player", "main", 1)
|
||||
move_act:to("current_player", "craft", 1)
|
||||
move_act:set_count(1)
|
||||
local craft_act = InventoryAction("craft")
|
||||
craft_act:craft("current_player")
|
||||
local drop_act = InventoryAction("drop")
|
||||
drop_act:from("current_player", "craft", 0)
|
||||
drop_act:from("current_player", "craft_result",10)
|
||||
move_act:apply()
|
||||
craft_act:apply()
|
||||
drop_act:apply()
|
||||
|
@ -111,6 +111,8 @@ void set_default_settings(Settings *settings)
|
||||
settings->setDefault("crystal_pvp", "false");
|
||||
settings->setDefault("autototem", "false");
|
||||
settings->setDefault("dont_point_nodes", "false");
|
||||
settings->setDefault("strip", "false");
|
||||
settings->setDefault("autorefill", "false");
|
||||
|
||||
// Keymap
|
||||
settings->setDefault("remote_port", "30000");
|
||||
|
@ -133,7 +133,7 @@ void LuaInventoryAction::readFullInventoryLocationInto(lua_State *L, InventoryLo
|
||||
loc->deSerialize(readParam<std::string>(L, 2));
|
||||
std::string l = readParam<std::string>(L, 3);
|
||||
*list = l;
|
||||
*index = luaL_checkinteger(L, 4);
|
||||
*index = luaL_checkinteger(L, 4) - 1;
|
||||
} catch (SerializationError &) {}
|
||||
}
|
||||
|
||||
|
@ -116,7 +116,7 @@ int LuaLocalPlayer::l_get_wield_index(lua_State *L)
|
||||
{
|
||||
LocalPlayer *player = getobject(L, 1);
|
||||
|
||||
lua_pushinteger(L, player->getWieldIndex());
|
||||
lua_pushinteger(L, player->getWieldIndex() + 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ int LuaLocalPlayer::l_get_wield_index(lua_State *L)
|
||||
int LuaLocalPlayer::l_set_wield_index(lua_State *L)
|
||||
{
|
||||
LocalPlayer *player = getobject(L, 1);
|
||||
u32 index = luaL_checkinteger(L, 2);
|
||||
u32 index = luaL_checkinteger(L, 2) - 1;
|
||||
|
||||
player->setWieldIndex(index);
|
||||
g_game->processItemSelection(&g_game->runData.new_playeritem);
|
||||
|
Loading…
x
Reference in New Issue
Block a user