more fixes

This commit is contained in:
BuckarooBanzay 2023-06-05 12:31:28 +02:00
parent 828cb5bc9b
commit d4c2cfbd60
2 changed files with 39 additions and 36 deletions

@ -43,7 +43,7 @@ digtron.mark_diggable = function(pos, nodes_dug, player)
-- returns fuel cost and what will be dropped by digging these nodes.
local target = minetest.get_node(pos)
-- prevent digtrons from being marked for digging.
if minetest.get_item_group(target.name, "digtron") ~= 0 or
minetest.get_item_group(target.name, "digtron_protected") ~= 0 or
@ -57,7 +57,7 @@ digtron.mark_diggable = function(pos, nodes_dug, player)
if target.name ~= "air" then
local in_known_group = false
local material_cost = 0
if digtron.config.uses_resources then
if minetest.get_item_group(target.name, "cracky") ~= 0 then
in_known_group = true
@ -75,13 +75,13 @@ digtron.mark_diggable = function(pos, nodes_dug, player)
material_cost = digtron.config.dig_cost_default
end
end
return material_cost, minetest.get_node_drops(target.name, "")
end
end
return 0
end
digtron.can_build_to = function(pos, protected_nodes, dug_nodes)
-- Returns whether a space is clear to have something put into it
@ -115,7 +115,7 @@ digtron.place_in_inventory = function(itemname, inventory_positions, fallback_po
--tries placing the item in each inventory node in turn. If there's no room, drop it at fallback_pos
local itemstack = ItemStack(itemname)
if inventory_positions ~= nil then
for k, location in pairs(inventory_positions) do
for _, location in pairs(inventory_positions) do
node_inventory_table.pos = location.pos
local inv = minetest.get_inventory(node_inventory_table)
itemstack = inv:add_item("main", itemstack)
@ -147,7 +147,7 @@ digtron.take_from_inventory = function(itemname, inventory_positions)
if inventory_positions == nil then return nil end
--tries to take an item from each inventory node in turn. Returns location of inventory item was taken from on success, nil on failure
local itemstack = ItemStack(itemname)
for k, location in pairs(inventory_positions) do
for _, location in pairs(inventory_positions) do
node_inventory_table.pos = location.pos
local inv = minetest.get_inventory(node_inventory_table)
local output = inv:remove_item("main", itemstack)
@ -158,8 +158,8 @@ digtron.take_from_inventory = function(itemname, inventory_positions)
return nil
end
-- Used to determine which coordinate is being checked for periodicity. eg, if the digtron is moving in the z direction, then periodicity is checked for every n nodes in the z axis.
digtron.get_controlling_coordinate = function(pos, facedir)
-- Used to determine which coordinate is being checked for periodicity. eg, if the digtron is moving in the z direction, then periodicity is checked for every n nodes in the z axis
digtron.get_controlling_coordinate = function(_, facedir)
-- used for determining builder period and offset
local dir = digtron.facedir_to_dir_map[facedir]
if dir == 1 or dir == 3 then
@ -172,7 +172,7 @@ digtron.get_controlling_coordinate = function(pos, facedir)
end
local fuel_craft = {method="fuel", width=1, items={}} -- reusable crafting recipe table for get_craft_result calls below
-- Searches fuel store inventories for burnable items and burns them until target is reached or surpassed
-- Searches fuel store inventories for burnable items and burns them until target is reached or surpassed
-- (or there's nothing left to burn). Returns the total fuel value burned
-- if the "test" parameter is set to true, doesn't actually take anything out of inventories.
-- We can get away with this sort of thing for fuel but not for builder inventory because there's just one
@ -183,7 +183,7 @@ digtron.burn = function(fuelstore_positions, target, test)
end
local current_burned = 0
for k, location in pairs(fuelstore_positions) do
for _, location in pairs(fuelstore_positions) do
if current_burned > target then
break
end
@ -194,8 +194,8 @@ digtron.burn = function(fuelstore_positions, target, test)
if invlist == nil then -- This check shouldn't be needed, it's yet another guard against https://github.com/minetest/minetest/issues/8067
break
end
for i, itemstack in pairs(invlist) do
for _, itemstack in pairs(invlist) do
fuel_craft.items[1] = itemstack:peek_item(1)
local fuel_per_item = minetest.get_craft_result(fuel_craft).time
if fuel_per_item ~= 0 then
@ -222,8 +222,8 @@ digtron.burn = function(fuelstore_positions, target, test)
end
-- Consume energy from the batteries
-- The same as burning coal, except that instead of destroying the items in the inventory, we merely drain
-- the charge in them, leaving them empty. The charge is converted into "coal heat units" by a downscaling
-- The same as burning coal, except that instead of destroying the items in the inventory, we merely drain
-- the charge in them, leaving them empty. The charge is converted into "coal heat units" by a downscaling
-- factor, since if taken at face value (10000 EU), the batteries would be the ultimate power source barely
-- ever needing replacement.
digtron.tap_batteries = function(battery_positions, target, test)
@ -237,20 +237,20 @@ digtron.tap_batteries = function(battery_positions, target, test)
-- An RE battery holds 10000 EU of charge
-- local power_ratio = 100 -- How much charge equals 1 unit of PU from coal
-- setting Moved to digtron.config.power_ratio
for k, location in pairs(battery_positions) do
for _, location in pairs(battery_positions) do
if current_burned > target then
break
end
node_inventory_table.pos = location.pos
local inv = minetest.get_inventory(node_inventory_table)
local invlist = inv:get_list("batteries")
if (invlist == nil) then -- This check shouldn't be needed, it's yet another guard against https://github.com/minetest/minetest/issues/8067
break
end
for i, itemstack in pairs(invlist) do
for _, itemstack in pairs(invlist) do
local meta = minetest.deserialize(itemstack:get_metadata())
if (meta ~= nil) then
local power_available = math.floor(meta.charge / digtron.config.power_ratio)
@ -265,14 +265,13 @@ digtron.tap_batteries = function(battery_positions, target, test)
end
current_burned = current_burned + actual_burned
end
end
if current_burned > target then
break
end
end
if test ~= true then
-- only update the list if we're doing this for real.
inv:set_list("batteries", invlist)
@ -363,7 +362,7 @@ digtron.damage_creatures = function(player, source_pos, target_pos, amount, item
obj:remove()
end
end
end
end
end
end
@ -382,8 +381,8 @@ end
-- If someone sets very large offsets or intervals for the offset markers they might be added too far
-- away. safe_add_entity causes these attempts to be ignored rather than crashing the game.
-- returns the entity if successful, nil otherwise
function safe_add_entity(pos, name)
success, ret = pcall(minetest.add_entity, pos, name)
local function safe_add_entity(pos, name)
local success, ret = pcall(minetest.add_entity, pos, name)
if success then return ret else return nil end
end
@ -411,13 +410,13 @@ digtron.show_offset_markers = function(pos, offset, period)
local entity = safe_add_entity({x=buildpos.x, y=buildpos.y, z=z_pos}, "digtron:marker")
if entity ~= nil then entity:setyaw(1.5708) end
if z_pos >= buildpos.z then
local entity = safe_add_entity({x=buildpos.x, y=buildpos.y, z=z_pos - period}, "digtron:marker")
entity = safe_add_entity({x=buildpos.x, y=buildpos.y, z=z_pos - period}, "digtron:marker")
if entity ~= nil then entity:setyaw(1.5708) end
end
if z_pos <= buildpos.z then
local entity = safe_add_entity({x=buildpos.x, y=buildpos.y, z=z_pos + period}, "digtron:marker")
entity = safe_add_entity({x=buildpos.x, y=buildpos.y, z=z_pos + period}, "digtron:marker")
if entity ~= nil then entity:setyaw(1.5708) end
end
end

@ -198,7 +198,7 @@ digtron.execute_dig_cycle = function(pos, clicker)
local can_build = true
local test_items = {}
local test_build_fuel_cost = 0
local test_build_return_code, test_build_return_items
local test_build_return_code, test_build_return_items, failed_to_find
if layout.builders ~= nil then
for _, location in pairs(layout.builders) do
@ -206,7 +206,7 @@ digtron.execute_dig_cycle = function(pos, clicker)
local targetdef = minetest.registered_nodes[target.name]
local test_location = vector.add(location.pos, dir)
if targetdef.test_build ~= nil then
test_build_return_code, test_build_return_items = targetdef.test_build(
test_build_return_code, test_build_return_items, failed_to_find = targetdef.test_build(
location.pos, test_location, layout.inventories, layout.protected, layout.nodes_dug, controlling_coordinate, layout.controller
)
for _, return_item in pairs(test_build_return_items) do
@ -336,7 +336,7 @@ digtron.execute_dig_cycle = function(pos, clicker)
local strange_failure = false
-- execute_build on all digtron components that have one
if layout.builders ~= nil then
for k, location in pairs(layout.builders) do
for _, location in pairs(layout.builders) do
local target = minetest.get_node(location.pos)
local targetdef = minetest.registered_nodes[target.name]
if targetdef.execute_build ~= nil then
@ -357,7 +357,7 @@ digtron.execute_dig_cycle = function(pos, clicker)
end
if layout.auto_ejectors ~= nil then
for k, location in pairs(layout.auto_ejectors) do
for _, location in pairs(layout.auto_ejectors) do
local target = minetest.get_node(location.pos)
local targetdef = minetest.registered_nodes[target.name]
if targetdef.execute_eject ~= nil then
@ -406,7 +406,9 @@ digtron.execute_dig_cycle = function(pos, clicker)
local node_to_dig, whether_to_dig = layout.nodes_dug:pop()
while node_to_dig ~= nil do
if whether_to_dig == true then
minetest.log("action", string.format("%s uses Digtron to dig %s at (%d, %d, %d)", clicker:get_player_name(), minetest.get_node(node_to_dig).name, node_to_dig.x, node_to_dig.y, node_to_dig.z))
minetest.log("action", string.format(
"%s uses Digtron to dig %s at (%d, %d, %d)", clicker:get_player_name(), minetest.get_node(node_to_dig).name, node_to_dig.x, node_to_dig.y, node_to_dig.z)
)
minetest.remove_node(node_to_dig)
end
-- all of the digtron's nodes wind up in nodes_dug, so this is an ideal place to stick
@ -507,7 +509,7 @@ digtron.execute_downward_dig_cycle = function(pos, clicker)
-- but doesn't actually dig the nodes yet. That comes later.
-- If we dug them now, sand would fall and some digtron nodes would die.
if layout.diggers ~= nil then
for k, location in pairs(layout.diggers) do
for _, location in pairs(layout.diggers) do
local target = minetest.get_node(location.pos)
local targetdef = minetest.registered_nodes[target.name]
if targetdef.execute_dig ~= nil then
@ -562,7 +564,7 @@ digtron.execute_downward_dig_cycle = function(pos, clicker)
-- damage the weak flesh
if digtron.config.damage_hp > 0 and layout.diggers ~= nil then
for k, location in pairs(layout.diggers) do
for _, location in pairs(layout.diggers) do
local target = minetest.get_node(location.pos)
local targetdef = minetest.registered_nodes[target.name]
if targetdef.damage_creatures ~= nil then
@ -619,7 +621,9 @@ digtron.execute_downward_dig_cycle = function(pos, clicker)
local node_to_dig, whether_to_dig = layout.nodes_dug:pop()
while node_to_dig ~= nil do
if whether_to_dig == true then
minetest.log("action", string.format("%s uses Digtron to dig %s at (%d, %d, %d)", clicker:get_player_name(), minetest.get_node(node_to_dig).name, node_to_dig.x, node_to_dig.y, node_to_dig.z))
minetest.log("action", string.format(
"%s uses Digtron to dig %s at (%d, %d, %d)", clicker:get_player_name(), minetest.get_node(node_to_dig).name, node_to_dig.x, node_to_dig.y, node_to_dig.z)
)
minetest.remove_node(node_to_dig)
end
node_to_dig, whether_to_dig = layout.nodes_dug:pop()