From ea99e7569126ca471b36a0044b8664b8baad2335 Mon Sep 17 00:00:00 2001 From: cron Date: Wed, 9 Dec 2020 23:13:34 +0000 Subject: [PATCH] Fix widespread off by one error --- clientmods/autoeat/init.lua | 2 +- clientmods/autominer/init.lua | 4 ++-- clientmods/quint/init.lua | 21 +++++++++------------ clientmods/scaffold/init.lua | 12 ++---------- clientmods/turtle/init.lua | 4 ++-- 5 files changed, 16 insertions(+), 27 deletions(-) diff --git a/clientmods/autoeat/init.lua b/clientmods/autoeat/init.lua index 6ea793c4a..a3a1a0dd3 100644 --- a/clientmods/autoeat/init.lua +++ b/clientmods/autoeat/init.lua @@ -7,7 +7,7 @@ function autoeat.eat() local player = minetest.localplayer local owx=player:get_wield_index() autoeat.eating = true - player:set_wield_index(8) + player:set_wield_index(9) minetest.place_node(player:get_pos()) minetest.after("0.2",function() player:set_wield_index(owx) diff --git a/clientmods/autominer/init.lua b/clientmods/autominer/init.lua index 50fa2b9ce..fc5add1a9 100644 --- a/clientmods/autominer/init.lua +++ b/clientmods/autominer/init.lua @@ -61,7 +61,7 @@ local function amautotool(pos) 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) @@ -97,7 +97,7 @@ local function dighead() local n=get_hnode() if n==nil or n['name'] == 'air' then return end --amautotool(ppos) - minetest.localplayer:set_wield_index(0) + minetest.localplayer:set_wield_index(1) minetest.dig_node(ppos) minetest.dig_node(vector.add(ppos,{x=0,y=1,z=0})) digging=false diff --git a/clientmods/quint/init.lua b/clientmods/quint/init.lua index 07734bd56..32db4629f 100644 --- a/clientmods/quint/init.lua +++ b/clientmods/quint/init.lua @@ -34,7 +34,7 @@ end local function parse_invaction(lists, taction) local idx = format_inv(taction) local slot = taction.slot - local itemstack = lists[idx][slot + 1] + local itemstack = lists[idx][slot] return idx, slot, itemstack end @@ -44,9 +44,6 @@ local function simulate_invaction(lists, invaction) local fidx, fslot, fis = parse_invaction(lists, invaction:to_table().from) local tidx, tslot, tis = parse_invaction(lists, invaction:to_table().to) - tslot = tslot + 1 - fslot = fslot + 1 - local tcount = invaction:to_table().count if tcount == 0 then 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 dinv = q.current[format_inv(dst)] - if sinv[srci + 1]:is_empty() then + if sinv[srci]:is_empty() then return true end 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 end - if not matching and dinv[i + 1]:get_name() == sinv[srci + 1]:get_name() then - if dinv[i + 1]:get_free_space() ~= 0 then + if not matching and dinv[i]:get_name() == sinv[srci]:get_name() then + if dinv[i]:get_free_space() ~= 0 then matching = i end end @@ -149,8 +146,8 @@ local function invaction_dump_slot(q, src, dst, srci, dstbounds) end if matching then - local free = dinv[matching + 1]:get_free_space() - local scount = sinv[srci + 1]:get_count() + local free = dinv[matching]:get_free_space() + local scount = sinv[srci]:get_count() local count = math.min(free, scount) local act = InventoryAction("move") @@ -188,8 +185,8 @@ local function rebind(lists, inv, bounds) bounds.max = #invlist end - bounds.min = math.max(bounds.min, 0) - bounds.max = math.min(bounds.max, #invlist - 1) + bounds.min = math.max(bounds.min, 1) + bounds.max = math.min(bounds.max, #invlist) return bounds end diff --git a/clientmods/scaffold/init.lua b/clientmods/scaffold/init.lua index 60ccc1411..3c66e0261 100644 --- a/clientmods/scaffold/init.lua +++ b/clientmods/scaffold/init.lua @@ -5,14 +5,6 @@ local category = "Scaffold" scaffold = {} 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) table.insert(scaffold.registered_scaffolds, func) end @@ -61,7 +53,7 @@ function scaffold.find_any_swap(items) for i, v in ipairs(items) do local n = minetest.find_item(v) if n then - minetest.localplayer:set_wield_index(n - 1) + minetest.localplayer:set_wield_index(n) return true end end @@ -157,5 +149,5 @@ scaffold.register_template_scaffold("RandomScaff", "scaffold_rnd", function(belo local n = minetest.get_node_or_nil(below) if n and scaffold.in_list(n.name,nlist.get('randomscaffold')) then return end scaffold.dig(below) - scaffold.place_if_needed(shuffle(nlist.get('randomscaffold')), below ) + scaffold.place_if_needed(table.shuffle(nlist.get('randomscaffold')), below ) end) diff --git a/clientmods/turtle/init.lua b/clientmods/turtle/init.lua index 4b2997371..92433951b 100644 --- a/clientmods/turtle/init.lua +++ b/clientmods/turtle/init.lua @@ -87,7 +87,7 @@ function turtle.get_best_tool_index(x, y, z) 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 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 - return idx - 1 + return idx end -- switch to the fastest tool to mine x, y, z