add luacheck and ci workflow (#88)

* add luacheck and ci workflow

* fix another bunch

* more fixes

* more fixes

* regex magic

* add deps

* doc.lua special rules

* more regex magic

* final fixes

---------

Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
This commit is contained in:
Buckaroo Banzai 2023-06-19 07:44:40 +02:00 committed by GitHub
parent 3f9ca87269
commit 3e1c1ca208
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 669 additions and 605 deletions

17
.github/workflows/luacheck.yml vendored Normal file

@ -0,0 +1,17 @@
name: luacheck
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: apt
run: sudo apt-get install -y luarocks
- name: luacheck install
run: luarocks install --local luacheck
- name: luacheck run
run: $HOME/.luarocks/bin/luacheck ./

27
.luacheckrc Normal file

@ -0,0 +1,27 @@
max_line_length = 200
globals = {
"digtron",
"catacomb"
}
read_globals = {
-- Stdlib
string = {fields = {"split"}},
table = {fields = {"copy", "getn"}},
"VoxelManip",
-- Minetest
"minetest",
"vector", "ItemStack",
"dump", "VoxelArea",
-- Deps
"default", "awards", "pipeworks", "hopper", "technic", "doc", "intllib"
}
files = {
["doc.lua"] = {
max_line_length = 1000
}
}

@ -1,8 +1,8 @@
if not minetest.get_modpath("awards") then if not minetest.get_modpath("awards") then
digtron.award_item_dug = function (items, name, count) end digtron.award_item_dug = function() end
digtron.award_layout = function (layout, name) end digtron.award_layout = function() end
digtron.award_item_built = function(item_name, name) end digtron.award_item_built = function() end
digtron.award_crate = function (layout, name) end digtron.award_crate = function() end
return return
end end
@ -10,14 +10,14 @@ end
-- internationalization boilerplate -- internationalization boilerplate
local MP = minetest.get_modpath(minetest.get_current_modname()) local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP.."/intllib.lua") local S = dofile(MP.."/intllib.lua")
awards.register_trigger("digtron_dig", { awards.register_trigger("digtron_dig", {
type = "counted_key", type = "counted_key",
progress = "@1/@2 excavated", progress = "@1/@2 excavated",
auto_description = {"Excavate 1 @2 using a Digtron.", "Excavate @1 @2 using a Digtron."}, auto_description = {"Excavate 1 @2 using a Digtron.", "Excavate @1 @2 using a Digtron."},
auto_description_total = {"Excavate @1 block using a Digtron.", "Excavate @1 blocks using a Digtron."}, auto_description_total = {"Excavate @1 block using a Digtron.", "Excavate @1 blocks using a Digtron."},
get_key = function(self, def) get_key = function(_, def)
return minetest.registered_aliases[def.trigger.node] or def.trigger.node return minetest.registered_aliases[def.trigger.node] or def.trigger.node
end, end,
key_is_item = true, key_is_item = true,
@ -37,7 +37,7 @@ awards.register_trigger("digtron_build", {
progress = "@1/@2 built", progress = "@1/@2 built",
auto_description = {"Build 1 @2 using a Digtron.", "Build @1 @2 using a Digtron."}, auto_description = {"Build 1 @2 using a Digtron.", "Build @1 @2 using a Digtron."},
auto_description_total = {"Build @1 block using a Digtron.", "Build @1 blocks using a Digtron."}, auto_description_total = {"Build @1 block using a Digtron.", "Build @1 blocks using a Digtron."},
get_key = function(self, def) get_key = function(_, def)
return minetest.registered_aliases[def.trigger.node] or def.trigger.node return minetest.registered_aliases[def.trigger.node] or def.trigger.node
end, end,
key_is_item = true, key_is_item = true,

@ -9,8 +9,8 @@
-- I'm trying to patch holes in bad mod programming, essentially. If a mod is so badly -- I'm trying to patch holes in bad mod programming, essentially. If a mod is so badly
-- programmed that it crashes anyway there's not a lot else I can do on my end of things. -- programmed that it crashes anyway there's not a lot else I can do on my end of things.
DigtronFakePlayer = {} digtron.DigtronFakePlayer = {}
DigtronFakePlayer.__index = DigtronFakePlayer digtron.DigtronFakePlayer.__index = digtron.DigtronFakePlayer
local function return_value(x) local function return_value(x)
return (function() return x end) return (function() return x end)
@ -32,14 +32,14 @@ local function return_empty_table()
return {} return {}
end end
function DigtronFakePlayer.update(self, pos, player_name) function digtron.DigtronFakePlayer.update(self, pos, player_name)
self.is_fake_player = ":digtron " .. player_name self.is_fake_player = ":digtron " .. player_name
self.get_pos = return_value(pos) self.get_pos = return_value(pos)
end end
function DigtronFakePlayer.create(pos, player_name) function digtron.DigtronFakePlayer.create(pos, player_name)
local self = {} local self = {}
setmetatable(self, DigtronFakePlayer) setmetatable(self, digtron.DigtronFakePlayer)
self.is_fake_player = ":digtron " .. player_name self.is_fake_player = ":digtron " .. player_name
@ -87,7 +87,6 @@ function DigtronFakePlayer.create(pos, player_name)
self.get_luaentity = return_nil self.get_luaentity = return_nil
-- Player object -- Player object
self.get_player_name = return_empty_string self.get_player_name = return_empty_string
self.get_player_velocity = return_nil self.get_player_velocity = return_nil
self.get_look_dir = return_value({x=0,y=1,z=0}) self.get_look_dir = return_value({x=0,y=1,z=0})
@ -113,7 +112,6 @@ function DigtronFakePlayer.create(pos, player_name)
self.set_physics_override = return_nil self.set_physics_override = return_nil
self.get_physics_override = return_value({speed = 1, jump = 1, gravity = 1, sneak = true, sneak_glitch = false, new_move = true,}) self.get_physics_override = return_value({speed = 1, jump = 1, gravity = 1, sneak = true, sneak_glitch = false, new_move = true,})
self.hud_add = return_nil self.hud_add = return_nil
self.hud_remove = return_nil self.hud_remove = return_nil
self.hud_change = return_nil self.hud_change = return_nil

@ -1,7 +1,5 @@
DigtronLayout = {} digtron.DigtronLayout = {}
DigtronLayout.__index = DigtronLayout digtron.DigtronLayout.__index = digtron.DigtronLayout
local modpath_awards = minetest.get_modpath("awards")
------------------------------------------------------------------------- -------------------------------------------------------------------------
-- Creation -- Creation
@ -45,25 +43,27 @@ local get_node_image = function(pos, node)
end end
-- temporary pointsets used while searching -- temporary pointsets used while searching
local to_test = Pointset.create() local to_test = digtron.Pointset.create()
local tested = Pointset.create() local tested = digtron.Pointset.create()
function DigtronLayout.create(pos, player) function digtron.DigtronLayout.create(pos, player)
local self = {} local self = {}
setmetatable(self, DigtronLayout) setmetatable(self, digtron.DigtronLayout)
--initialize. We're assuming that the start position is a controller digtron, should be a safe assumption since only the controller node should call this --initialize. We're assuming that the start position is a controller digtron, should be a safe assumption since only the controller node should call this
self.traction = 0 self.traction = 0
self.all = {} self.all = {}
self.water_touching = false self.water_touching = false
self.lava_touching = false self.lava_touching = false
self.protected = Pointset.create() -- if any nodes we look at are protected, make note of that. That way we don't need to keep re-testing protection state later. self.protected = digtron.Pointset.create() -- if any nodes we look at are protected, make note of that. That way we don't need to keep re-testing protection state later.
self.old_pos_pointset = Pointset.create() -- For tracking original location of nodes if we do transformations on the Digtron self.old_pos_pointset = digtron.Pointset.create() -- For tracking original location of nodes if we do transformations on the Digtron
self.nodes_dug = Pointset.create() -- For tracking adjacent nodes that will have been dug by digger heads in future self.nodes_dug = digtron.Pointset.create() -- For tracking adjacent nodes that will have been dug by digger heads in future
self.contains_protected_node = false -- used to indicate if at least one node in this digtron array is protected from the player. self.contains_protected_node = false -- used to indicate if at least one node in this digtron array is protected from the player.
self.controller = {x=pos.x, y=pos.y, z=pos.z} --Make a deep copy of the pos parameter just in case the calling code wants to play silly buggers with it self.controller = {x=pos.x, y=pos.y, z=pos.z} --Make a deep copy of the pos parameter just in case the calling code wants to play silly buggers with it
table.insert(self.all, get_node_image(pos, minetest.get_node(pos))) -- We never visit the source node, so insert it into the all table a priori. Revisit this design decision if a controller node is created that contains fuel or inventory or whatever. -- We never visit the source node, so insert it into the all table a priori.
-- Revisit this design decision if a controller node is created that contains fuel or inventory or whatever.
table.insert(self.all, get_node_image(pos, minetest.get_node(pos)))
self.extents_max_x = pos.x self.extents_max_x = pos.x
self.extents_min_x = pos.x self.extents_min_x = pos.x
@ -311,7 +311,7 @@ local top = {
{axis="y", dir=1}, {axis="y", dir=1},
} }
-- Rotates 90 degrees widdershins around the axis defined by facedir (which in this case is pointing out the front of the node, so it needs to be converted into an upward-pointing axis internally) -- Rotates 90 degrees widdershins around the axis defined by facedir (which in this case is pointing out the front of the node, so it needs to be converted into an upward-pointing axis internally)
function DigtronLayout.rotate_layout_image(self, facedir) function digtron.DigtronLayout.rotate_layout_image(self, facedir)
if self == nil or self.all == nil or self.controller == nil or self.old_pos_pointset == nil then if self == nil or self.all == nil or self.controller == nil or self.old_pos_pointset == nil then
-- this should not be possible, but if it is then abort. -- this should not be possible, but if it is then abort.
@ -328,7 +328,7 @@ function DigtronLayout.rotate_layout_image(self, facedir)
local params = top[math.floor(facedir/4)] local params = top[math.floor(facedir/4)]
for k, node_image in pairs(self.all) do for _, node_image in pairs(self.all) do
rotate_node_image(node_image, self.controller, params.axis, params.dir, self.old_pos_pointset) rotate_node_image(node_image, self.controller, params.axis, params.dir, self.old_pos_pointset)
end end
return self return self
@ -337,7 +337,7 @@ end
----------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------
-- Translation -- Translation
function DigtronLayout.move_layout_image(self, dir) function digtron.DigtronLayout.move_layout_image(self, dir)
self.extents_max_x = self.extents_max_x + dir.x self.extents_max_x = self.extents_max_x + dir.x
self.extents_min_x = self.extents_min_x + dir.x self.extents_min_x = self.extents_min_x + dir.x
self.extents_max_y = self.extents_max_y + dir.y self.extents_max_y = self.extents_max_y + dir.y
@ -345,7 +345,7 @@ function DigtronLayout.move_layout_image(self, dir)
self.extents_max_z = self.extents_max_z + dir.z self.extents_max_z = self.extents_max_z + dir.z
self.extents_min_z = self.extents_min_z + dir.z self.extents_min_z = self.extents_min_z + dir.z
for k, node_image in pairs(self.all) do for _, node_image in pairs(self.all) do
self.old_pos_pointset:set(node_image.pos.x, node_image.pos.y, node_image.pos.z, true) self.old_pos_pointset:set(node_image.pos.x, node_image.pos.y, node_image.pos.z, true)
node_image.pos = add_in_place(node_image.pos, dir) node_image.pos = add_in_place(node_image.pos, dir)
self.nodes_dug:set(node_image.pos.x, node_image.pos.y, node_image.pos.z, false) -- we've moved a digtron node into this space, mark it so that we don't dig it. self.nodes_dug:set(node_image.pos.x, node_image.pos.y, node_image.pos.z, false) -- we've moved a digtron node into this space, mark it so that we don't dig it.
@ -355,8 +355,8 @@ end
----------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------
-- Writing to world -- Writing to world
function DigtronLayout.can_write_layout_image(self) function digtron.DigtronLayout.can_write_layout_image(self)
for k, node_image in pairs(self.all) do for _, node_image in pairs(self.all) do
--check if we're moving into a protected node --check if we're moving into a protected node
if self.protected:get(node_image.pos.x, node_image.pos.y, node_image.pos.z) then if self.protected:get(node_image.pos.x, node_image.pos.y, node_image.pos.z) then
return false return false
@ -452,7 +452,7 @@ local set_meta_with_retry = function(meta, meta_table)
end end
local air_node = {name="air"} local air_node = {name="air"}
function DigtronLayout.write_layout_image(self, player) function digtron.DigtronLayout.write_layout_image(self, player)
-- destroy the old digtron -- destroy the old digtron
local oldpos, _ = self.old_pos_pointset:pop() local oldpos, _ = self.old_pos_pointset:pop()
while oldpos ~= nil do while oldpos ~= nil do
@ -472,7 +472,7 @@ function DigtronLayout.write_layout_image(self, player)
end end
-- create the new one -- create the new one
for k, node_image in pairs(self.all) do for _, node_image in pairs(self.all) do
local new_pos = node_image.pos local new_pos = node_image.pos
local new_node = node_image.node local new_node = node_image.node
local old_node = minetest.get_node(new_pos) local old_node = minetest.get_node(new_pos)
@ -502,10 +502,10 @@ end
--------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------
-- Serialization. Currently only serializes the data that is needed by the crate, upgrade this function if more is needed -- Serialization. Currently only serializes the data that is needed by the crate, upgrade this function if more is needed
function DigtronLayout.serialize(self) function digtron.DigtronLayout.serialize(self)
-- serialize can't handle ItemStack objects, convert them to strings. -- serialize can't handle ItemStack objects, convert them to strings.
for _, node_image in pairs(self.all) do for _, node_image in pairs(self.all) do
for k, inv in pairs(node_image.meta.inventory) do for _, inv in pairs(node_image.meta.inventory) do
for index, item in pairs(inv) do for index, item in pairs(inv) do
inv[index] = item:to_string() inv[index] = item:to_string()
end end
@ -515,9 +515,9 @@ function DigtronLayout.serialize(self)
return minetest.serialize({controller=self.controller, all=self.all}) return minetest.serialize({controller=self.controller, all=self.all})
end end
function DigtronLayout.deserialize(layout_string) function digtron.DigtronLayout.deserialize(layout_string)
local self = {} local self = {}
setmetatable(self, DigtronLayout) setmetatable(self, digtron.DigtronLayout)
if not layout_string or layout_string == "" then if not layout_string or layout_string == "" then
return nil return nil
@ -526,7 +526,7 @@ function DigtronLayout.deserialize(layout_string)
self.all = deserialized_layout.all self.all = deserialized_layout.all
self.controller = deserialized_layout.controller self.controller = deserialized_layout.controller
self.old_pos_pointset = Pointset.create() -- needed by the write_layout method, leave empty self.old_pos_pointset = digtron.Pointset.create() -- needed by the write_layout method, leave empty
return self return self
end end

@ -1,7 +1,7 @@
-- A simple special-purpose class, this is used for building up sets of three-dimensional points for fast reference -- A simple special-purpose class, this is used for building up sets of three-dimensional points for fast reference
Pointset = {} digtron.Pointset = {}
Pointset.__index = Pointset digtron.Pointset.__index = digtron.Pointset
-- from builtin\game\misc.lua, modified to take values directly to avoid creating an intermediate vector -- from builtin\game\misc.lua, modified to take values directly to avoid creating an intermediate vector
local hash_node_position_values = function(x, y, z) local hash_node_position_values = function(x, y, z)
@ -10,26 +10,26 @@ local hash_node_position_values = function(x, y, z)
+ x + 32768 + x + 32768
end end
function Pointset.create() function digtron.Pointset.create()
local set = {} local set = {}
setmetatable(set,Pointset) setmetatable(set,digtron.Pointset)
set.points = {} set.points = {}
return set return set
end end
function Pointset:clear() function digtron.Pointset:clear()
local points = self.points local points = self.points
for k, v in pairs(points) do for k in pairs(points) do
points[k] = nil points[k] = nil
end end
end end
function Pointset:set(x, y, z, value) function digtron.Pointset:set(x, y, z, value)
-- sets a value in the 3D array "points". -- sets a value in the 3D array "points".
self.points[hash_node_position_values(x,y,z)] = value self.points[hash_node_position_values(x,y,z)] = value
end end
function Pointset:set_if_not_in(excluded, x, y, z, value) function digtron.Pointset:set_if_not_in(excluded, x, y, z, value)
-- If a value is not already set for this point in the 3D array "excluded", set it in "points" -- If a value is not already set for this point in the 3D array "excluded", set it in "points"
if excluded:get(x, y, z) ~= nil then if excluded:get(x, y, z) ~= nil then
return return
@ -37,24 +37,24 @@ function Pointset:set_if_not_in(excluded, x, y, z, value)
self:set(x, y, z, value) self:set(x, y, z, value)
end end
function Pointset:get(x, y, z) function digtron.Pointset:get(x, y, z)
-- return a value from the 3D array "points" -- return a value from the 3D array "points"
return self.points[hash_node_position_values(x,y,z)] return self.points[hash_node_position_values(x,y,z)]
end end
function Pointset:set_pos(pos, value) function digtron.Pointset:set_pos(pos, value)
self:set(pos.x, pos.y, pos.z, value) self:set(pos.x, pos.y, pos.z, value)
end end
function Pointset:set_pos_if_not_in(excluded, pos, value) function digtron.Pointset:set_pos_if_not_in(excluded, pos, value)
self:set_if_not_in(excluded, pos.x, pos.y, pos.z, value) self:set_if_not_in(excluded, pos.x, pos.y, pos.z, value)
end end
function Pointset:get_pos(pos) function digtron.Pointset:get_pos(pos)
return self:get(pos.x, pos.y, pos.z) return self:get(pos.x, pos.y, pos.z)
end end
function Pointset:pop() function digtron.Pointset:pop()
-- returns a point that's in the 3D array, and then removes it. -- returns a point that's in the 3D array, and then removes it.
local hash, value = next(self.points) local hash, value = next(self.points)
if hash == nil then return nil end if hash == nil then return nil end
@ -63,8 +63,9 @@ function Pointset:pop()
return pos, value return pos, value
end end
function Pointset:get_pos_list(value) function digtron.Pointset:get_pos_list(value)
-- Returns a list of all points with the given value in standard Minetest vector format. If no value is provided, returns all points -- Returns a list of all points with the given value in standard Minetest vector format.
-- If no value is provided, returns all points
local outlist = {} local outlist = {}
for hash, pointsval in pairs(self.points) do for hash, pointsval in pairs(self.points) do
if value == nil or pointsval == value then if value == nil or pointsval == value then
@ -73,5 +74,3 @@ function Pointset:get_pos_list(value)
end end
return outlist return outlist
end end

@ -14,7 +14,7 @@ local battery_ratio = (10000/digtron.config.power_ratio) / coal_fuel
-- internationalization boilerplate -- internationalization boilerplate
local MP = minetest.get_modpath(minetest.get_current_modname()) local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP.."/intllib.lua") local S = dofile(MP.."/intllib.lua")
local pipeworks_enabled = minetest.get_modpath("pipeworks") ~= nil local pipeworks_enabled = minetest.get_modpath("pipeworks") ~= nil
local hoppers_enabled = minetest.get_modpath("hopper") and hopper ~= nil and hopper.add_container ~= nil local hoppers_enabled = minetest.get_modpath("hopper") and hopper ~= nil and hopper.add_container ~= nil

@ -7,19 +7,19 @@ minetest.register_entity("digtron:marker", {
physical = false, physical = false,
}, },
on_activate = function(self, staticdata) on_activate = function(self)
minetest.after(5.0, minetest.after(5.0,
function(self) function()
self.object:remove() self.object:remove()
end, end,
self) self)
end, end,
on_rightclick=function(self, clicker) on_rightclick=function(self)
self.object:remove() self.object:remove()
end, end,
on_punch = function(self, hitter) on_punch = function(self)
self.object:remove() self.object:remove()
end, end,
}) })
@ -28,24 +28,31 @@ minetest.register_entity("digtron:marker_vertical", {
initial_properties = { initial_properties = {
visual = "cube", visual = "cube",
visual_size = {x=1.05, y=1.05}, visual_size = {x=1.05, y=1.05},
textures = {"digtron_marker.png","digtron_marker.png","digtron_marker_side.png^[transformR90","digtron_marker_side.png^[transformR90","digtron_marker_side.png^[transformR90","digtron_marker_side.png^[transformR90"}, textures = {
"digtron_marker.png",
"digtron_marker.png",
"digtron_marker_side.png^[transformR90",
"digtron_marker_side.png^[transformR90",
"digtron_marker_side.png^[transformR90",
"digtron_marker_side.png^[transformR90"
},
collisionbox = {-0.525, -0.525, -0.525, 0.525, 0.525, 0.525}, collisionbox = {-0.525, -0.525, -0.525, 0.525, 0.525, 0.525},
physical = false, physical = false,
}, },
on_activate = function(self, staticdata) on_activate = function(self)
minetest.after(5.0, minetest.after(5.0,
function(self) function()
self.object:remove() self.object:remove()
end, end,
self) self)
end, end,
on_rightclick=function(self, clicker) on_rightclick=function(self)
self.object:remove() self.object:remove()
end, end,
on_punch = function(self, hitter) on_punch = function(self)
self.object:remove() self.object:remove()
end, end,
}) })
@ -59,19 +66,19 @@ minetest.register_entity("digtron:marker_crate_good", {
physical = false, physical = false,
}, },
on_activate = function(self, staticdata) on_activate = function(self)
minetest.after(digtron.config.marker_crate_good_duration, minetest.after(digtron.config.marker_crate_good_duration,
function(self) function()
self.object:remove() self.object:remove()
end, end,
self) self)
end, end,
on_rightclick=function(self, clicker) on_rightclick=function(self)
self.object:remove() self.object:remove()
end, end,
on_punch = function(self, hitter) on_punch = function(self)
self.object:remove() self.object:remove()
end, end,
}) })
@ -85,19 +92,19 @@ minetest.register_entity("digtron:marker_crate_bad", {
physical = false, physical = false,
}, },
on_activate = function(self, staticdata) on_activate = function(self)
minetest.after(digtron.config.marker_crate_bad_duration, minetest.after(digtron.config.marker_crate_bad_duration,
function(self) function()
self.object:remove() self.object:remove()
end, end,
self) self)
end, end,
on_rightclick=function(self, clicker) on_rightclick=function(self)
self.object:remove() self.object:remove()
end, end,
on_punch = function(self, hitter) on_punch = function(self)
self.object:remove() self.object:remove()
end, end,
}) })

@ -42,7 +42,8 @@ local digtron_modpath = minetest.get_modpath( "digtron" )
dofile( digtron_modpath .. "/class_fakeplayer.lua") dofile( digtron_modpath .. "/class_fakeplayer.lua")
digtron.fake_player = DigtronFakePlayer.create({x=0,y=0,z=0}, "fake_player") -- since we only need one fake player at a time and it doesn't retain useful state, create a global one and just update it as needed. -- since we only need one fake player at a time and it doesn't retain useful state, create a global one and just update it as needed.
digtron.fake_player = digtron.DigtronFakePlayer.create({x=0,y=0,z=0}, "fake_player")
dofile( digtron_modpath .. "/config.lua" ) dofile( digtron_modpath .. "/config.lua" )
dofile( digtron_modpath .. "/util.lua" ) dofile( digtron_modpath .. "/util.lua" )

@ -1,6 +1,6 @@
-- internationalization boilerplate -- internationalization boilerplate
local MP = minetest.get_modpath(minetest.get_current_modname()) local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP.."/intllib.lua") local S = dofile(MP.."/intllib.lua")
minetest.register_node("digtron:axle", { minetest.register_node("digtron:axle", {
description = S("Digtron Rotation Axle"), description = S("Digtron Rotation Axle"),
@ -38,7 +38,7 @@ minetest.register_node("digtron:axle", {
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) on_rightclick = function(pos, node, clicker)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
-- new delay code without nodetimer (lost on crating) -- new delay code without nodetimer (lost on crating)
@ -54,7 +54,7 @@ minetest.register_node("digtron:axle", {
return return
end end
local image = DigtronLayout.create(pos, clicker) local image = digtron.DigtronLayout.create(pos, clicker)
if image:rotate_layout_image(node.param2) == false then if image:rotate_layout_image(node.param2) == false then
-- This should be impossible, but if self-validation fails abort. -- This should be impossible, but if self-validation fails abort.
return return
@ -77,7 +77,7 @@ minetest.register_node("digtron:axle", {
end end
end, end,
on_timer = function(pos, elapsed) on_timer = function(pos)
minetest.get_meta(pos):set_string("waiting", nil) minetest.get_meta(pos):set_string("waiting", nil)
end, end,
}) })

@ -1,6 +1,6 @@
-- internationalization boilerplate -- internationalization boilerplate
local MP = minetest.get_modpath(minetest.get_current_modname()) local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP.."/intllib.lua") local S = dofile(MP.."/intllib.lua")
-- Battery storage. Controller node draws electrical power from here. -- Battery storage. Controller node draws electrical power from here.
@ -18,7 +18,7 @@ local battery_holder_formspec_string = "size[8,9.3]" ..
"listring[current_player;main]" .. "listring[current_player;main]" ..
default.get_hotbar_bg(0,5.15) default.get_hotbar_bg(0,5.15)
local battery_holder_formspec = function(pos, meta) local battery_holder_formspec = function()
return battery_holder_formspec_string return battery_holder_formspec_string
end end
@ -64,7 +64,7 @@ minetest.register_node("digtron:battery_holder", {
end, end,
-- Allow all items with energy storage to be placed in the inventory -- Allow all items with energy storage to be placed in the inventory
allow_metadata_inventory_put = function(pos, listname, index, stack, player) allow_metadata_inventory_put = function(_, listname, _, stack)
if listname == "batteries" then if listname == "batteries" then
local node_name = stack:get_name() local node_name = stack:get_name()
@ -88,7 +88,7 @@ minetest.register_node("digtron:battery_holder", {
end, end,
can_dig = function(pos,player) can_dig = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
return inv:is_empty("batteries") return inv:is_empty("batteries")
@ -99,18 +99,18 @@ minetest.register_node("digtron:battery_holder", {
----------------------------------------------------------------- -----------------------------------------------------------------
tube = (function() if minetest.get_modpath("pipeworks") then return { tube = (function() if minetest.get_modpath("pipeworks") then return {
insert_object = function(pos, node, stack, direction) insert_object = function(pos, _, stack)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
return inv:add_item("batteries", stack) return inv:add_item("batteries", stack)
end, end,
can_insert = function(pos, node, stack, direction) can_insert = function(pos, _, stack)
local meta = stack:get_metadata() local meta = stack:get_metadata()
local md = minetest.deserialize(meta) local md = minetest.deserialize(meta)
-- And specifically if they hold any charge -- And specifically if they hold any charge
-- Disregard empty batteries, the player should know better -- Disregard empty batteries, the player should know better
if md and md.charge > 0 then if md and md.charge > 0 then
local meta = minetest.get_meta(pos) meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
return inv:room_for_item("batteries", stack) return inv:room_for_item("batteries", stack)
end end

@ -1,6 +1,6 @@
-- internationalization boilerplate -- internationalization boilerplate
local MP = minetest.get_modpath(minetest.get_current_modname()) local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP.."/intllib.lua") local S = dofile(MP.."/intllib.lua")
-- Note: builders go in group 4 and have both test_build and execute_build methods. -- Note: builders go in group 4 and have both test_build and execute_build methods.
@ -19,15 +19,18 @@ local builder_formspec_string =
"list[current_name;main;".. tostring(displace_due_to_help_button/2) ..",0;1,1;]" .. "list[current_name;main;".. tostring(displace_due_to_help_button/2) ..",0;1,1;]" ..
"label[" .. tostring(displace_due_to_help_button/2).. ",0.8;" .. S("Block to build") .. "]" .. "label[" .. tostring(displace_due_to_help_button/2).. ",0.8;" .. S("Block to build") .. "]" ..
"field[" .. tostring(displace_due_to_help_button + 1.3) ..",0.8;1,0.1;extrusion;" .. S("Extrusion") .. ";${extrusion}]" .. "field[" .. tostring(displace_due_to_help_button + 1.3) ..",0.8;1,0.1;extrusion;" .. S("Extrusion") .. ";${extrusion}]" ..
"tooltip[extrusion;" .. S("Builder will extrude this many blocks in the direction it is facing.\nCan be set from 1 to @1.\nNote that Digtron won't build into unloaded map regions.", digtron.config.maximum_extrusion) .. "]" .. "tooltip[extrusion;" .. S("Builder will extrude this many blocks in the direction it is facing.\nCan be set from 1 to @1.\nNote that Digtron won't build into unloaded map regions.",
digtron.config.maximum_extrusion) .. "]" ..
"field[" .. tostring(displace_due_to_help_button + 2.3) ..",0.8;1,0.1;period;" .. S("Periodicity") .. ";${period}]" .. "field[" .. tostring(displace_due_to_help_button + 2.3) ..",0.8;1,0.1;period;" .. S("Periodicity") .. ";${period}]" ..
"tooltip[period;" .. S("Builder will build once every n steps.\nThese steps are globally aligned, so all builders with the\nsame period and offset will build on the same location.") .. "]" .. "tooltip[period;" .. S("Builder will build once every n steps.\nThese steps are globally aligned, so all builders with the\nsame period and offset will build on the same location.") .. "]" ..
"field[" .. tostring(displace_due_to_help_button + 3.3) ..",0.8;1,0.1;offset;" .. S("Offset") .. ";${offset}]" .. "field[" .. tostring(displace_due_to_help_button + 3.3) ..",0.8;1,0.1;offset;" .. S("Offset") .. ";${offset}]" ..
"tooltip[offset;" .. S("Offsets the start of periodicity counting by this amount.\nFor example, a builder with period 2 and offset 0 builds\nevery even-numbered block and one with period 2 and\noffset 1 builds every odd-numbered block.") .. "]" .. "tooltip[offset;" .. S("Offsets the start of periodicity counting by this amount.\nFor example, a builder with period 2 and offset 0 builds\nevery even-numbered block and one with period 2 and\n" ..
"offset 1 builds every odd-numbered block.") .. "]" ..
"button_exit[" .. tostring(displace_due_to_help_button + 4.0) ..",0.5;1,0.1;set;" .. S("Save &\nShow") .. "]" .. "button_exit[" .. tostring(displace_due_to_help_button + 4.0) ..",0.5;1,0.1;set;" .. S("Save &\nShow") .. "]" ..
"tooltip[set;" .. S("Saves settings") .. "]" .. "tooltip[set;" .. S("Saves settings") .. "]" ..
"field[" .. tostring(displace_due_to_help_button + 5.3) .. ",0.8;1,0.1;build_facing;" .. S("Facing") .. ";${build_facing}]" .. "field[" .. tostring(displace_due_to_help_button + 5.3) .. ",0.8;1,0.1;build_facing;" .. S("Facing") .. ";${build_facing}]" ..
"tooltip[build_facing;" .. S("Value from 0-23. Not all block types make use of this.\nUse the 'Read & Save' button to copy the facing of the block\ncurrently in the builder output location.") .. "]" .. "tooltip[build_facing;" .. S("Value from 0-23. Not all block types make use of this.\nUse the 'Read & Save' button to copy the facing of the block\n" ..
"currently in the builder output location.") .. "]" ..
"button_exit[" .. tostring(displace_due_to_help_button + 6.0) ..",0.5;1,0.1;read;" .. S("Read &\nSave") .. "]" .. "button_exit[" .. tostring(displace_due_to_help_button + 6.0) ..",0.5;1,0.1;read;" .. S("Read &\nSave") .. "]" ..
"tooltip[read;" .. S("Reads the facing of the block currently in the build location,\nthen saves all settings.") .. "]" .. "tooltip[read;" .. S("Reads the facing of the block currently in the build location,\nthen saves all settings.") .. "]" ..
"list[current_player;main;0,1.3;8,1;]" .. "list[current_player;main;0,1.3;8,1;]" ..
@ -43,7 +46,6 @@ if minetest.get_modpath("doc") then
end end
local builder_formspec = function(pos, meta) local builder_formspec = function(pos, meta)
local nodemeta = "nodemeta:"..pos.x .. "," .. pos.y .. "," ..pos.z
return builder_formspec_string return builder_formspec_string
:gsub("${extrusion}", meta:get_int("extrusion"), 1) :gsub("${extrusion}", meta:get_int("extrusion"), 1)
:gsub("${period}", meta:get_int("period"), 1) :gsub("${period}", meta:get_int("period"), 1)
@ -52,7 +54,7 @@ local builder_formspec = function(pos, meta)
:gsub("current_name", "nodemeta:"..pos.x .. "," .. pos.y .. "," ..pos.z, 2) :gsub("current_name", "nodemeta:"..pos.x .. "," .. pos.y .. "," ..pos.z, 2)
end end
local builder_on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) local builder_on_rightclick = function(pos, _, clicker, itemstack, pointed_thing)
local item_def = itemstack:get_definition() local item_def = itemstack:get_definition()
if item_def.type == "node" and minetest.get_item_group(itemstack:get_name(), "digtron") > 0 then if item_def.type == "node" and minetest.get_item_group(itemstack:get_name(), "digtron") > 0 then
local returnstack, success = minetest.item_place_node(itemstack, clicker, pointed_thing) local returnstack, success = minetest.item_place_node(itemstack, clicker, pointed_thing)
@ -104,8 +106,6 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields)
end end
if extrusion and extrusion > 0 and extrusion <= digtron.config.maximum_extrusion then if extrusion and extrusion > 0 and extrusion <= digtron.config.maximum_extrusion then
meta:set_int("extrusion", math.floor(tonumber(fields.extrusion))) meta:set_int("extrusion", math.floor(tonumber(fields.extrusion)))
else
extrusion = meta:get_int("extrusion")
end end
local nodename = minetest.get_node_or_nil(pos).name local nodename = minetest.get_node_or_nil(pos).name
@ -115,7 +115,7 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields)
if fields.set then if fields.set then
-- copy current settings to all builders -- copy current settings to all builders
local layout = DigtronLayout.create(pos, sender) local layout = digtron.DigtronLayout.create(pos, sender)
if layout.builders ~= nil then if layout.builders ~= nil then
@ -125,9 +125,8 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields)
if target_item_name ~= "air" and minetest.get_item_group(target_item_name, "digtron") == 0 then if target_item_name ~= "air" and minetest.get_item_group(target_item_name, "digtron") == 0 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_meta = minetest.get_meta(location.pos) local target_meta = minetest.get_meta(location.pos)
target_meta:set_int("period", meta:get_int("period")) target_meta:set_int("period", meta:get_int("period"))
target_meta:set_int("offset", meta:get_int("offset")) target_meta:set_int("offset", meta:get_int("offset"))
@ -145,17 +144,16 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields)
elseif fields.read then elseif fields.read then
-- make all builders perform read&save -- make all builders perform read&save
local layout = DigtronLayout.create(pos, sender) local layout = digtron.DigtronLayout.create(pos, sender)
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 facing = minetest.get_node(location.pos).param2 local facing = minetest.get_node(location.pos).param2
local buildpos = digtron.find_new_pos(location.pos, facing) local buildpos = digtron.find_new_pos(location.pos, facing)
local target_node = minetest.get_node(buildpos) local target_node = minetest.get_node(buildpos)
if target_node.name ~= "air" and minetest.get_item_group(target_node.name, "digtron") == 0 then if target_node.name ~= "air" and minetest.get_item_group(target_node.name, "digtron") == 0 then
local meta = minetest.get_meta(location.pos) meta = minetest.get_meta(location.pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
local target_name = digtron.builder_read_item_substitutions[target_node.name] or target_node.name local target_name = digtron.builder_read_item_substitutions[target_node.name] or target_node.name
inv:set_stack("main", 1, target_name) inv:set_stack("main", 1, target_name)
@ -180,7 +178,7 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields)
local buildpos = digtron.find_new_pos(pos, facing) local buildpos = digtron.find_new_pos(pos, facing)
local target_node = minetest.get_node(buildpos) local target_node = minetest.get_node(buildpos)
if target_node.name ~= "air" and minetest.get_item_group(target_node.name, "digtron") == 0 then if target_node.name ~= "air" and minetest.get_item_group(target_node.name, "digtron") == 0 then
local meta = minetest.get_meta(pos) meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
local target_name = digtron.builder_read_item_substitutions[target_node.name] or target_node.name local target_name = digtron.builder_read_item_substitutions[target_node.name] or target_node.name
inv:set_stack("main", 1, target_name) inv:set_stack("main", 1, target_name)
@ -260,7 +258,7 @@ minetest.register_node("digtron:builder", {
digtron.update_builder_item(pos) digtron.update_builder_item(pos)
end, end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player) allow_metadata_inventory_put = function(pos, listname, index, stack)
local stack_name = stack:get_name() local stack_name = stack:get_name()
if minetest.get_item_group(stack_name, "digtron") ~= 0 then if minetest.get_item_group(stack_name, "digtron") ~= 0 then
@ -285,7 +283,7 @@ minetest.register_node("digtron:builder", {
return 0 return 0
end, end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player) allow_metadata_inventory_take = function(pos, listname, index)
node_inventory_table.pos = pos node_inventory_table.pos = pos
local inv = minetest.get_inventory(node_inventory_table) local inv = minetest.get_inventory(node_inventory_table)
inv:set_stack(listname, index, ItemStack("")) inv:set_stack(listname, index, ItemStack(""))
@ -302,7 +300,7 @@ minetest.register_node("digtron:builder", {
-- 1, {{itemstack, source inventory pos}, ...} -- can build, took items from inventory -- 1, {{itemstack, source inventory pos}, ...} -- can build, took items from inventory
-- 2, {{itemstack, source inventory pos}, ...}, itemstack -- was supposed to build, but couldn't get the item from inventory -- 2, {{itemstack, source inventory pos}, ...}, itemstack -- was supposed to build, but couldn't get the item from inventory
-- 3, {} -- builder configuration error -- 3, {} -- builder configuration error
test_build = function(pos, test_pos, inventory_positions, protected_nodes, nodes_dug, controlling_coordinate, controller_pos) test_build = function(pos, test_pos, inventory_positions, protected_nodes, nodes_dug, controlling_coordinate)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local facing = minetest.get_node(pos).param2 local facing = minetest.get_node(pos).param2
local buildpos = digtron.find_new_pos(test_pos, facing) local buildpos = digtron.find_new_pos(test_pos, facing)
@ -386,9 +384,10 @@ minetest.register_node("digtron:builder", {
local oldnode = minetest.get_node(buildpos) local oldnode = minetest.get_node(buildpos)
if not digtron.config.uses_resources then if not digtron.config.uses_resources then
local returned_stack, success = digtron.item_place_node(item_stack, player, buildpos, build_facing) local _, success = digtron.item_place_node(item_stack, player, buildpos, build_facing)
if success == true then if success == true then
minetest.log("action", string.format("%s uses Digtron to build %s at (%d, %d, %d), displacing %s", player:get_player_name(), item_stack:get_name(), buildpos.x, buildpos.y, buildpos.z, oldnode.name)) minetest.log("action",
string.format("%s uses Digtron to build %s at (%d, %d, %d), displacing %s", player:get_player_name(), item_stack:get_name(), buildpos.x, buildpos.y, buildpos.z, oldnode.name))
nodes_dug:set(buildpos.x, buildpos.y, buildpos.z, false) nodes_dug:set(buildpos.x, buildpos.y, buildpos.z, false)
built_count = built_count + 1 built_count = built_count + 1
else else
@ -401,9 +400,10 @@ minetest.register_node("digtron:builder", {
-- item not in inventory! Need to sound the angry buzzer to let the player know, so return a negative number. -- item not in inventory! Need to sound the angry buzzer to let the player know, so return a negative number.
return (built_count + 1) * -1 return (built_count + 1) * -1
end end
local returned_stack, success = digtron.item_place_node(ItemStack(item_stack), player, buildpos, build_facing) local _, success = digtron.item_place_node(ItemStack(item_stack), player, buildpos, build_facing)
if success == true then if success == true then
minetest.log("action", string.format("%s uses Digtron to build %s at (%d, %d, %d), displacing %s", player:get_player_name(), item_stack:get_name(), buildpos.x, buildpos.y, buildpos.z, oldnode.name)) minetest.log("action",
string.format("%s uses Digtron to build %s at (%d, %d, %d), displacing %s", player:get_player_name(), item_stack:get_name(), buildpos.x, buildpos.y, buildpos.z, oldnode.name))
--flag this node as *not* to be dug. --flag this node as *not* to be dug.
nodes_dug:set(buildpos.x, buildpos.y, buildpos.z, false) nodes_dug:set(buildpos.x, buildpos.y, buildpos.z, false)
digtron.award_item_built(item_stack:get_name(), player) digtron.award_item_built(item_stack:get_name(), player)
@ -489,7 +489,7 @@ minetest.register_node("digtron:master_builder", {
digtron.update_builder_item(pos) digtron.update_builder_item(pos)
end, end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player) allow_metadata_inventory_put = function(pos, listname, index, stack)
local stack_name = stack:get_name() local stack_name = stack:get_name()
if minetest.get_item_group(stack_name, "digtron") ~= 0 then if minetest.get_item_group(stack_name, "digtron") ~= 0 then
@ -514,7 +514,7 @@ minetest.register_node("digtron:master_builder", {
return 0 return 0
end, end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player) allow_metadata_inventory_take = function(pos, listname, index)
node_inventory_table.pos = pos node_inventory_table.pos = pos
local inv = minetest.get_inventory(node_inventory_table) local inv = minetest.get_inventory(node_inventory_table)
inv:set_stack(listname, index, ItemStack("")) inv:set_stack(listname, index, ItemStack(""))

@ -1,6 +1,6 @@
-- internationalization boilerplate -- internationalization boilerplate
local MP = minetest.get_modpath(minetest.get_current_modname()) local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP.."/intllib.lua") local S = dofile(MP.."/intllib.lua")
local controller_nodebox ={ local controller_nodebox ={
{-0.3125, -0.3125, -0.3125, 0.3125, 0.3125, 0.3125}, -- Core {-0.3125, -0.3125, -0.3125, 0.3125, 0.3125, 0.3125}, -- Core
@ -52,7 +52,7 @@ minetest.register_node("digtron:controller", {
meta:set_string("infotext", S("Heat remaining in controller furnace: @1", 0)) meta:set_string("infotext", S("Heat remaining in controller furnace: @1", 0))
end, end,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) on_rightclick = function(pos, _, clicker)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
-- new delay code without nodetimer (lost on crating) -- new delay code without nodetimer (lost on crating)
@ -69,7 +69,7 @@ minetest.register_node("digtron:controller", {
return return
end end
local newpos, status, return_code = digtron.execute_dig_cycle(pos, clicker) local newpos, status = digtron.execute_dig_cycle(pos, clicker)
meta = minetest.get_meta(newpos) meta = minetest.get_meta(newpos)
if status ~= nil then if status ~= nil then
@ -83,7 +83,7 @@ minetest.register_node("digtron:controller", {
meta:set_string("last_time",tostring(minetest.get_gametime())) meta:set_string("last_time",tostring(minetest.get_gametime()))
end, end,
on_timer = function(pos, elapsed) on_timer = function(pos)
minetest.get_meta(pos):set_string("waiting", nil) minetest.get_meta(pos):set_string("waiting", nil)
end, end,
}) })
@ -97,15 +97,18 @@ local auto_formspec = "size[8,6.2]" ..
default.gui_slots .. default.gui_slots ..
"container[2.0,0]" .. "container[2.0,0]" ..
"field[0.0,0.8;1,0.1;cycles;" .. S("Cycles").. ";${cycles}]" .. "field[0.0,0.8;1,0.1;cycles;" .. S("Cycles").. ";${cycles}]" ..
"tooltip[cycles;" .. S("When triggered, this controller will try to run for the given number of cycles.\nThe cycle count will decrement as it runs, so if it gets halted by a problem\nyou can fix the problem and restart.").. "]" .. "tooltip[cycles;" .. S("When triggered, this controller will try to run for the given number of cycles.\nThe cycle count will decrement as it runs, so if it gets halted by a problem\n" ..
"you can fix the problem and restart.").. "]" ..
"button_exit[0.7,0.5;1,0.1;set;" .. S("Set").. "]" .. "button_exit[0.7,0.5;1,0.1;set;" .. S("Set").. "]" ..
"tooltip[set;" .. S("Saves the cycle setting without starting the controller running").. "]" .. "tooltip[set;" .. S("Saves the cycle setting without starting the controller running").. "]" ..
"button_exit[1.7,0.5;1,0.1;execute;" .. S("Set &\nExecute").. "]" .. "button_exit[1.7,0.5;1,0.1;execute;" .. S("Set &\nExecute").. "]" ..
"tooltip[execute;" .. S("Begins executing the given number of cycles").. "]" .. "tooltip[execute;" .. S("Begins executing the given number of cycles").. "]" ..
"field[0.0,2.0;1,0.1;slope;" .. S("Slope").. ";${slope}]" .. "field[0.0,2.0;1,0.1;slope;" .. S("Slope").. ";${slope}]" ..
"tooltip[slope;" .. S("For diagonal digging. After moving forward this number of nodes the auto controller\nwill add an additional cycle moving the digtron laterally in the\ndirection of the arrows on the side of this controller.\nSet to 0 for no lateral digging.").. "]" .. "tooltip[slope;" .. S("For diagonal digging. After moving forward this number of nodes the auto controller\nwill add an additional cycle moving the digtron laterally in the\n" ..
"direction of the arrows on the side of this controller.\nSet to 0 for no lateral digging.").. "]" ..
"field[1.0,2.0;1,0.1;offset;" .. S("Offset").. ";${offset}]" .. "field[1.0,2.0;1,0.1;offset;" .. S("Offset").. ";${offset}]" ..
"tooltip[offset;" .. S("Sets the offset of the lateral motion defined in the Slope field.\nNote: this offset is relative to the controller's location.\nThe controller will move laterally when it reaches the indicated point.").. "]" .. "tooltip[offset;" .. S("Sets the offset of the lateral motion defined in the Slope field.\nNote: this offset is relative to the controller's location.\n" ..
"The controller will move laterally when it reaches the indicated point.").. "]" ..
"field[2.0,2.0;1,0.1;period;" .. S("Delay").. ";${period}]" .. "field[2.0,2.0;1,0.1;period;" .. S("Delay").. ";${period}]" ..
"tooltip[period;" .. S("Number of seconds to wait between each cycle").. "]" .. "tooltip[period;" .. S("Number of seconds to wait between each cycle").. "]" ..
"list[current_name;stop;3.0,0.7;1,1;]" .. "list[current_name;stop;3.0,0.7;1,1;]" ..
@ -233,7 +236,7 @@ minetest.register_node("digtron:auto_controller", {
inv:set_size("stop", 1) inv:set_size("stop", 1)
end, end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player) allow_metadata_inventory_put = function(pos, listname, index, stack)
if minetest.get_item_group(stack:get_name(), "digtron") ~= 0 then if minetest.get_item_group(stack:get_name(), "digtron") ~= 0 then
return 0 -- pointless setting a Digtron node as a stop block return 0 -- pointless setting a Digtron node as a stop block
end end
@ -243,14 +246,14 @@ minetest.register_node("digtron:auto_controller", {
return 0 return 0
end, end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player) allow_metadata_inventory_take = function(pos, listname, index)
node_inventory_table.pos = pos node_inventory_table.pos = pos
local inv = minetest.get_inventory(node_inventory_table) local inv = minetest.get_inventory(node_inventory_table)
inv:set_stack(listname, index, ItemStack("")) inv:set_stack(listname, index, ItemStack(""))
return 0 return 0
end, end,
on_receive_fields = function(pos, formname, fields, sender) on_receive_fields = function(pos, _, fields, sender)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local offset = tonumber(fields.offset) local offset = tonumber(fields.offset)
local period = tonumber(fields.period) local period = tonumber(fields.period)
@ -306,7 +309,7 @@ minetest.register_node("digtron:auto_controller", {
end end
end, end,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) on_rightclick = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("infotext", meta:get_string("infotext") .. "\n" .. S("Interrupted!")) meta:set_string("infotext", meta:get_string("infotext") .. "\n" .. S("Interrupted!"))
meta:set_string("waiting", "true") meta:set_string("waiting", "true")
@ -345,14 +348,14 @@ minetest.register_node("digtron:pusher", {
fixed = controller_nodebox, fixed = controller_nodebox,
}, },
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) on_rightclick = function(pos, _, clicker)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
if meta:get_string("waiting") == "true" then if meta:get_string("waiting") == "true" then
-- Been too soon since last time the digtron did a cycle. -- Been too soon since last time the digtron did a cycle.
return return
end end
local newpos, status_text, return_code = digtron.execute_move_cycle(pos, clicker) local newpos, status_text = digtron.execute_move_cycle(pos, clicker)
meta = minetest.get_meta(newpos) meta = minetest.get_meta(newpos)
meta:set_string("infotext", status_text) meta:set_string("infotext", status_text)
@ -361,7 +364,7 @@ minetest.register_node("digtron:pusher", {
minetest.get_node_timer(newpos):start(digtron.config.cycle_time) minetest.get_node_timer(newpos):start(digtron.config.cycle_time)
end, end,
on_timer = function(pos, elapsed) on_timer = function(pos)
minetest.get_meta(pos):set_string("waiting", nil) minetest.get_meta(pos):set_string("waiting", nil)
end, end,
}) })

@ -1,6 +1,6 @@
-- internationalization boilerplate -- internationalization boilerplate
local MP = minetest.get_modpath(minetest.get_current_modname()) local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP.."/intllib.lua") local S = dofile(MP.."/intllib.lua")
local modpath_awards = minetest.get_modpath("awards") local modpath_awards = minetest.get_modpath("awards")
@ -23,7 +23,7 @@ local player_permitted = function(pos, player)
end end
local store_digtron = function(pos, clicker, loaded_node_name, protected) local store_digtron = function(pos, clicker, loaded_node_name, protected)
local layout = DigtronLayout.create(pos, clicker) local layout = digtron.DigtronLayout.create(pos, clicker)
local protection_prefix = "" local protection_prefix = ""
local protection_suffix = "" local protection_suffix = ""
if protected then if protected then
@ -112,7 +112,7 @@ minetest.register_node("digtron:empty_crate", {
return player and not minetest.is_protected(pos, player:get_player_name()) return player and not minetest.is_protected(pos, player:get_player_name())
end, end,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) on_rightclick = function(pos, _, clicker)
store_digtron(pos, clicker, "digtron:loaded_crate") store_digtron(pos, clicker, "digtron:loaded_crate")
end end
}) })
@ -147,7 +147,7 @@ minetest.register_node("digtron:empty_locked_crate", {
can_dig = function(pos,player) can_dig = function(pos,player)
return player and not minetest.is_protected(pos, player:get_player_name()) and player_permitted(pos, player) return player and not minetest.is_protected(pos, player:get_player_name()) and player_permitted(pos, player)
end, end,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) on_rightclick = function(pos, _, clicker)
if player_permitted(pos,clicker) then if player_permitted(pos,clicker) then
store_digtron(pos, clicker, "digtron:loaded_locked_crate", true) store_digtron(pos, clicker, "digtron:loaded_locked_crate", true)
end end
@ -186,7 +186,7 @@ else
"tooltip[unpack;" .. S("Attempts to unpack the Digtron on this location") .. "]" "tooltip[unpack;" .. S("Attempts to unpack the Digtron on this location") .. "]"
end end
local loaded_formspec = function(pos, meta) local loaded_formspec = function()
return loaded_formspec_string return loaded_formspec_string
end end
@ -215,7 +215,7 @@ local loaded_on_recieve = function(pos, fields, sender, protected)
end end
local layout_string = meta:get_string("crated_layout") local layout_string = meta:get_string("crated_layout")
local layout = DigtronLayout.deserialize(layout_string) local layout = digtron.DigtronLayout.deserialize(layout_string)
if layout == nil then if layout == nil then
meta:set_string("infotext", infotext .. "\n" .. S("Unable to read layout from crate metadata, regrettably this Digtron may be corrupted.")) meta:set_string("infotext", infotext .. "\n" .. S("Unable to read layout from crate metadata, regrettably this Digtron may be corrupted."))
@ -273,7 +273,7 @@ local loaded_on_dig = function(pos, player, loaded_node_name)
stack_meta:set_string("crated_layout", meta:get_string("crated_layout")) stack_meta:set_string("crated_layout", meta:get_string("crated_layout"))
stack_meta:set_string("description", meta:get_string("title")) stack_meta:set_string("description", meta:get_string("title"))
local inv = player:get_inventory() local inv = player:get_inventory()
local stack = inv:add_item("main", stack) stack = inv:add_item("main", stack)
if stack:get_count() > 0 then if stack:get_count() > 0 then
-- prevent crash by not dropping loaded crate (see #44) -- prevent crash by not dropping loaded crate (see #44)
-- minetest.add_item(pos, stack) -- minetest.add_item(pos, stack)
@ -326,20 +326,20 @@ minetest.register_node("digtron:loaded_crate", {
meta:set_string("formspec", loaded_formspec(pos, meta)) meta:set_string("formspec", loaded_formspec(pos, meta))
end, end,
on_receive_fields = function(pos, formname, fields, sender) on_receive_fields = function(pos, _, fields, sender)
return loaded_on_recieve(pos, fields, sender) return loaded_on_recieve(pos, fields, sender)
end, end,
on_dig = function(pos, node, player) on_dig = function(pos, _, player)
if player and not minetest.is_protected(pos, player:get_player_name()) then if player and not minetest.is_protected(pos, player:get_player_name()) then
return loaded_on_dig(pos, player, "digtron:loaded_crate") return loaded_on_dig(pos, player, "digtron:loaded_crate")
end end
end, end,
after_place_node = function(pos, placer, itemstack, pointed_thing) after_place_node = function(pos, _, itemstack)
loaded_after_place(pos, itemstack) loaded_after_place(pos, itemstack)
end, end,
on_drop = function(a, b, c) end -- prevent dropping loaded digtrons, causing server to crash (see #44) on_drop = function() end -- prevent dropping loaded digtrons, causing server to crash (see #44)
}) })
minetest.register_node("digtron:loaded_locked_crate", { minetest.register_node("digtron:loaded_locked_crate", {
@ -349,17 +349,21 @@ minetest.register_node("digtron:loaded_locked_crate", {
groups = {cracky = 3, oddly_breakable_by_hand=3, not_in_creative_inventory=1, digtron_protected=1}, groups = {cracky = 3, oddly_breakable_by_hand=3, not_in_creative_inventory=1, digtron_protected=1},
stack_max = 1, stack_max = 1,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
tiles = {"digtron_plate.png^digtron_crate.png","digtron_plate.png^digtron_crate.png","digtron_plate.png^digtron_crate.png^digtron_lock.png","digtron_plate.png^digtron_crate.png^digtron_lock.png","digtron_plate.png^digtron_crate.png^digtron_lock.png","digtron_plate.png^digtron_crate.png^digtron_lock.png"}, tiles = {
"digtron_plate.png^digtron_crate.png",
"digtron_plate.png^digtron_crate.png",
"digtron_plate.png^digtron_crate.png^digtron_lock.png",
"digtron_plate.png^digtron_crate.png^digtron_lock.png",
"digtron_plate.png^digtron_crate.png^digtron_lock.png",
"digtron_plate.png^digtron_crate.png^digtron_lock.png"
},
is_ground_content = false, is_ground_content = false,
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("owner", "") meta:set_string("owner", "")
end, end,
-- can_dig = function(pos,node,player) on_dig = function(pos, _, player)
-- return player and not minetest.is_protected(pos, player:get_player_name()) and player_permitted(pos,player)
-- end,
on_dig = function(pos, node, player)
if player and not minetest.is_protected(pos, player:get_player_name()) and player_permitted(pos,player) then if player and not minetest.is_protected(pos, player:get_player_name()) and player_permitted(pos,player) then
return loaded_on_dig(pos, player, "digtron:loaded_locked_crate") return loaded_on_dig(pos, player, "digtron:loaded_locked_crate")
else else
@ -367,14 +371,14 @@ minetest.register_node("digtron:loaded_locked_crate", {
end end
end, end,
after_place_node = function(pos, placer, itemstack, pointed_thing) after_place_node = function(pos, placer, itemstack)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("owner", placer:get_player_name() or "") meta:set_string("owner", placer:get_player_name() or "")
loaded_after_place(pos, itemstack) loaded_after_place(pos, itemstack)
meta:set_string("infotext", meta:get_string("infotext") .. "\n" .. S("Owned by @1", meta:get_string("owner"))) meta:set_string("infotext", meta:get_string("infotext") .. "\n" .. S("Owned by @1", meta:get_string("owner")))
end, end,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) on_rightclick = function(pos, _, clicker)
if player_permitted(pos,clicker) then if player_permitted(pos,clicker) then
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
minetest.show_formspec( minetest.show_formspec(
@ -383,7 +387,7 @@ minetest.register_node("digtron:loaded_locked_crate", {
loaded_formspec_string:gsub("${title}", meta:get_string("title"), 1)) loaded_formspec_string:gsub("${title}", meta:get_string("title"), 1))
end end
end, end,
on_drop = function(a, b, c) end -- prevent dropping loaded digtrons, causing server to crash on_drop = function() end -- prevent dropping loaded digtrons, causing server to crash
}) })
minetest.register_on_player_receive_fields(function(player, formname, fields) minetest.register_on_player_receive_fields(function(player, formname, fields)

@ -1,6 +1,6 @@
-- internationalization boilerplate -- internationalization boilerplate
local MP = minetest.get_modpath(minetest.get_current_modname()) local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP.."/intllib.lua") local S = dofile(MP.."/intllib.lua")
-- Note: diggers go in group 3 and have an execute_dig method. -- Note: diggers go in group 3 and have an execute_dig method.
@ -36,7 +36,8 @@ local intermittent_formspec_string = default.gui_bg ..
"field[0.5,0.8;1,0.1;period;" .. S("Periodicity") .. ";${period}]" .. "field[0.5,0.8;1,0.1;period;" .. S("Periodicity") .. ";${period}]" ..
"tooltip[period;" .. S("Digger will dig once every n steps.\nThese steps are globally aligned, all diggers with\nthe same period and offset will dig on the same location.") .. "]" .. "tooltip[period;" .. S("Digger will dig once every n steps.\nThese steps are globally aligned, all diggers with\nthe same period and offset will dig on the same location.") .. "]" ..
"field[1.5,0.8;1,0.1;offset;" .. S("Offset") .. ";${offset}]" .. "field[1.5,0.8;1,0.1;offset;" .. S("Offset") .. ";${offset}]" ..
"tooltip[offset;" .. S("Offsets the start of periodicity counting by this amount.\nFor example, a digger with period 2 and offset 0 digs\nevery even-numbered block and one with period 2 and\noffset 1 digs every odd-numbered block.") .. "]" .. "tooltip[offset;" .. S("Offsets the start of periodicity counting by this amount.\nFor example, a digger with period 2 and offset 0 digs\nevery even-numbered block and one with period 2 and\n" ..
"offset 1 digs every odd-numbered block.") .. "]" ..
"button_exit[2.2,0.5;1,0.1;set;" .. S("Save &\nShow") .. "]" .. "button_exit[2.2,0.5;1,0.1;set;" .. S("Save &\nShow") .. "]" ..
"tooltip[set;" .. S("Saves settings") .. "]" "tooltip[set;" .. S("Saves settings") .. "]"
@ -48,7 +49,7 @@ if modpath_doc then
intermittent_formspec_string = "size[3.5,1]" .. intermittent_formspec_string intermittent_formspec_string = "size[3.5,1]" .. intermittent_formspec_string
end end
local intermittent_formspec = function(pos, meta) local intermittent_formspec = function(_, meta)
return intermittent_formspec_string return intermittent_formspec_string
:gsub("${period}", meta:get_int("period"), 1) :gsub("${period}", meta:get_int("period"), 1)
:gsub("${offset}", meta:get_int("offset"), 1) :gsub("${offset}", meta:get_int("offset"), 1)
@ -60,7 +61,7 @@ local intermittent_on_construct = function(pos)
meta:set_int("offset", 0) meta:set_int("offset", 0)
end end
local intermittent_on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) local intermittent_on_rightclick = function(pos, _, clicker, itemstack, pointed_thing)
local item_def = itemstack:get_definition() local item_def = itemstack:get_definition()
if item_def.type == "node" and minetest.get_item_group(itemstack:get_name(), "digtron") > 0 then if item_def.type == "node" and minetest.get_item_group(itemstack:get_name(), "digtron") > 0 then
local returnstack, success = minetest.item_place_node(itemstack, clicker, pointed_thing) local returnstack, success = minetest.item_place_node(itemstack, clicker, pointed_thing)
@ -137,7 +138,7 @@ minetest.register_node("digtron:digger", {
}, },
-- returns fuel_cost, item_produced -- returns fuel_cost, item_produced
execute_dig = function(pos, protected_nodes, nodes_dug, controlling_coordinate, lateral_dig, player) execute_dig = function(pos, protected_nodes, nodes_dug, _, _, player)
local facing = minetest.get_node(pos).param2 local facing = minetest.get_node(pos).param2
local digpos = digtron.find_new_pos(pos, facing) local digpos = digtron.find_new_pos(pos, facing)
@ -148,7 +149,7 @@ minetest.register_node("digtron:digger", {
return digtron.mark_diggable(digpos, nodes_dug, player) return digtron.mark_diggable(digpos, nodes_dug, player)
end, end,
damage_creatures = function(player, pos, controlling_coordinate, items_dropped) damage_creatures = function(player, pos, _, items_dropped)
local facing = minetest.get_node(pos).param2 local facing = minetest.get_node(pos).param2
digtron.damage_creatures(player, pos, digtron.find_new_pos(pos, facing), damage_hp, items_dropped) digtron.damage_creatures(player, pos, digtron.find_new_pos(pos, facing), damage_hp, items_dropped)
end, end,
@ -261,7 +262,7 @@ minetest.register_node("digtron:soft_digger", {
"digtron_plate.png^digtron_motor.png^[colorize:" .. digtron.soft_digger_colorize, "digtron_plate.png^digtron_motor.png^[colorize:" .. digtron.soft_digger_colorize,
}, },
execute_dig = function(pos, protected_nodes, nodes_dug, controlling_coordinate, lateral_dig, player) execute_dig = function(pos, protected_nodes, nodes_dug, _, _, player)
local facing = minetest.get_node(pos).param2 local facing = minetest.get_node(pos).param2
local digpos = digtron.find_new_pos(pos, facing) local digpos = digtron.find_new_pos(pos, facing)
@ -276,7 +277,7 @@ minetest.register_node("digtron:soft_digger", {
return 0 return 0
end, end,
damage_creatures = function(player, pos, controlling_coordinate, items_dropped) damage_creatures = function(player, pos, _, items_dropped)
local facing = minetest.get_node(pos).param2 local facing = minetest.get_node(pos).param2
digtron.damage_creatures(player, pos, digtron.find_new_pos(pos, facing), damage_hp_half, items_dropped) digtron.damage_creatures(player, pos, digtron.find_new_pos(pos, facing), damage_hp_half, items_dropped)
end, end,
@ -400,7 +401,7 @@ minetest.register_node("digtron:dual_digger", {
}, },
-- returns fuel_cost, items_produced -- returns fuel_cost, items_produced
execute_dig = function(pos, protected_nodes, nodes_dug, controlling_coordinate, lateral_dig, player) execute_dig = function(pos, protected_nodes, nodes_dug, _, _, player)
local facing = minetest.get_node(pos).param2 local facing = minetest.get_node(pos).param2
local digpos = digtron.find_new_pos(pos, facing) local digpos = digtron.find_new_pos(pos, facing)
local digdown = digtron.find_new_pos_downward(pos, facing) local digdown = digtron.find_new_pos_downward(pos, facing)
@ -430,7 +431,7 @@ minetest.register_node("digtron:dual_digger", {
return cost, items return cost, items
end, end,
damage_creatures = function(player, pos, controlling_coordinate, items_dropped) damage_creatures = function(player, pos, _, items_dropped)
local facing = minetest.get_node(pos).param2 local facing = minetest.get_node(pos).param2
digtron.damage_creatures(player, pos, digtron.find_new_pos(pos, facing), damage_hp, items_dropped) digtron.damage_creatures(player, pos, digtron.find_new_pos(pos, facing), damage_hp, items_dropped)
digtron.damage_creatures(player, pos, digtron.find_new_pos_downward(pos, facing), damage_hp, items_dropped) digtron.damage_creatures(player, pos, digtron.find_new_pos_downward(pos, facing), damage_hp, items_dropped)
@ -482,7 +483,7 @@ minetest.register_node("digtron:dual_soft_digger", {
}, },
-- returns fuel_cost, items_produced -- returns fuel_cost, items_produced
execute_dig = function(pos, protected_nodes, nodes_dug, controlling_coordinate, lateral_dig, player) execute_dig = function(pos, protected_nodes, nodes_dug, _, _, player)
local facing = minetest.get_node(pos).param2 local facing = minetest.get_node(pos).param2
local digpos = digtron.find_new_pos(pos, facing) local digpos = digtron.find_new_pos(pos, facing)
local digdown = digtron.find_new_pos_downward(pos, facing) local digdown = digtron.find_new_pos_downward(pos, facing)
@ -512,7 +513,7 @@ minetest.register_node("digtron:dual_soft_digger", {
return cost, items return cost, items
end, end,
damage_creatures = function(player, pos, controlling_coordinate, items_dropped) damage_creatures = function(player, pos, _, items_dropped)
local facing = minetest.get_node(pos).param2 local facing = minetest.get_node(pos).param2
digtron.damage_creatures(player, pos, digtron.find_new_pos(pos, facing), damage_hp_half, items_dropped) digtron.damage_creatures(player, pos, digtron.find_new_pos(pos, facing), damage_hp_half, items_dropped)
digtron.damage_creatures(player, pos, digtron.find_new_pos_downward(pos, facing), damage_hp_half, items_dropped) digtron.damage_creatures(player, pos, digtron.find_new_pos_downward(pos, facing), damage_hp_half, items_dropped)

@ -1,6 +1,6 @@
-- internationalization boilerplate -- internationalization boilerplate
local MP = minetest.get_modpath(minetest.get_current_modname()) local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP.."/intllib.lua") local S = dofile(MP.."/intllib.lua")
local inventory_formspec_string = local inventory_formspec_string =
"size[9,9.3]" .. "size[9,9.3]" ..
@ -29,7 +29,8 @@ minetest.register_node("digtron:duplicator", {
_doc_items_usagehelp = digtron.doc.duplicator_usagehelp, _doc_items_usagehelp = digtron.doc.duplicator_usagehelp,
groups = {cracky = 3, oddly_breakable_by_hand=3}, groups = {cracky = 3, oddly_breakable_by_hand=3},
sounds = digtron.metal_sounds, sounds = digtron.metal_sounds,
tiles = {"digtron_plate.png^(digtron_axel_side.png^[transformR90)", tiles = {
"digtron_plate.png^(digtron_axel_side.png^[transformR90)",
"digtron_plate.png^(digtron_axel_side.png^[transformR270)", "digtron_plate.png^(digtron_axel_side.png^[transformR270)",
"digtron_plate.png^digtron_axel_side.png", "digtron_plate.png^digtron_axel_side.png",
"digtron_plate.png^(digtron_axel_side.png^[transformR180)", "digtron_plate.png^(digtron_axel_side.png^[transformR180)",
@ -68,13 +69,13 @@ minetest.register_node("digtron:duplicator", {
inv:set_size("main", 8*4) inv:set_size("main", 8*4)
end, end,
can_dig = function(pos,player) can_dig = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
return inv:is_empty("main") return inv:is_empty("main")
end, end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player) allow_metadata_inventory_put = function(_, _, _, stack)
if minetest.get_item_group(stack:get_name(), "digtron") > 0 then if minetest.get_item_group(stack:get_name(), "digtron") > 0 then
return stack:get_count() return stack:get_count()
else else
@ -82,7 +83,7 @@ minetest.register_node("digtron:duplicator", {
end end
end, end,
on_receive_fields = function(pos, formname, fields, sender) on_receive_fields = function(pos, _, fields, sender)
local player_name = sender:get_player_name() local player_name = sender:get_player_name()
if fields.help then if fields.help then
minetest.after(0.5, doc.show_entry, player_name, "nodes", "digtron:duplicator", true) minetest.after(0.5, doc.show_entry, player_name, "nodes", "digtron:duplicator", true)
@ -113,7 +114,7 @@ minetest.register_node("digtron:duplicator", {
return return
end end
local layout = DigtronLayout.create(pos, sender) local layout = digtron.DigtronLayout.create(pos, sender)
if layout.contains_protected_node then if layout.contains_protected_node then
minetest.sound_play("buzzer", {gain=0.5, pos=pos}) minetest.sound_play("buzzer", {gain=0.5, pos=pos})

@ -1,6 +1,6 @@
-- internationalization boilerplate -- internationalization boilerplate
local MP = minetest.get_modpath(minetest.get_current_modname()) local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP.."/intllib.lua") local S = dofile(MP.."/intllib.lua")
--Build up the formspec, somewhat complicated due to multiple mod options --Build up the formspec, somewhat complicated due to multiple mod options
local pipeworks_path = minetest.get_modpath("pipeworks") local pipeworks_path = minetest.get_modpath("pipeworks")
@ -19,9 +19,9 @@ if doc_path then
formspec_width = formspec_width + 1.5 formspec_width = formspec_width + 1.5
end end
local ejector_formspec_string = "size[".. formspec_width .. ",1]" .. ejector_formspec_string ejector_formspec_string = "size[".. formspec_width .. ",1]" .. ejector_formspec_string
local ejector_formspec = function(pos, meta) local ejector_formspec = function(_, meta)
local return_string = ejector_formspec_string local return_string = ejector_formspec_string
if pipeworks_path then if pipeworks_path then
return_string = return_string .. "checkbox[0,0.5;nonpipe;"..S("Eject into world")..";"..meta:get_string("nonpipe").."]" .. return_string = return_string .. "checkbox[0,0.5;nonpipe;"..S("Eject into world")..";"..meta:get_string("nonpipe").."]" ..
@ -55,7 +55,7 @@ local function eject_items(pos, node, player, eject_even_without_pipeworks, layo
end end
if layout == nil then if layout == nil then
layout = DigtronLayout.create(pos, player) layout = digtron.DigtronLayout.create(pos, player)
end end
-- Build a list of all the items that builder nodes want to use. -- Build a list of all the items that builder nodes want to use.
@ -149,7 +149,7 @@ minetest.register_node("digtron:inventory_ejector", {
eject_items(pos, node, player, meta:get_string("nonpipe") == "true", layout) eject_items(pos, node, player, meta:get_string("nonpipe") == "true", layout)
end, end,
on_receive_fields = function(pos, formname, fields, sender) on_receive_fields = function(pos, _, fields, sender)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
if fields.help and minetest.get_modpath("doc") then --check for mod in case someone disabled it after this digger was built if fields.help and minetest.get_modpath("doc") then --check for mod in case someone disabled it after this digger was built

@ -1,6 +1,6 @@
-- internationalization boilerplate -- internationalization boilerplate
local MP = minetest.get_modpath(minetest.get_current_modname()) local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP.."/intllib.lua") local S = dofile(MP.."/intllib.lua")
-- A do-nothing "structural" node, to ensure all digtron nodes that are supposed to be connected to each other can be connected to each other. -- A do-nothing "structural" node, to ensure all digtron nodes that are supposed to be connected to each other can be connected to each other.
minetest.register_node("digtron:structure", { minetest.register_node("digtron:structure", {

@ -1,6 +1,6 @@
-- internationalization boilerplate -- internationalization boilerplate
local MP = minetest.get_modpath(minetest.get_current_modname()) local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP.."/intllib.lua") local S = dofile(MP.."/intllib.lua")
local size = 3/16 local size = 3/16
@ -28,10 +28,14 @@ minetest.register_node("digtron:power_connector", {
_doc_items_longdesc = digtron.doc.power_connector_longdesc, _doc_items_longdesc = digtron.doc.power_connector_longdesc,
_doc_items_usagehelp = digtron.doc.power_connector_usagehelp, _doc_items_usagehelp = digtron.doc.power_connector_usagehelp,
groups = connector_groups, groups = connector_groups,
tiles = {"digtron_plate.png^digtron_power_connector_top.png^digtron_digger_yb_frame.png", "digtron_plate.png^digtron_digger_yb_frame.png", tiles = {
"digtron_plate.png^digtron_digger_yb_frame.png^digtron_power_connector_side.png", "digtron_plate.png^digtron_digger_yb_frame.png^digtron_power_connector_side.png", "digtron_plate.png^digtron_power_connector_top.png^digtron_digger_yb_frame.png",
"digtron_plate.png^digtron_digger_yb_frame.png^digtron_power_connector_side.png", "digtron_plate.png^digtron_digger_yb_frame.png^digtron_power_connector_side.png", "digtron_plate.png^digtron_digger_yb_frame.png",
}, "digtron_plate.png^digtron_digger_yb_frame.png^digtron_power_connector_side.png",
"digtron_plate.png^digtron_digger_yb_frame.png^digtron_power_connector_side.png",
"digtron_plate.png^digtron_digger_yb_frame.png^digtron_power_connector_side.png",
"digtron_plate.png^digtron_digger_yb_frame.png^digtron_power_connector_side.png",
},
connect_sides = {"bottom", "top", "left", "right", "front", "back"}, connect_sides = {"bottom", "top", "left", "right", "front", "back"},
drawtype = "nodebox", drawtype = "nodebox",
sounds = digtron.metal_sounds, sounds = digtron.metal_sounds,
@ -59,15 +63,15 @@ minetest.register_node("digtron:power_connector", {
meta:set_string("formspec", get_formspec_string(0,0)) meta:set_string("formspec", get_formspec_string(0,0))
end, end,
technic_run = function(pos, node) technic_run = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local eu_input = meta:get_int("HV_EU_input") local eu_input = meta:get_int("HV_EU_input")
local demand = meta:get_int("HV_EU_demand") local demand = meta:get_int("HV_EU_demand")
meta:set_string("infotext", S("Digtron Power @1/@2", eu_input, demand)) meta:set_string("infotext", S("Digtron Power @1/@2", eu_input, demand))
end, end,
on_receive_fields = function(pos, formname, fields, sender) on_receive_fields = function(pos, _, fields, sender)
local layout = DigtronLayout.create(pos, sender) local layout = digtron.DigtronLayout.create(pos, sender)
local max_cost = 0 local max_cost = 0
if layout.builders ~= nil then if layout.builders ~= nil then
for _, node_image in pairs(layout.builders) do for _, node_image in pairs(layout.builders) do
@ -75,7 +79,7 @@ minetest.register_node("digtron:power_connector", {
end end
end end
if layout.diggers ~= nil then if layout.diggers ~= nil then
for _, node_image in pairs(layout.diggers) do for _ in pairs(layout.diggers) do
max_cost = max_cost + max_dig_cost max_cost = max_cost + max_dig_cost
end end
end end
@ -87,7 +91,7 @@ minetest.register_node("digtron:power_connector", {
meta:set_int("HV_EU_demand", current_max) meta:set_int("HV_EU_demand", current_max)
elseif fields.value ~= nil then elseif fields.value ~= nil then
local number = tonumber(fields.value) or 0 local number = tonumber(fields.value) or 0
local number = math.min(math.max(number, 0), current_max) number = math.min(math.max(number, 0), current_max)
meta:set_int("HV_EU_demand", number) meta:set_int("HV_EU_demand", number)
end end

@ -1,6 +1,6 @@
-- internationalization boilerplate -- internationalization boilerplate
local MP = minetest.get_modpath(minetest.get_current_modname()) local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP.."/intllib.lua") local S = dofile(MP.."/intllib.lua")
local pipeworks_path = minetest.get_modpath("pipeworks") local pipeworks_path = minetest.get_modpath("pipeworks")
@ -17,7 +17,7 @@ local inventory_formspec_string =
"listring[current_player;main]" .. "listring[current_player;main]" ..
default.get_hotbar_bg(0,5.15) default.get_hotbar_bg(0,5.15)
local inventory_formspec = function(pos, meta) local inventory_formspec = function()
return inventory_formspec_string return inventory_formspec_string
end end
@ -57,7 +57,7 @@ minetest.register_node("digtron:inventory", {
inv:set_size("main", 8*4) inv:set_size("main", 8*4)
end, end,
can_dig = function(pos,player) can_dig = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
return inv:is_empty("main") return inv:is_empty("main")
@ -67,12 +67,12 @@ minetest.register_node("digtron:inventory", {
---------------------------------------------------------------- ----------------------------------------------------------------
tube = (function() if pipeworks_path then return { tube = (function() if pipeworks_path then return {
insert_object = function(pos, node, stack, direction) insert_object = function(pos, _, stack)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
return inv:add_item("main", stack) return inv:add_item("main", stack)
end, end,
can_insert = function(pos, node, stack, direction) can_insert = function(pos, _, stack)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
return inv:room_for_item("main", stack) return inv:room_for_item("main", stack)
@ -98,7 +98,7 @@ local fuelstore_formspec_string =
"listring[current_player;main]" .. "listring[current_player;main]" ..
default.get_hotbar_bg(0,5.15) default.get_hotbar_bg(0,5.15)
local fuelstore_formspec = function(pos, meta) local fuelstore_formspec = function()
return fuelstore_formspec_string return fuelstore_formspec_string
end end
@ -139,7 +139,7 @@ minetest.register_node("digtron:fuelstore", {
end, end,
-- Only allow fuel items to be placed in fuel -- Only allow fuel items to be placed in fuel
allow_metadata_inventory_put = function(pos, listname, index, stack, player) allow_metadata_inventory_put = function(_, listname, _, stack)
if listname == "fuel" then if listname == "fuel" then
if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then
return stack:get_count() return stack:get_count()
@ -150,7 +150,7 @@ minetest.register_node("digtron:fuelstore", {
return 0 return 0
end, end,
can_dig = function(pos,player) can_dig = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
return inv:is_empty("fuel") return inv:is_empty("fuel")
@ -160,7 +160,7 @@ minetest.register_node("digtron:fuelstore", {
---------------------------------------------------------------- ----------------------------------------------------------------
tube = (function() if pipeworks_path then return { tube = (function() if pipeworks_path then return {
insert_object = function(pos, node, stack, direction) insert_object = function(pos, _, stack)
if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
@ -168,7 +168,7 @@ minetest.register_node("digtron:fuelstore", {
end end
return stack return stack
end, end,
can_insert = function(pos, node, stack, direction) can_insert = function(pos, _, stack)
if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
@ -199,7 +199,7 @@ local combined_storage_formspec_string =
"listring[current_player;main]" .. "listring[current_player;main]" ..
default.get_hotbar_bg(0,5.75) default.get_hotbar_bg(0,5.75)
local combined_storage_formspec = function(pos, meta) local combined_storage_formspec = function()
return combined_storage_formspec_string return combined_storage_formspec_string
end end
@ -224,7 +224,8 @@ minetest.register_node("digtron:combined_storage", {
is_ground_content = false, is_ground_content = false,
tiles = { tiles = {
"digtron_plate.png^digtron_crossbrace.png^digtron_flammable_small.png^[transformR180^digtron_flammable_small.png", "digtron_plate.png^digtron_crossbrace.png^digtron_flammable_small.png^[transformR180^digtron_flammable_small.png",
"digtron_plate.png^digtron_crossbrace.png^digtron_flammable_small.png^[transformR180^digtron_flammable_small.png", "digtron_plate.png^digtron_crossbrace.png^digtron_flammable_small.png^digtron_storage.png", "digtron_plate.png^digtron_crossbrace.png^digtron_flammable_small.png^[transformR180^digtron_flammable_small.png",
"digtron_plate.png^digtron_crossbrace.png^digtron_flammable_small.png^digtron_storage.png",
"digtron_plate.png^digtron_crossbrace.png^digtron_flammable_small.png^digtron_storage.png", "digtron_plate.png^digtron_crossbrace.png^digtron_flammable_small.png^digtron_storage.png",
"digtron_plate.png^digtron_crossbrace.png^digtron_flammable_small.png^digtron_storage.png", "digtron_plate.png^digtron_crossbrace.png^digtron_flammable_small.png^digtron_storage.png",
"digtron_plate.png^digtron_crossbrace.png^digtron_flammable_small.png^digtron_storage.png", "digtron_plate.png^digtron_crossbrace.png^digtron_flammable_small.png^digtron_storage.png",
@ -238,7 +239,7 @@ minetest.register_node("digtron:combined_storage", {
end, end,
-- Only allow fuel items to be placed in fuel -- Only allow fuel items to be placed in fuel
allow_metadata_inventory_put = function(pos, listname, index, stack, player) allow_metadata_inventory_put = function(_, listname, _, stack)
if listname == "fuel" then if listname == "fuel" then
if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then
return stack:get_count() return stack:get_count()
@ -249,7 +250,7 @@ minetest.register_node("digtron:combined_storage", {
return stack:get_count() -- otherwise, allow all drops return stack:get_count() -- otherwise, allow all drops
end, end,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, _, count)
if to_list == "main" then if to_list == "main" then
return count return count
end end
@ -263,7 +264,7 @@ minetest.register_node("digtron:combined_storage", {
return 0 return 0
end, end,
can_dig = function(pos,player) can_dig = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
return inv:is_empty("fuel") and inv:is_empty("main") return inv:is_empty("fuel") and inv:is_empty("main")
@ -272,7 +273,7 @@ minetest.register_node("digtron:combined_storage", {
-- Pipeworks compatibility -- Pipeworks compatibility
---------------------------------------------------------------- ----------------------------------------------------------------
tube = (function() if pipeworks_path then return { tube = (function() if pipeworks_path then return {
insert_object = function(pos, node, stack, direction) insert_object = function(pos, _, stack, direction)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 and direction.y == 1 then if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 and direction.y == 1 then
@ -280,7 +281,7 @@ minetest.register_node("digtron:combined_storage", {
end end
return inv:add_item("main", stack) return inv:add_item("main", stack)
end, end,
can_insert = function(pos, node, stack, direction) can_insert = function(pos, _, stack, direction)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 and direction.y == 1 then if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 and direction.y == 1 then

@ -1,6 +1,6 @@
-- internationalization boilerplate -- internationalization boilerplate
local MP = minetest.get_modpath(minetest.get_current_modname()) local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP.."/intllib.lua") local S = dofile(MP.."/intllib.lua")
minetest.register_craftitem("digtron:digtron_core", { minetest.register_craftitem("digtron:digtron_core", {
description = S("Digtron Core"), description = S("Digtron Core"),

@ -28,7 +28,7 @@ minetest.register_lbm({
minetest.register_lbm({ minetest.register_lbm({
name = "digtron:fuelstore_upgrade", name = "digtron:fuelstore_upgrade",
nodenames = {"digtron:fuelstore"}, nodenames = {"digtron:fuelstore"},
action = function(pos, node) action = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
local list = inv:get_list("main") local list = inv:get_list("main")
@ -40,7 +40,7 @@ minetest.register_lbm({
minetest.register_lbm({ minetest.register_lbm({
name = "digtron:autocontroller_lateral_upgrade", name = "digtron:autocontroller_lateral_upgrade",
nodenames = {"digtron:auto_controller"}, nodenames = {"digtron:auto_controller"},
action = function(pos, node) action = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local cycles = meta:get_int("offset") local cycles = meta:get_int("offset")
meta:set_int("cycles", cycles) meta:set_int("cycles", cycles)
@ -52,7 +52,7 @@ minetest.register_lbm({
minetest.register_lbm({ minetest.register_lbm({
name = "digtron:builder_extrusion_upgrade", name = "digtron:builder_extrusion_upgrade",
nodenames = {"digtron:builder"}, nodenames = {"digtron:builder"},
action = function(pos, node) action = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_int("extrusion", 1) meta:set_int("extrusion", 1)
end end

@ -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
@ -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
@ -195,7 +195,7 @@ digtron.burn = function(fuelstore_positions, target, test)
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
@ -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 -- 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
@ -250,7 +250,7 @@ digtron.tap_batteries = function(battery_positions, target, test)
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,7 +265,6 @@ 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
@ -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
@ -413,11 +412,11 @@ digtron.show_offset_markers = function(pos, offset, period)
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

@ -1,6 +1,6 @@
-- internationalization boilerplate -- internationalization boilerplate
local MP = minetest.get_modpath(minetest.get_current_modname()) local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP.."/intllib.lua") local S = dofile(MP.."/intllib.lua")
local dig_dust = function(pos, facing) local dig_dust = function(pos, facing)
local direction = minetest.facedir_to_dir(facing) local direction = minetest.facedir_to_dir(facing)
@ -117,11 +117,11 @@ digtron.execute_dig_cycle = function(pos, clicker)
local dir = minetest.facedir_to_dir(facing) local dir = minetest.facedir_to_dir(facing)
local fuel_burning = meta:get_float("fuel_burning") -- get amount of burned fuel left over from last cycle local fuel_burning = meta:get_float("fuel_burning") -- get amount of burned fuel left over from last cycle
local status_text = S("Heat remaining in controller furnace: @1", math.floor(math.max(0, fuel_burning))) local status_text = S("Heat remaining in controller furnace: @1", math.floor(math.max(0, fuel_burning)))
local exhaust = meta:get_int("on_coal")
local layout = DigtronLayout.create(pos, clicker) local layout = digtron.DigtronLayout.create(pos, clicker)
local status_text, return_code = neighbour_test(layout, status_text, dir) local return_code
status_text, return_code = neighbour_test(layout, status_text, dir)
if return_code ~= 0 then if return_code ~= 0 then
return pos, status_text, return_code return pos, status_text, return_code
end end
@ -144,7 +144,7 @@ digtron.execute_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
@ -196,20 +196,20 @@ digtron.execute_dig_cycle = function(pos, clicker)
-- need from inventory, and then we put it all back afterward. -- need from inventory, and then we put it all back afterward.
-- Note that this test may overestimate the amount of work that will actually need to be done so don't treat its fuel cost as authoritative. -- Note that this test may overestimate the amount of work that will actually need to be done so don't treat its fuel cost as authoritative.
local can_build = true local can_build = true
local test_build_return_code = nil
local test_build_return_items = nil
local failed_to_find = nil
local test_items = {} local test_items = {}
local test_fuel_items = {}
local test_build_fuel_cost = 0 local test_build_fuel_cost = 0
local test_build_return_code, test_build_return_items, failed_to_find
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]
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, failed_to_find = targetdef.test_build(location.pos, test_location, layout.inventories, layout.protected, layout.nodes_dug, controlling_coordinate, layout.controller) test_build_return_code, test_build_return_items, failed_to_find = targetdef.test_build(
for k, return_item in pairs(test_build_return_items) do 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
table.insert(test_items, return_item) table.insert(test_items, return_item)
test_build_fuel_cost = test_build_fuel_cost + digtron.config.build_cost test_build_fuel_cost = test_build_fuel_cost + digtron.config.build_cost
end end
@ -259,6 +259,7 @@ digtron.execute_dig_cycle = function(pos, clicker)
fuel_burning = 0 fuel_burning = 0
end end
local exhaust
if (test_fuel_needed < test_fuel_burned) then if (test_fuel_needed < test_fuel_burned) then
exhaust = 0 -- all power needs met by electricity, don't blow smoke exhaust = 0 -- all power needs met by electricity, don't blow smoke
else else
@ -268,7 +269,7 @@ digtron.execute_dig_cycle = function(pos, clicker)
end end
--Put everything back where it came from --Put everything back where it came from
for k, item_return in pairs(test_items) do for _, item_return in pairs(test_items) do
digtron.place_in_specific_inventory(item_return.item, item_return.location, layout.inventories, layout.controller) digtron.place_in_specific_inventory(item_return.item, item_return.location, layout.inventories, layout.controller)
end end
@ -281,7 +282,7 @@ digtron.execute_dig_cycle = function(pos, clicker)
minetest.get_meta(pos):set_string("waiting", "true") minetest.get_meta(pos):set_string("waiting", "true")
minetest.get_node_timer(pos):start(digtron.config.cycle_time) minetest.get_node_timer(pos):start(digtron.config.cycle_time)
local return_string = nil local return_string = nil
local return_code = 5 return_code = 5
if test_build_return_code == 3 then if test_build_return_code == 3 then
minetest.sound_play("honk", {gain=0.5, pos=pos}) -- A builder is not configured minetest.sound_play("honk", {gain=0.5, pos=pos}) -- A builder is not configured
return_string = S("Digtron connected to at least one builder with no output material assigned.") .. "\n" return_string = S("Digtron connected to at least one builder with no output material assigned.") .. "\n"
@ -304,7 +305,7 @@ digtron.execute_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
@ -335,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
@ -346,7 +347,6 @@ digtron.execute_dig_cycle = function(pos, clicker)
-- So this should never happen. However, "should never happens" happen sometimes. So -- So this should never happen. However, "should never happens" happen sometimes. So
-- don't interrupt the build cycle as a whole, we've already moved so might as well try to complete as much as possible. -- don't interrupt the build cycle as a whole, we've already moved so might as well try to complete as much as possible.
strange_failure = true strange_failure = true
build_return = (build_return * -1) - 1
elseif digtron.config.uses_resources then elseif digtron.config.uses_resources then
building_fuel_cost = building_fuel_cost + (digtron.config.build_cost * build_return) building_fuel_cost = building_fuel_cost + (digtron.config.build_cost * build_return)
end end
@ -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
@ -368,7 +368,7 @@ digtron.execute_dig_cycle = function(pos, clicker)
end end
end end
local status_text = "" status_text = ""
if strange_failure then if strange_failure then
-- We weren't able to detect this build failure ahead of time, so make a big noise now. This is strange, shouldn't happen. -- We weren't able to detect this build failure ahead of time, so make a big noise now. This is strange, shouldn't happen.
minetest.sound_play("dingding", {gain=1.0, pos=pos}) minetest.sound_play("dingding", {gain=1.0, pos=pos})
@ -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
@ -420,11 +422,11 @@ end
-- Simplified version of the above method that only moves, and doesn't execute diggers or builders. -- Simplified version of the above method that only moves, and doesn't execute diggers or builders.
digtron.execute_move_cycle = function(pos, clicker) digtron.execute_move_cycle = function(pos, clicker)
local meta = minetest.get_meta(pos) local layout = digtron.DigtronLayout.create(pos, clicker)
local layout = DigtronLayout.create(pos, clicker)
local status_text = "" local status_text = ""
local status_text, return_code = neighbour_test(layout, status_text, nil) -- skip traction check for pusher by passing nil for direction local return_code
status_text, return_code = neighbour_test(layout, status_text, nil) -- skip traction check for pusher by passing nil for direction
if return_code ~= 0 then if return_code ~= 0 then
return pos, status_text, return_code return pos, status_text, return_code
end end
@ -436,7 +438,6 @@ digtron.execute_move_cycle = function(pos, clicker)
local facing = minetest.get_node(pos).param2 local facing = minetest.get_node(pos).param2
local dir = minetest.facedir_to_dir(facing) local dir = minetest.facedir_to_dir(facing)
local controlling_coordinate = digtron.get_controlling_coordinate(pos, facing)
-- if the player is standing within the array or next to it, move him too. -- if the player is standing within the array or next to it, move him too.
local move_player = move_player_test(layout, clicker) local move_player = move_player_test(layout, clicker)
@ -480,11 +481,12 @@ digtron.execute_downward_dig_cycle = function(pos, clicker)
local dir = digtron.facedir_to_down_dir(facing) local dir = digtron.facedir_to_down_dir(facing)
local fuel_burning = meta:get_float("fuel_burning") -- get amount of burned fuel left over from last cycle local fuel_burning = meta:get_float("fuel_burning") -- get amount of burned fuel left over from last cycle
local status_text = S("Heat remaining in controller furnace: @1", math.floor(math.max(0, fuel_burning))) local status_text = S("Heat remaining in controller furnace: @1", math.floor(math.max(0, fuel_burning)))
local return_code
local exhaust = meta:get_int("on_coal") local exhaust = meta:get_int("on_coal")
local layout = DigtronLayout.create(pos, clicker) local layout = digtron.DigtronLayout.create(pos, clicker)
local status_text, return_code = neighbour_test(layout, status_text, dir) status_text, return_code = neighbour_test(layout, status_text, dir)
if return_code ~= 0 then if return_code ~= 0 then
return pos, status_text, return_code return pos, status_text, return_code
end end
@ -494,7 +496,6 @@ digtron.execute_downward_dig_cycle = function(pos, clicker)
return pos, size_check_error, 8 return pos, size_check_error, 8
end end
local controlling_coordinate = digtron.get_controlling_coordinate(pos, facing) local controlling_coordinate = digtron.get_controlling_coordinate(pos, facing)
---------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------
@ -508,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
@ -563,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
@ -590,7 +591,7 @@ digtron.execute_downward_dig_cycle = function(pos, clicker)
end end
digtron.award_item_dug(items_dropped, clicker) -- Achievements mod hook digtron.award_item_dug(items_dropped, clicker) -- Achievements mod hook
local status_text = "" status_text = ""
-- actually burn the fuel needed -- actually burn the fuel needed
fuel_burning = fuel_burning - digging_fuel_cost fuel_burning = fuel_burning - digging_fuel_cost
@ -620,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()

@ -162,7 +162,6 @@ digtron.item_place_node = function(itemstack, placer, place_to, param2)
-- Note that fake_player:update is called in the DigtronLayout class's "create" function, -- Note that fake_player:update is called in the DigtronLayout class's "create" function,
-- which is called before Digtron does any of this building stuff, so it's not necessary -- which is called before Digtron does any of this building stuff, so it's not necessary
-- to update it here. -- to update it here.
local _, callback
for _, callback in ipairs(minetest.registered_on_placenodes) do for _, callback in ipairs(minetest.registered_on_placenodes) do
-- Deepcopy pos, node and pointed_thing because callback can modify them -- Deepcopy pos, node and pointed_thing because callback can modify them
local place_to_copy = {x=place_to.x, y=place_to.y, z=place_to.z} local place_to_copy = {x=place_to.x, y=place_to.y, z=place_to.z}