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
25
util.lua
25
util.lua
@ -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
|
||||
@ -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
|
||||
@ -195,7 +195,7 @@ digtron.burn = function(fuelstore_positions, target, test)
|
||||
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
|
||||
@ -238,7 +238,7 @@ digtron.tap_batteries = function(battery_positions, target, test)
|
||||
-- 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
|
||||
@ -250,7 +250,7 @@ digtron.tap_batteries = function(battery_positions, target, test)
|
||||
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,7 +265,6 @@ digtron.tap_batteries = function(battery_positions, target, test)
|
||||
end
|
||||
current_burned = current_burned + actual_burned
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if current_burned > target then
|
||||
@ -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
|
||||
|
||||
@ -413,11 +412,11 @@ digtron.show_offset_markers = function(pos, offset, period)
|
||||
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()
|
||||
|
Loading…
Reference in New Issue
Block a user