mirror of
https://github.com/minetest-mods/digtron.git
synced 2024-07-07 08:15:22 +02:00
more fixes
This commit is contained in:
parent
828cb5bc9b
commit
d4c2cfbd60
55
util.lua
55
util.lua
@ -43,7 +43,7 @@ digtron.mark_diggable = function(pos, nodes_dug, player)
|
|||||||
-- returns fuel cost and what will be dropped by digging these nodes.
|
-- returns fuel cost and what will be dropped by digging these nodes.
|
||||||
|
|
||||||
local target = minetest.get_node(pos)
|
local target = minetest.get_node(pos)
|
||||||
|
|
||||||
-- prevent digtrons from being marked for digging.
|
-- prevent digtrons from being marked for digging.
|
||||||
if minetest.get_item_group(target.name, "digtron") ~= 0 or
|
if minetest.get_item_group(target.name, "digtron") ~= 0 or
|
||||||
minetest.get_item_group(target.name, "digtron_protected") ~= 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
|
if target.name ~= "air" then
|
||||||
local in_known_group = false
|
local in_known_group = false
|
||||||
local material_cost = 0
|
local material_cost = 0
|
||||||
|
|
||||||
if digtron.config.uses_resources then
|
if digtron.config.uses_resources then
|
||||||
if minetest.get_item_group(target.name, "cracky") ~= 0 then
|
if minetest.get_item_group(target.name, "cracky") ~= 0 then
|
||||||
in_known_group = true
|
in_known_group = true
|
||||||
@ -75,13 +75,13 @@ digtron.mark_diggable = function(pos, nodes_dug, player)
|
|||||||
material_cost = digtron.config.dig_cost_default
|
material_cost = digtron.config.dig_cost_default
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return material_cost, minetest.get_node_drops(target.name, "")
|
return material_cost, minetest.get_node_drops(target.name, "")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
digtron.can_build_to = function(pos, protected_nodes, dug_nodes)
|
digtron.can_build_to = function(pos, protected_nodes, dug_nodes)
|
||||||
-- Returns whether a space is clear to have something put into it
|
-- 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
|
--tries placing the item in each inventory node in turn. If there's no room, drop it at fallback_pos
|
||||||
local itemstack = ItemStack(itemname)
|
local itemstack = ItemStack(itemname)
|
||||||
if inventory_positions ~= nil then
|
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
|
node_inventory_table.pos = location.pos
|
||||||
local inv = minetest.get_inventory(node_inventory_table)
|
local inv = minetest.get_inventory(node_inventory_table)
|
||||||
itemstack = inv:add_item("main", itemstack)
|
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
|
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
|
--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)
|
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
|
node_inventory_table.pos = location.pos
|
||||||
local inv = minetest.get_inventory(node_inventory_table)
|
local inv = minetest.get_inventory(node_inventory_table)
|
||||||
local output = inv:remove_item("main", itemstack)
|
local output = inv:remove_item("main", itemstack)
|
||||||
@ -158,8 +158,8 @@ digtron.take_from_inventory = function(itemname, inventory_positions)
|
|||||||
return nil
|
return nil
|
||||||
end
|
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.
|
-- 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)
|
digtron.get_controlling_coordinate = function(_, facedir)
|
||||||
-- used for determining builder period and offset
|
-- used for determining builder period and offset
|
||||||
local dir = digtron.facedir_to_dir_map[facedir]
|
local dir = digtron.facedir_to_dir_map[facedir]
|
||||||
if dir == 1 or dir == 3 then
|
if dir == 1 or dir == 3 then
|
||||||
@ -172,7 +172,7 @@ digtron.get_controlling_coordinate = function(pos, facedir)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local fuel_craft = {method="fuel", width=1, items={}} -- reusable crafting recipe table for get_craft_result calls below
|
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
|
-- (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.
|
-- 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
|
-- 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
|
end
|
||||||
|
|
||||||
local current_burned = 0
|
local current_burned = 0
|
||||||
for k, location in pairs(fuelstore_positions) do
|
for _, location in pairs(fuelstore_positions) do
|
||||||
if current_burned > target then
|
if current_burned > target then
|
||||||
break
|
break
|
||||||
end
|
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
|
if invlist == nil then -- This check shouldn't be needed, it's yet another guard against https://github.com/minetest/minetest/issues/8067
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
for i, itemstack in pairs(invlist) do
|
for _, itemstack in pairs(invlist) do
|
||||||
fuel_craft.items[1] = itemstack:peek_item(1)
|
fuel_craft.items[1] = itemstack:peek_item(1)
|
||||||
local fuel_per_item = minetest.get_craft_result(fuel_craft).time
|
local fuel_per_item = minetest.get_craft_result(fuel_craft).time
|
||||||
if fuel_per_item ~= 0 then
|
if fuel_per_item ~= 0 then
|
||||||
@ -222,8 +222,8 @@ digtron.burn = function(fuelstore_positions, target, test)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Consume energy from the batteries
|
-- Consume energy from the batteries
|
||||||
-- The same as burning coal, except that instead of destroying the items in the inventory, we merely drain
|
-- 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 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
|
-- factor, since if taken at face value (10000 EU), the batteries would be the ultimate power source barely
|
||||||
-- ever needing replacement.
|
-- ever needing replacement.
|
||||||
digtron.tap_batteries = function(battery_positions, target, test)
|
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
|
-- An RE battery holds 10000 EU of charge
|
||||||
-- local power_ratio = 100 -- How much charge equals 1 unit of PU from coal
|
-- local power_ratio = 100 -- How much charge equals 1 unit of PU from coal
|
||||||
-- setting Moved to digtron.config.power_ratio
|
-- 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
|
if current_burned > target then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
node_inventory_table.pos = location.pos
|
node_inventory_table.pos = location.pos
|
||||||
local inv = minetest.get_inventory(node_inventory_table)
|
local inv = minetest.get_inventory(node_inventory_table)
|
||||||
local invlist = inv:get_list("batteries")
|
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
|
if (invlist == nil) then -- This check shouldn't be needed, it's yet another guard against https://github.com/minetest/minetest/issues/8067
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
for i, itemstack in pairs(invlist) do
|
for _, itemstack in pairs(invlist) do
|
||||||
local meta = minetest.deserialize(itemstack:get_metadata())
|
local meta = minetest.deserialize(itemstack:get_metadata())
|
||||||
if (meta ~= nil) then
|
if (meta ~= nil) then
|
||||||
local power_available = math.floor(meta.charge / digtron.config.power_ratio)
|
local power_available = math.floor(meta.charge / digtron.config.power_ratio)
|
||||||
@ -265,14 +265,13 @@ digtron.tap_batteries = function(battery_positions, target, test)
|
|||||||
end
|
end
|
||||||
current_burned = current_burned + actual_burned
|
current_burned = current_burned + actual_burned
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if current_burned > target then
|
if current_burned > target then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if test ~= true then
|
if test ~= true then
|
||||||
-- only update the list if we're doing this for real.
|
-- only update the list if we're doing this for real.
|
||||||
inv:set_list("batteries", invlist)
|
inv:set_list("batteries", invlist)
|
||||||
@ -363,7 +362,7 @@ digtron.damage_creatures = function(player, source_pos, target_pos, amount, item
|
|||||||
obj:remove()
|
obj:remove()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
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
|
-- 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.
|
-- away. safe_add_entity causes these attempts to be ignored rather than crashing the game.
|
||||||
-- returns the entity if successful, nil otherwise
|
-- returns the entity if successful, nil otherwise
|
||||||
function safe_add_entity(pos, name)
|
local function safe_add_entity(pos, name)
|
||||||
success, ret = pcall(minetest.add_entity, pos, name)
|
local success, ret = pcall(minetest.add_entity, pos, name)
|
||||||
if success then return ret else return nil end
|
if success then return ret else return nil end
|
||||||
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")
|
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 entity ~= nil then entity:setyaw(1.5708) end
|
||||||
|
|
||||||
if z_pos >= buildpos.z then
|
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
|
if entity ~= nil then entity:setyaw(1.5708) end
|
||||||
end
|
end
|
||||||
if z_pos <= buildpos.z then
|
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
|
if entity ~= nil then entity:setyaw(1.5708) end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -198,7 +198,7 @@ digtron.execute_dig_cycle = function(pos, clicker)
|
|||||||
local can_build = true
|
local can_build = true
|
||||||
local test_items = {}
|
local test_items = {}
|
||||||
local test_build_fuel_cost = 0
|
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
|
if layout.builders ~= nil then
|
||||||
for _, location in pairs(layout.builders) do
|
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 targetdef = minetest.registered_nodes[target.name]
|
||||||
local test_location = vector.add(location.pos, dir)
|
local test_location = vector.add(location.pos, dir)
|
||||||
if targetdef.test_build ~= nil then
|
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
|
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
|
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
|
local strange_failure = false
|
||||||
-- execute_build on all digtron components that have one
|
-- execute_build on all digtron components that have one
|
||||||
if layout.builders ~= nil then
|
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 target = minetest.get_node(location.pos)
|
||||||
local targetdef = minetest.registered_nodes[target.name]
|
local targetdef = minetest.registered_nodes[target.name]
|
||||||
if targetdef.execute_build ~= nil then
|
if targetdef.execute_build ~= nil then
|
||||||
@ -357,7 +357,7 @@ digtron.execute_dig_cycle = function(pos, clicker)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if layout.auto_ejectors ~= nil then
|
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 target = minetest.get_node(location.pos)
|
||||||
local targetdef = minetest.registered_nodes[target.name]
|
local targetdef = minetest.registered_nodes[target.name]
|
||||||
if targetdef.execute_eject ~= nil then
|
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()
|
local node_to_dig, whether_to_dig = layout.nodes_dug:pop()
|
||||||
while node_to_dig ~= nil do
|
while node_to_dig ~= nil do
|
||||||
if whether_to_dig == true then
|
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)
|
minetest.remove_node(node_to_dig)
|
||||||
end
|
end
|
||||||
-- all of the digtron's nodes wind up in nodes_dug, so this is an ideal place to stick
|
-- 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.
|
-- 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 we dug them now, sand would fall and some digtron nodes would die.
|
||||||
if layout.diggers ~= nil then
|
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 target = minetest.get_node(location.pos)
|
||||||
local targetdef = minetest.registered_nodes[target.name]
|
local targetdef = minetest.registered_nodes[target.name]
|
||||||
if targetdef.execute_dig ~= nil then
|
if targetdef.execute_dig ~= nil then
|
||||||
@ -562,7 +564,7 @@ digtron.execute_downward_dig_cycle = function(pos, clicker)
|
|||||||
|
|
||||||
-- damage the weak flesh
|
-- damage the weak flesh
|
||||||
if digtron.config.damage_hp > 0 and layout.diggers ~= nil then
|
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 target = minetest.get_node(location.pos)
|
||||||
local targetdef = minetest.registered_nodes[target.name]
|
local targetdef = minetest.registered_nodes[target.name]
|
||||||
if targetdef.damage_creatures ~= nil then
|
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()
|
local node_to_dig, whether_to_dig = layout.nodes_dug:pop()
|
||||||
while node_to_dig ~= nil do
|
while node_to_dig ~= nil do
|
||||||
if whether_to_dig == true then
|
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)
|
minetest.remove_node(node_to_dig)
|
||||||
end
|
end
|
||||||
node_to_dig, whether_to_dig = layout.nodes_dug:pop()
|
node_to_dig, whether_to_dig = layout.nodes_dug:pop()
|
||||||
|
Loading…
Reference in New Issue
Block a user