Fix widespread off by one error
This commit is contained in:
parent
087de58064
commit
ea99e75691
@ -7,7 +7,7 @@ function autoeat.eat()
|
|||||||
local player = minetest.localplayer
|
local player = minetest.localplayer
|
||||||
local owx=player:get_wield_index()
|
local owx=player:get_wield_index()
|
||||||
autoeat.eating = true
|
autoeat.eating = true
|
||||||
player:set_wield_index(8)
|
player:set_wield_index(9)
|
||||||
minetest.place_node(player:get_pos())
|
minetest.place_node(player:get_pos())
|
||||||
minetest.after("0.2",function()
|
minetest.after("0.2",function()
|
||||||
player:set_wield_index(owx)
|
player:set_wield_index(owx)
|
||||||
|
@ -61,7 +61,7 @@ local function amautotool(pos)
|
|||||||
for index, stack in pairs(inventory.main) do
|
for index, stack in pairs(inventory.main) do
|
||||||
is_better, best_time = check_tool(stack, node_groups, best_time)
|
is_better, best_time = check_tool(stack, node_groups, best_time)
|
||||||
if is_better then
|
if is_better then
|
||||||
new_index = index - 1
|
new_index = index
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
player:set_wield_index(new_index)
|
player:set_wield_index(new_index)
|
||||||
@ -97,7 +97,7 @@ local function dighead()
|
|||||||
local n=get_hnode()
|
local n=get_hnode()
|
||||||
if n==nil or n['name'] == 'air' then return end
|
if n==nil or n['name'] == 'air' then return end
|
||||||
--amautotool(ppos)
|
--amautotool(ppos)
|
||||||
minetest.localplayer:set_wield_index(0)
|
minetest.localplayer:set_wield_index(1)
|
||||||
minetest.dig_node(ppos)
|
minetest.dig_node(ppos)
|
||||||
minetest.dig_node(vector.add(ppos,{x=0,y=1,z=0}))
|
minetest.dig_node(vector.add(ppos,{x=0,y=1,z=0}))
|
||||||
digging=false
|
digging=false
|
||||||
|
@ -34,7 +34,7 @@ end
|
|||||||
local function parse_invaction(lists, taction)
|
local function parse_invaction(lists, taction)
|
||||||
local idx = format_inv(taction)
|
local idx = format_inv(taction)
|
||||||
local slot = taction.slot
|
local slot = taction.slot
|
||||||
local itemstack = lists[idx][slot + 1]
|
local itemstack = lists[idx][slot]
|
||||||
|
|
||||||
return idx, slot, itemstack
|
return idx, slot, itemstack
|
||||||
end
|
end
|
||||||
@ -44,9 +44,6 @@ local function simulate_invaction(lists, invaction)
|
|||||||
local fidx, fslot, fis = parse_invaction(lists, invaction:to_table().from)
|
local fidx, fslot, fis = parse_invaction(lists, invaction:to_table().from)
|
||||||
local tidx, tslot, tis = parse_invaction(lists, invaction:to_table().to)
|
local tidx, tslot, tis = parse_invaction(lists, invaction:to_table().to)
|
||||||
|
|
||||||
tslot = tslot + 1
|
|
||||||
fslot = fslot + 1
|
|
||||||
|
|
||||||
local tcount = invaction:to_table().count
|
local tcount = invaction:to_table().count
|
||||||
if tcount == 0 then
|
if tcount == 0 then
|
||||||
tcount = fis:get_count()
|
tcount = fis:get_count()
|
||||||
@ -128,17 +125,17 @@ local function invaction_dump_slot(q, src, dst, srci, dstbounds)
|
|||||||
local sinv = q.current[format_inv(src)]
|
local sinv = q.current[format_inv(src)]
|
||||||
local dinv = q.current[format_inv(dst)]
|
local dinv = q.current[format_inv(dst)]
|
||||||
|
|
||||||
if sinv[srci + 1]:is_empty() then
|
if sinv[srci]:is_empty() then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
for i = dstbounds.min, dstbounds.max do
|
for i = dstbounds.min, dstbounds.max do
|
||||||
if not empty and dinv[i + 1]:is_empty() then
|
if not empty and dinv[i]:is_empty() then
|
||||||
empty = i
|
empty = i
|
||||||
end
|
end
|
||||||
|
|
||||||
if not matching and dinv[i + 1]:get_name() == sinv[srci + 1]:get_name() then
|
if not matching and dinv[i]:get_name() == sinv[srci]:get_name() then
|
||||||
if dinv[i + 1]:get_free_space() ~= 0 then
|
if dinv[i]:get_free_space() ~= 0 then
|
||||||
matching = i
|
matching = i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -149,8 +146,8 @@ local function invaction_dump_slot(q, src, dst, srci, dstbounds)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if matching then
|
if matching then
|
||||||
local free = dinv[matching + 1]:get_free_space()
|
local free = dinv[matching]:get_free_space()
|
||||||
local scount = sinv[srci + 1]:get_count()
|
local scount = sinv[srci]:get_count()
|
||||||
local count = math.min(free, scount)
|
local count = math.min(free, scount)
|
||||||
|
|
||||||
local act = InventoryAction("move")
|
local act = InventoryAction("move")
|
||||||
@ -188,8 +185,8 @@ local function rebind(lists, inv, bounds)
|
|||||||
bounds.max = #invlist
|
bounds.max = #invlist
|
||||||
end
|
end
|
||||||
|
|
||||||
bounds.min = math.max(bounds.min, 0)
|
bounds.min = math.max(bounds.min, 1)
|
||||||
bounds.max = math.min(bounds.max, #invlist - 1)
|
bounds.max = math.min(bounds.max, #invlist)
|
||||||
|
|
||||||
return bounds
|
return bounds
|
||||||
end
|
end
|
||||||
|
@ -5,14 +5,6 @@ local category = "Scaffold"
|
|||||||
scaffold = {}
|
scaffold = {}
|
||||||
scaffold.registered_scaffolds = {}
|
scaffold.registered_scaffolds = {}
|
||||||
|
|
||||||
local function shuffle(tbl)
|
|
||||||
for i = #tbl, 2, -1 do
|
|
||||||
local j = math.random(i)
|
|
||||||
tbl[i], tbl[j] = tbl[j], tbl[i]
|
|
||||||
end
|
|
||||||
return tbl
|
|
||||||
end
|
|
||||||
|
|
||||||
function scaffold.register_scaffold(func)
|
function scaffold.register_scaffold(func)
|
||||||
table.insert(scaffold.registered_scaffolds, func)
|
table.insert(scaffold.registered_scaffolds, func)
|
||||||
end
|
end
|
||||||
@ -61,7 +53,7 @@ function scaffold.find_any_swap(items)
|
|||||||
for i, v in ipairs(items) do
|
for i, v in ipairs(items) do
|
||||||
local n = minetest.find_item(v)
|
local n = minetest.find_item(v)
|
||||||
if n then
|
if n then
|
||||||
minetest.localplayer:set_wield_index(n - 1)
|
minetest.localplayer:set_wield_index(n)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -157,5 +149,5 @@ scaffold.register_template_scaffold("RandomScaff", "scaffold_rnd", function(belo
|
|||||||
local n = minetest.get_node_or_nil(below)
|
local n = minetest.get_node_or_nil(below)
|
||||||
if n and scaffold.in_list(n.name,nlist.get('randomscaffold')) then return end
|
if n and scaffold.in_list(n.name,nlist.get('randomscaffold')) then return end
|
||||||
scaffold.dig(below)
|
scaffold.dig(below)
|
||||||
scaffold.place_if_needed(shuffle(nlist.get('randomscaffold')), below )
|
scaffold.place_if_needed(table.shuffle(nlist.get('randomscaffold')), below )
|
||||||
end)
|
end)
|
||||||
|
@ -87,7 +87,7 @@ function turtle.get_best_tool_index(x, y, z)
|
|||||||
|
|
||||||
local nodecaps = minetest.get_node_def(node.name).groups
|
local nodecaps = minetest.get_node_def(node.name).groups
|
||||||
|
|
||||||
local idx = minetest.localplayer:get_wield_index() + 1
|
local idx = minetest.localplayer:get_wield_index()
|
||||||
local best = math.huge
|
local best = math.huge
|
||||||
|
|
||||||
for i, v in ipairs(minetest.get_inventory("current_player").main) do
|
for i, v in ipairs(minetest.get_inventory("current_player").main) do
|
||||||
@ -100,7 +100,7 @@ function turtle.get_best_tool_index(x, y, z)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return idx - 1
|
return idx
|
||||||
end
|
end
|
||||||
|
|
||||||
-- switch to the fastest tool to mine x, y, z
|
-- switch to the fastest tool to mine x, y, z
|
||||||
|
Loading…
x
Reference in New Issue
Block a user