From 3e1c1ca20800cfed87ee0c825661e6b579a1a6f5 Mon Sep 17 00:00:00 2001 From: Buckaroo Banzai <39065740+BuckarooBanzay@users.noreply.github.com> Date: Mon, 19 Jun 2023 07:44:40 +0200 Subject: [PATCH] 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 --- .github/workflows/luacheck.yml | 17 +++ .luacheckrc | 27 +++++ awards.lua | 16 +-- class_fakeplayer.lua | 32 +++--- class_layout.lua | 110 +++++++++---------- class_pointset.lua | 35 +++--- doc.lua | 4 +- entities.lua | 71 ++++++------ init.lua | 5 +- nodes/node_axle.lua | 16 +-- nodes/node_battery_holder.lua | 34 +++--- nodes/node_builders.lua | 194 ++++++++++++++++----------------- nodes/node_controllers.lua | 95 ++++++++-------- nodes/node_crate.lua | 100 +++++++++-------- nodes/node_diggers.lua | 101 ++++++++--------- nodes/node_duplicator.lua | 13 ++- nodes/node_item_ejector.lua | 46 ++++---- nodes/node_misc.lua | 2 +- nodes/node_power_connector.lua | 40 ++++--- nodes/node_storage.lua | 69 ++++++------ nodes/recipes.lua | 4 +- upgrades.lua | 8 +- util.lua | 55 +++++----- util_execute_cycle.lua | 161 +++++++++++++-------------- util_item_place_node.lua | 19 ++-- 25 files changed, 669 insertions(+), 605 deletions(-) create mode 100644 .github/workflows/luacheck.yml create mode 100644 .luacheckrc diff --git a/.github/workflows/luacheck.yml b/.github/workflows/luacheck.yml new file mode 100644 index 0000000..1effc90 --- /dev/null +++ b/.github/workflows/luacheck.yml @@ -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 ./ diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..d28b414 --- /dev/null +++ b/.luacheckrc @@ -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 + } +} \ No newline at end of file diff --git a/awards.lua b/awards.lua index 074fe3b..376bff5 100644 --- a/awards.lua +++ b/awards.lua @@ -1,8 +1,8 @@ if not minetest.get_modpath("awards") then - digtron.award_item_dug = function (items, name, count) end - digtron.award_layout = function (layout, name) end - digtron.award_item_built = function(item_name, name) end - digtron.award_crate = function (layout, name) end + digtron.award_item_dug = function() end + digtron.award_layout = function() end + digtron.award_item_built = function() end + digtron.award_crate = function() end return end @@ -10,14 +10,14 @@ end -- internationalization boilerplate 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", { type = "counted_key", progress = "@1/@2 excavated", 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."}, - get_key = function(self, def) + get_key = function(_, def) return minetest.registered_aliases[def.trigger.node] or def.trigger.node end, key_is_item = true, @@ -37,7 +37,7 @@ awards.register_trigger("digtron_build", { progress = "@1/@2 built", 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."}, - get_key = function(self, def) + get_key = function(_, def) return minetest.registered_aliases[def.trigger.node] or def.trigger.node end, key_is_item = true, @@ -75,7 +75,7 @@ digtron.award_layout = function(layout, player) if layout.builders ~= nil and table.getn(layout.builders) > 24 then awards.unlock(name, "digtron_builder25") end - + if layout.controller.y > 100 then awards.unlock(name, "digtron_height100") if layout.controller.y > 1000 then diff --git a/class_fakeplayer.lua b/class_fakeplayer.lua index 7976cb4..91c8d32 100644 --- a/class_fakeplayer.lua +++ b/class_fakeplayer.lua @@ -2,15 +2,15 @@ -- demand a "Player" object as a parameter and hopefully prevent the mods that have -- registered with those callbacks from crashing on a nil dereference or bad function -- call. This is not supposed to be a remotely functional thing, it's just supposed --- to provide dummy methods and return values of the correct data type for anything that +-- to provide dummy methods and return values of the correct data type for anything that -- might ignore the false "is_player()" return and go ahead and try to use this thing -- anyway. -- 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. -DigtronFakePlayer = {} -DigtronFakePlayer.__index = DigtronFakePlayer +digtron.DigtronFakePlayer = {} +digtron.DigtronFakePlayer.__index = digtron.DigtronFakePlayer local function return_value(x) return (function() return x end) @@ -32,18 +32,18 @@ local function return_empty_table() return {} end -function DigtronFakePlayer.update(self, pos, player_name) +function digtron.DigtronFakePlayer.update(self, pos, player_name) self.is_fake_player = ":digtron " .. player_name self.get_pos = return_value(pos) end -function DigtronFakePlayer.create(pos, player_name) +function digtron.DigtronFakePlayer.create(pos, player_name) local self = {} - setmetatable(self, DigtronFakePlayer) - + setmetatable(self, digtron.DigtronFakePlayer) + self.is_fake_player = ":digtron " .. player_name - -- ObjectRef + -- ObjectRef self.get_pos = return_value(pos) self.set_pos = return_nil self.move_to = return_nil @@ -87,7 +87,6 @@ function DigtronFakePlayer.create(pos, player_name) self.get_luaentity = return_nil -- Player object - self.get_player_name = return_empty_string self.get_player_velocity = return_nil self.get_look_dir = return_value({x=0,y=1,z=0}) @@ -112,13 +111,12 @@ function DigtronFakePlayer.create(pos, player_name) 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.hud_add = return_nil self.hud_remove = return_nil self.hud_change = return_nil self.hud_get = return_nil -- possibly important return value? - self.hud_set_flags = return_nil + self.hud_set_flags = return_nil self.hud_get_flags = return_value({ hotbar=true, healthbar=true, crosshair=true, wielditem=true, breathbar=true, minimap=true }) self.hud_set_hotbar_itemcount = return_nil self.hud_get_hotbar_itemcount = return_zero @@ -128,18 +126,18 @@ function DigtronFakePlayer.create(pos, player_name) self.hud_get_hotbar_selected_image = return_empty_string self.set_sky = return_nil self.get_sky = return_empty_table -- may need members on this table - + self.set_clouds = return_nil self.get_clouds = return_value({density = 0, color = "#fff0f0e5", ambient = "#000000", height = 120, thickness = 16, speed = {x=0, y=-2}}) - + self.override_day_night_ratio = return_nil self.get_day_night_ratio = return_nil - + self.set_local_animation = return_nil self.get_local_animation = return_empty_table - + self.set_eye_offset = return_nil self.get_eye_offset = return_value({x=0,y=0,z=0},{x=0,y=0,z=0}) - + return self end \ No newline at end of file diff --git a/class_layout.lua b/class_layout.lua index 1fc0749..678aed2 100644 --- a/class_layout.lua +++ b/class_layout.lua @@ -1,7 +1,5 @@ -DigtronLayout = {} -DigtronLayout.__index = DigtronLayout - -local modpath_awards = minetest.get_modpath("awards") +digtron.DigtronLayout = {} +digtron.DigtronLayout.__index = digtron.DigtronLayout ------------------------------------------------------------------------- -- Creation @@ -15,7 +13,7 @@ local get_node_image = function(pos, node) if node_image.meta ~= nil and node_def._digtron_formspec ~= nil then node_image.meta.fields.formspec = node_def._digtron_formspec(pos, meta) -- causes formspec to be automatically upgraded whenever Digtron moves end - + local group = minetest.get_item_group(node.name, "digtron") -- group 1 has no special metadata if group > 1 and group < 10 then @@ -27,7 +25,7 @@ local get_node_image = function(pos, node) .. tostring(group) .. ". This error should not be possible. Please see https://github.com/minetest/minetest/issues/8067") end end - + -- Record what kind of thing we've got in a builder node so its facing can be rotated properly if group == 4 then local build_item = "" @@ -45,25 +43,27 @@ local get_node_image = function(pos, node) end -- temporary pointsets used while searching -local to_test = Pointset.create() -local tested = Pointset.create() +local to_test = digtron.Pointset.create() +local tested = digtron.Pointset.create() -function DigtronLayout.create(pos, player) +function digtron.DigtronLayout.create(pos, player) 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 self.traction = 0 self.all = {} self.water_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.old_pos_pointset = 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.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 = digtron.Pointset.create() -- For tracking original location of nodes if we do transformations on the Digtron + 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.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_min_x = pos.x @@ -79,12 +79,12 @@ function DigtronLayout.create(pos, player) to_test:set(pos.x, pos.y - 1, pos.z, true) to_test:set(pos.x, pos.y, pos.z + 1, true) to_test:set(pos.x, pos.y, pos.z - 1, true) - + if minetest.is_protected(pos, player:get_player_name()) and not minetest.check_player_privs(player, "protection_bypass") then self.protected:set(pos.x, pos.y, pos.z, true) self.contains_protected_node = true end - + -- Do a loop on to_test positions, adding new to_test positions as we find digtron nodes. This is a flood fill operation -- that follows node faces (no diagonals) local testpos, _ = to_test:pop() @@ -96,7 +96,7 @@ function DigtronLayout.create(pos, player) --digtron array is next to unloaded nodes, too dangerous to do anything. Abort. self.ignore_touching = true end - + if minetest.get_item_group(node.name, "water") ~= 0 then self.water_touching = true elseif minetest.get_item_group(node.name, "lava") ~= 0 then @@ -111,12 +111,12 @@ function DigtronLayout.create(pos, player) self.protected:set(testpos.x, testpos.y, testpos.z, true) is_protected = true end - + local group_number = minetest.get_item_group(node.name, "digtron") if group_number > 0 then --found one. Add it to the digtrons output local node_image = get_node_image(testpos, node) - + table.insert(self.all, node_image) -- add a reference to this node's position to special node lists @@ -147,11 +147,11 @@ function DigtronLayout.create(pos, player) self.auto_ejectors = self.auto_ejectors or {} table.insert(self.auto_ejectors, node_image) end - + if is_protected then self.contains_protected_node = true end - + -- update extents self.extents_max_x = math.max(self.extents_max_x, testpos.x) self.extents_min_x = math.min(self.extents_min_x, testpos.x) @@ -159,7 +159,7 @@ function DigtronLayout.create(pos, player) self.extents_min_y = math.min(self.extents_min_y, testpos.y) self.extents_max_z = math.max(self.extents_max_z, testpos.z) self.extents_min_z = math.min(self.extents_min_z, testpos.z) - + --queue up potential new test points adjacent to this digtron node to_test:set_if_not_in(tested, testpos.x + 1, testpos.y, testpos.z, true) to_test:set_if_not_in(tested, testpos.x - 1, testpos.y, testpos.z, true) @@ -172,15 +172,15 @@ function DigtronLayout.create(pos, player) -- Allowing unknown nodes to provide traction, since they're not buildable_to either self.traction = self.traction + 1 end - + testpos, _ = to_test:pop() end - + digtron.award_layout(self, player) -- hook for achievements mod - + to_test:clear() tested:clear() - + return self end @@ -245,7 +245,7 @@ local rotate_pos = function(axis, direction, pos) pos.x = pos.z pos.z = -temp_x end - else + else if direction < 0 then local temp_x = pos.x pos.x = -pos.y @@ -280,25 +280,25 @@ local rotate_node_image = function(node_image, origin, axis, direction, old_pos_ elseif node_image.paramtype2 == "facedir" then node_image.node.param2 = facedir_rotate[axis][direction][node_image.node.param2] end - + if node_image.build_item_paramtype2 == "wallmounted" then node_image.meta.fields.build_facing = wallmounted_rotate[axis][direction][tonumber(node_image.meta.fields.build_facing)] elseif node_image.build_item_paramtype2 == "facedir" then node_image.meta.fields.build_facing = facedir_rotate[axis][direction][tonumber(node_image.meta.fields.build_facing)] end - + node_image.meta.fields.waiting = nil -- If we're rotating a controller that's in the "waiting" state, clear it. Otherwise it may stick like that. -- record the old location so we can destroy the old node if the rotation operation is possible old_pos_pointset:set(node_image.pos.x, node_image.pos.y, node_image.pos.z, true) - + -- position in space relative to origin local pos = subtract_in_place(node_image.pos, origin) pos = rotate_pos(axis, direction, pos) -- Move back to original reference frame node_image.pos = add_in_place(pos, origin) - - return node_image + + return node_image end @@ -311,7 +311,7 @@ local top = { {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) -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 -- this should not be possible, but if it is then abort. @@ -325,10 +325,10 @@ function DigtronLayout.rotate_layout_image(self, facedir) -- 12, 13, 14, 15 == (1,0,0) -- 16, 17, 18, 19 == (-1,0,0) -- 20, 21, 22, 23== (0,-1,0) - + 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) end return self @@ -337,15 +337,15 @@ end ----------------------------------------------------------------------------------------------- -- 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_min_x = self.extents_min_x + dir.x self.extents_max_y = self.extents_max_y + dir.y self.extents_min_y = self.extents_min_y + dir.y self.extents_max_z = self.extents_max_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) 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. @@ -355,8 +355,8 @@ end ----------------------------------------------------------------------------------------------- -- Writing to world -function DigtronLayout.can_write_layout_image(self) - for k, node_image in pairs(self.all) do +function digtron.DigtronLayout.can_write_layout_image(self) + for _, node_image in pairs(self.all) do --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 return false @@ -394,14 +394,14 @@ local node_callbacks = function(player) local old_pos = dug_node_pos[i] local old_node = dug_node[i] local old_meta = dug_node_meta[i] - + for _, callback in ipairs(minetest.registered_on_dignodes) do -- Copy pos and node because callback can modify them local pos_copy = {x=old_pos.x, y=old_pos.y, z=old_pos.z} local oldnode_copy = {name=old_node.name, param1=old_node.param1, param2=old_node.param2} callback(pos_copy, oldnode_copy, digtron.fake_player) end - + local old_def = minetest.registered_nodes[old_node.name] if old_def ~= nil and old_def.after_dig_node ~= nil then old_def.after_dig_node(old_pos, old_node, old_meta, player) @@ -414,7 +414,7 @@ local node_callbacks = function(player) local new_pos = placed_node_pos[i] local new_node = placed_new_node[i] local old_node = placed_old_node[i] - + for _, callback in ipairs(minetest.registered_on_placenodes) do -- Copy pos and node because callback can modify them local pos_copy = {x=new_pos.x, y=new_pos.y, z=new_pos.z} @@ -422,7 +422,7 @@ local node_callbacks = function(player) local newnode_copy = {name=new_node.name, param1=new_node.param1, param2=new_node.param2} callback(pos_copy, newnode_copy, digtron.fake_player, oldnode_copy) end - + local new_def = minetest.registered_nodes[new_node.name] if new_def ~= nil and new_def.after_place_node ~= nil then new_def.after_place_node(new_pos, player) @@ -452,7 +452,7 @@ local set_meta_with_retry = function(meta, meta_table) end local air_node = {name="air"} -function DigtronLayout.write_layout_image(self, player) +function digtron.DigtronLayout.write_layout_image(self, player) -- destroy the old digtron local oldpos, _ = self.old_pos_pointset:pop() while oldpos ~= nil do @@ -472,7 +472,7 @@ function DigtronLayout.write_layout_image(self, player) end -- 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_node = node_image.node local old_node = minetest.get_node(new_pos) @@ -481,13 +481,13 @@ function DigtronLayout.write_layout_image(self, player) minetest.log("error", "DigtronLayout.write_layout_image failed to write a Digtron node, aborting write.") return false end - + placed_nodes_count = placed_nodes_count + 1 placed_node_pos[placed_nodes_count] = new_pos placed_new_node[placed_nodes_count] = new_node placed_old_node[placed_nodes_count] = old_node end - + -- fake_player will be passed to callbacks to prevent actual player from "taking the blame" for this action. -- For example, the hunger mod shouldn't be making the player hungry when he moves Digtron. digtron.fake_player:update(self.controller, player:get_player_name()) @@ -502,10 +502,10 @@ end --------------------------------------------------------------------------------------------- -- 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. 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 inv[index] = item:to_string() end @@ -515,10 +515,10 @@ function DigtronLayout.serialize(self) return minetest.serialize({controller=self.controller, all=self.all}) end -function DigtronLayout.deserialize(layout_string) +function digtron.DigtronLayout.deserialize(layout_string) local self = {} - setmetatable(self, DigtronLayout) - + setmetatable(self, digtron.DigtronLayout) + if not layout_string or layout_string == "" then return nil end @@ -526,7 +526,7 @@ function DigtronLayout.deserialize(layout_string) self.all = deserialized_layout.all 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 end diff --git a/class_pointset.lua b/class_pointset.lua index 40663d6..032555b 100644 --- a/class_pointset.lua +++ b/class_pointset.lua @@ -1,7 +1,7 @@ -- A simple special-purpose class, this is used for building up sets of three-dimensional points for fast reference -Pointset = {} -Pointset.__index = Pointset +digtron.Pointset = {} +digtron.Pointset.__index = digtron.Pointset -- 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) @@ -10,26 +10,26 @@ local hash_node_position_values = function(x, y, z) + x + 32768 end -function Pointset.create() +function digtron.Pointset.create() local set = {} - setmetatable(set,Pointset) + setmetatable(set,digtron.Pointset) set.points = {} return set end -function Pointset:clear() +function digtron.Pointset:clear() local points = self.points - for k, v in pairs(points) do + for k in pairs(points) do points[k] = nil 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". self.points[hash_node_position_values(x,y,z)] = value 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 excluded:get(x, y, z) ~= nil then return @@ -37,34 +37,35 @@ function Pointset:set_if_not_in(excluded, x, y, z, value) self:set(x, y, z, value) end -function Pointset:get(x, y, z) +function digtron.Pointset:get(x, y, z) -- return a value from the 3D array "points" return self.points[hash_node_position_values(x,y,z)] end -function Pointset:set_pos(pos, value) +function digtron.Pointset:set_pos(pos, value) self:set(pos.x, pos.y, pos.z, value) 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) end -function Pointset:get_pos(pos) +function digtron.Pointset:get_pos(pos) return self:get(pos.x, pos.y, pos.z) end -function Pointset:pop() +function digtron.Pointset:pop() -- returns a point that's in the 3D array, and then removes it. local hash, value = next(self.points) if hash == nil then return nil end local pos = minetest.get_position_from_hash(hash) - self.points[hash] = nil + self.points[hash] = nil return pos, value end -function 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 +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 local outlist = {} for hash, pointsval in pairs(self.points) do if value == nil or pointsval == value then @@ -73,5 +74,3 @@ function Pointset:get_pos_list(value) end return outlist end - - \ No newline at end of file diff --git a/doc.lua b/doc.lua index 257968a..d7857bf 100644 --- a/doc.lua +++ b/doc.lua @@ -14,7 +14,7 @@ local battery_ratio = (10000/digtron.config.power_ratio) / coal_fuel -- internationalization boilerplate 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 hoppers_enabled = minetest.get_modpath("hopper") and hopper ~= nil and hopper.add_container ~= nil @@ -102,7 +102,7 @@ if pipeworks_enabled then .."\n\n".. S("Fuel modules are compatible with Pipeworks blocks. When a Digtron moves one of the inventory modules adjacent to a pipe it will automatically hook up to it, and disconnect again when it moves on.") end - + digtron.doc.combined_storage_longdesc = S("Stores fuel for a Digtron and also has an inventory for building materials") digtron.doc.combined_storage_usagehelp = S("For smaller jobs the two dedicated modules may simply be too much of a good thing, wasting precious Digtron space to give unneeded capacity. The combined storage module is the best of both worlds, splitting its internal space between building material inventory and fuel storage. It has 3/4 building material capacity and 1/4 fuel storage capacity.") .. "\n\n" .. standard_fuel_doc diff --git a/entities.lua b/entities.lua index d203bd9..13d6bba 100644 --- a/entities.lua +++ b/entities.lua @@ -7,19 +7,19 @@ minetest.register_entity("digtron:marker", { physical = false, }, - on_activate = function(self, staticdata) - minetest.after(5.0, - function(self) + on_activate = function(self) + minetest.after(5.0, + function() self.object:remove() end, self) end, - - on_rightclick=function(self, clicker) + + on_rightclick=function(self) self.object:remove() end, - - on_punch = function(self, hitter) + + on_punch = function(self) self.object:remove() end, }) @@ -28,24 +28,31 @@ minetest.register_entity("digtron:marker_vertical", { initial_properties = { visual = "cube", 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}, physical = false, }, - on_activate = function(self, staticdata) - minetest.after(5.0, - function(self) + on_activate = function(self) + minetest.after(5.0, + function() self.object:remove() end, self) end, - - on_rightclick=function(self, clicker) + + on_rightclick=function(self) self.object:remove() end, - - on_punch = function(self, hitter) + + on_punch = function(self) self.object:remove() end, }) @@ -59,19 +66,19 @@ minetest.register_entity("digtron:marker_crate_good", { physical = false, }, - on_activate = function(self, staticdata) - minetest.after(digtron.config.marker_crate_good_duration, - function(self) + on_activate = function(self) + minetest.after(digtron.config.marker_crate_good_duration, + function() self.object:remove() end, self) end, - - on_rightclick=function(self, clicker) + + on_rightclick=function(self) self.object:remove() end, - - on_punch = function(self, hitter) + + on_punch = function(self) self.object:remove() end, }) @@ -85,19 +92,19 @@ minetest.register_entity("digtron:marker_crate_bad", { physical = false, }, - on_activate = function(self, staticdata) - minetest.after(digtron.config.marker_crate_bad_duration, - function(self) + on_activate = function(self) + minetest.after(digtron.config.marker_crate_bad_duration, + function() self.object:remove() end, self) end, - - on_rightclick=function(self, clicker) + + on_rightclick=function(self) self.object:remove() end, - - on_punch = function(self, hitter) + + on_punch = function(self) self.object:remove() end, }) @@ -114,7 +121,7 @@ minetest.register_entity("digtron:builder_item", { textures = {""}, automatic_rotate = math.pi * 0.25, }, - + on_activate = function(self, staticdata) local props = self.object:get_properties() if staticdata ~= nil and staticdata ~= "" then @@ -133,9 +140,9 @@ minetest.register_entity("digtron:builder_item", { digtron.create_builder_item = nil else self.object:remove() - end + end end, - + get_staticdata = function(self) local props = self.object:get_properties() if props ~= nil and props.textures ~= nil and props.textures[1] ~= nil then diff --git a/init.lua b/init.lua index 82de725..f52e572 100644 --- a/init.lua +++ b/init.lua @@ -33,7 +33,7 @@ digtron.builder_on_place_items = { digtron.builder_on_place_prefixes = { ["farming:"] = true, ["farming_plus:"] = true, - ["crops:"] = true, + ["crops:"] = true, } -- Finally, items belonging to group "digtron_on_place" will have their on_place methods called. @@ -42,7 +42,8 @@ local digtron_modpath = minetest.get_modpath( "digtron" ) 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 .. "/util.lua" ) diff --git a/nodes/node_axle.lua b/nodes/node_axle.lua index 1ae9ecc..d43bd60 100644 --- a/nodes/node_axle.lua +++ b/nodes/node_axle.lua @@ -1,6 +1,6 @@ -- internationalization boilerplate 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", { description = S("Digtron Rotation Axle"), @@ -21,7 +21,7 @@ minetest.register_node("digtron:axle", { "digtron_plate.png^digtron_axel_side.png", "digtron_plate.png^digtron_axel_side.png", }, - + drawtype = "nodebox", node_box = { type = "fixed", @@ -37,10 +37,10 @@ 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) - + -- new delay code without nodetimer (lost on crating) local now = minetest.get_gametime() local last_time = tonumber(meta:get_string("last_time")) or 0 @@ -54,7 +54,7 @@ minetest.register_node("digtron:axle", { return end - local image = DigtronLayout.create(pos, clicker) + local image = digtron.DigtronLayout.create(pos, clicker) if image:rotate_layout_image(node.param2) == false then -- This should be impossible, but if self-validation fails abort. return @@ -76,8 +76,8 @@ minetest.register_node("digtron:axle", { meta:set_string("infotext", S("Digtron is obstructed.")) end end, - - on_timer = function(pos, elapsed) + + on_timer = function(pos) minetest.get_meta(pos):set_string("waiting", nil) end, }) \ No newline at end of file diff --git a/nodes/node_battery_holder.lua b/nodes/node_battery_holder.lua index 456f9cc..4582a35 100644 --- a/nodes/node_battery_holder.lua +++ b/nodes/node_battery_holder.lua @@ -1,6 +1,6 @@ -- internationalization boilerplate 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. @@ -18,7 +18,7 @@ local battery_holder_formspec_string = "size[8,9.3]" .. "listring[current_player;main]" .. default.get_hotbar_bg(0,5.15) -local battery_holder_formspec = function(pos, meta) +local battery_holder_formspec = function() return battery_holder_formspec_string end @@ -28,7 +28,7 @@ if not minetest.get_modpath("technic") then -- leave them registered, though, in case technic is being removed from an existing server. holder_groups.not_in_creative_inventory = 1 end - + minetest.register_node("digtron:battery_holder", { description = S("Digtron Battery Holder"), _doc_items_longdesc = digtron.doc.battery_holder_longdesc, @@ -62,55 +62,55 @@ minetest.register_node("digtron:battery_holder", { local inv = meta:get_inventory() inv:set_size("batteries", 8*4) end, - + -- 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 local node_name = stack:get_name() - + -- Allow all items with energy storage from technic mod - if technic.power_tools[node_name] ~= nil then + if technic.power_tools[node_name] ~= nil then local meta = stack:get_metadata() local md = minetest.deserialize(meta) -- And specifically if they hold any charge -- Disregard empty batteries, the player should know better if md and md.charge > 0 then - return stack:get_count() + return stack:get_count() else return 0 end - + else return 0 end end return 0 end, - - - can_dig = function(pos,player) + + + can_dig = function(pos) local meta = minetest.get_meta(pos) local inv = meta:get_inventory() return inv:is_empty("batteries") end, - + -- Pipeworks compatibility -- Because who wouldn't send batteries through pipes if he could? ----------------------------------------------------------------- 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 inv = meta:get_inventory() return inv:add_item("batteries", stack) end, - can_insert = function(pos, node, stack, direction) + can_insert = function(pos, _, stack) local meta = stack:get_metadata() local md = minetest.deserialize(meta) -- And specifically if they hold any charge -- Disregard empty batteries, the player should know better if md and md.charge > 0 then - local meta = minetest.get_meta(pos) + meta = minetest.get_meta(pos) local inv = meta:get_inventory() return inv:room_for_item("batteries", stack) end @@ -119,7 +119,7 @@ minetest.register_node("digtron:battery_holder", { input_inventory = "batteries", connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1, top = 1} } end end)(), - + after_place_node = (function() if minetest.get_modpath("pipeworks") then return pipeworks.after_place end end)(), after_dig_node = (function() if minetest.get_modpath("pipeworks")then return pipeworks.after_dig end end)() }) diff --git a/nodes/node_builders.lua b/nodes/node_builders.lua index 4d17667..aacc40c 100644 --- a/nodes/node_builders.lua +++ b/nodes/node_builders.lua @@ -1,6 +1,6 @@ -- internationalization boilerplate 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. @@ -19,15 +19,18 @@ local builder_formspec_string = "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") .. "]" .. "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}]" .. "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}]" .. - "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") .. "]" .. "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}]" .. - "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") .. "]" .. "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;]" .. @@ -41,9 +44,8 @@ if minetest.get_modpath("doc") then "button_exit[7.0,0.5;1,0.1;help;" .. S("Help") .. "]" .. "tooltip[help;" .. S("Show documentation about this block") .. "]" end - + local builder_formspec = function(pos, meta) - local nodemeta = "nodemeta:"..pos.x .. "," .. pos.y .. "," ..pos.z return builder_formspec_string :gsub("${extrusion}", meta:get_int("extrusion"), 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) 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() 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) @@ -61,7 +63,7 @@ local builder_on_rightclick = function(pos, node, clicker, itemstack, pointed_th end return returnstack, success end - local meta = minetest.get_meta(pos) + local meta = minetest.get_meta(pos) minetest.show_formspec(clicker:get_player_name(), "digtron:builder"..minetest.pos_to_string(pos), builder_formspec(pos, meta)) @@ -73,13 +75,13 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields) return end local pos = minetest.string_to_pos(formname:sub(16, -1)) - + local meta = minetest.get_meta(pos) local period = tonumber(fields.period) local offset = tonumber(fields.offset) local build_facing = tonumber(fields.build_facing) local extrusion = tonumber(fields.extrusion) - + if period and period > 0 then meta:set_int("period", math.floor(tonumber(fields.period))) else @@ -104,74 +106,70 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields) end if extrusion and extrusion > 0 and extrusion <= digtron.config.maximum_extrusion then meta:set_int("extrusion", math.floor(tonumber(fields.extrusion))) - else - extrusion = meta:get_int("extrusion") end - + local nodename = minetest.get_node_or_nil(pos).name - + -- Master builder: bulk operations on all builders, layout cycling if nodename == "digtron:master_builder" then - + if fields.set then -- copy current settings to all builders - local layout = DigtronLayout.create(pos, sender) - + local layout = digtron.DigtronLayout.create(pos, sender) + if layout.builders ~= nil then - + local inv = meta:get_inventory() local target_item = inv:get_stack("main",1) local target_item_name = target_item:get_name() - - if target_item_name ~= "air" and minetest.get_item_group(target_item_name, "digtron") == 0 then - - for k, location in pairs(layout.builders) do - local target = minetest.get_node(location.pos) + if target_item_name ~= "air" and minetest.get_item_group(target_item_name, "digtron") == 0 then + + for _, location in pairs(layout.builders) do + local target_meta = minetest.get_meta(location.pos) target_meta:set_int("period", meta:get_int("period")) target_meta:set_int("offset", meta:get_int("offset")) target_meta:set_int("build_facing", meta:get_int("build_facing")) target_meta:set_int("extrusion", meta:get_int("extrusion")) - + local target_inv = target_meta:get_inventory() target_inv:set_stack("main", 1, target_item_name) - + digtron.update_builder_item(location.pos) end end end - + elseif fields.read then -- make all builders perform read&save - local layout = DigtronLayout.create(pos, sender) - + local layout = digtron.DigtronLayout.create(pos, sender) + if layout.builders ~= nil then - for k, location in pairs(layout.builders) do - - local target = minetest.get_node(location.pos) + for _, location in pairs(layout.builders) do + local facing = minetest.get_node(location.pos).param2 local buildpos = digtron.find_new_pos(location.pos, facing) local target_node = minetest.get_node(buildpos) 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 target_name = digtron.builder_read_item_substitutions[target_node.name] or target_node.name inv:set_stack("main", 1, target_name) meta:set_int("build_facing", target_node.param2) digtron.update_builder_item(location.pos) end - + end end end - - + + -- regular builder: changes apply only to itself else - + if fields.set then digtron.show_offset_markers(pos, offset, period) @@ -180,16 +178,16 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields) local buildpos = digtron.find_new_pos(pos, facing) local target_node = minetest.get_node(buildpos) 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 target_name = digtron.builder_read_item_substitutions[target_node.name] or target_node.name inv:set_stack("main", 1, target_name) meta:set_int("build_facing", target_node.param2) end end - + end - + if fields.help and minetest.get_modpath("doc") then --check for mod in case someone disabled it after this digger was built minetest.after(0.5, doc.show_entry, sender:get_player_name(), "nodes", "digtron:builder", true) end @@ -209,7 +207,7 @@ minetest.register_node("digtron:builder", { paramtype = "light", paramtype2= "facedir", is_ground_content = false, - tiles = { + tiles = { "digtron_plate.png^[transformR90", "digtron_plate.png^[transformR270", "digtron_plate.png", @@ -217,7 +215,7 @@ minetest.register_node("digtron:builder", { "digtron_plate.png^digtron_builder.png", "digtron_plate.png", }, - + drawtype = "nodebox", node_box = { type = "fixed", @@ -238,88 +236,88 @@ minetest.register_node("digtron:builder", { {-0.3125, -0.0625, 0.3125, 0.3125, 0.0625, 0.375}, -- frontcross_horizontal } }, - + on_construct = function(pos) local meta = minetest.get_meta(pos) - meta:set_int("period", 1) - meta:set_int("offset", 0) + meta:set_int("period", 1) + meta:set_int("offset", 0) meta:set_int("build_facing", 0) meta:set_int("extrusion", 1) - + local inv = meta:get_inventory() inv:set_size("main", 1) end, - + on_rightclick = builder_on_rightclick, - + on_destruct = function(pos) digtron.remove_builder_item(pos) end, - + after_place_node = function(pos) digtron.update_builder_item(pos) 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() - + if minetest.get_item_group(stack_name, "digtron") ~= 0 then return 0 -- don't allow builders to be set to build Digtron nodes, they'll just clog the output. - end - + end + local stack_def = minetest.registered_nodes[stack_name] if not stack_def and not digtron.whitelisted_on_place(stack_name) then return 0 -- don't allow craft items unless their on_place is whitelisted. end - + node_inventory_table.pos = pos local inv = minetest.get_inventory(node_inventory_table) inv:set_stack(listname, index, stack:take_item(1)) - + -- If we're adding a wallmounted item and the build facing is greater than 5, reset it to 0 local meta = minetest.get_meta(pos) if stack_def ~= nil and stack_def.paramtype2 == "wallmounted" and tonumber(meta:get_int("build_facing")) > 5 then meta:set_int("build_facing", 0) end - + return 0 end, - - allow_metadata_inventory_take = function(pos, listname, index, stack, player) + + allow_metadata_inventory_take = function(pos, listname, index) node_inventory_table.pos = pos local inv = minetest.get_inventory(node_inventory_table) inv:set_stack(listname, index, ItemStack("")) return 0 end, - + -- "builder at pos, imagine that you're in test_pos. If you're willing and able to build from there, take the item you need from inventory. -- return the item you took and the inventory location you took it from so it can be put back after all the other builders have been tested. -- If you couldn't get the item from inventory, return an error code so we can abort the cycle. -- If you're not supposed to build at all, or the location is obstructed, return 0 to let us know you're okay and we shouldn't abort." - + --return code and accompanying value: -- 0, {} -- not supposed to build, no error -- 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 -- 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 facing = minetest.get_node(pos).param2 local buildpos = digtron.find_new_pos(test_pos, facing) - + if (buildpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") ~= 0 then --It's not the builder's turn to build right now. return 0, {} end - + local extrusion_count = 0 local extrusion_target = meta:get_int("extrusion") if extrusion_target == nil or extrusion_target < 1 or extrusion_target > 100 then extrusion_target = 1 -- failsafe end - + local return_items = {} - + node_inventory_table.pos = pos local inv = minetest.get_inventory(node_inventory_table) local item_stack = inv:get_stack("main", 1) @@ -327,20 +325,20 @@ minetest.register_node("digtron:builder", { if item_stack:is_empty() then return 3, {} -- error code for "this builder's item slot is unset" end - + while extrusion_count < extrusion_target do if not digtron.can_move_to(buildpos, protected_nodes, nodes_dug) then --using "can_move_to" instead of "can_build_to" test case in case the builder is pointed "backward", and will thus --be building into the space that it's currently in and will be vacating after moving, or in case the builder is aimed --sideways and a fellow digtron node was ahead of it (will also be moving out of the way). - + --If the player has built his digtron stupid (eg has another digtron node in the place the builder wants to build) this --assumption is wrong, but I can't hold the player's hand through *every* possible bad design decision. Worst case, --the digtron will think its inventory can't handle the next build step and abort the build when it actually could have --managed one more cycle. That's not a bad outcome for a digtron array that was built stupidly to begin with. return 1, return_items end - + local source_location = digtron.take_from_inventory(item_stack:get_name(), inventory_positions) if source_location ~= nil then table.insert(return_items, {item=item_stack, location=source_location}) @@ -350,34 +348,34 @@ minetest.register_node("digtron:builder", { extrusion_count = extrusion_count + 1 buildpos = digtron.find_new_pos(buildpos, facing) end - + return 1, return_items end, - + execute_build = function(pos, player, inventory_positions, protected_nodes, nodes_dug, controlling_coordinate, controller_pos) local meta = minetest.get_meta(pos) local build_facing = tonumber(meta:get_int("build_facing")) local facing = minetest.get_node(pos).param2 local buildpos = digtron.find_new_pos(pos, facing) - + if (buildpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") ~= 0 then return 0 end - + local extrusion_count = 0 local extrusion_target = meta:get_int("extrusion") if extrusion_target == nil or extrusion_target < 1 or extrusion_target > 100 then extrusion_target = 1 -- failsafe end local built_count = 0 - + node_inventory_table.pos = pos local inv = minetest.get_inventory(node_inventory_table) local item_stack = inv:get_stack("main", 1) if item_stack:is_empty() then return built_count end - + while extrusion_count < extrusion_target do if not digtron.can_build_to(buildpos, protected_nodes, nodes_dug) then return built_count @@ -386,24 +384,26 @@ minetest.register_node("digtron:builder", { local oldnode = minetest.get_node(buildpos) 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 - 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) built_count = built_count + 1 else return built_count end end - + local sourcepos = digtron.take_from_inventory(item_stack:get_name(), inventory_positions) if sourcepos == nil then -- 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 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 - 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. nodes_dug:set(buildpos.x, buildpos.y, buildpos.z, false) digtron.award_item_built(item_stack:get_name(), player) @@ -423,7 +423,7 @@ minetest.register_node("digtron:builder", { }) -- Master builder node --- Does not build anything, but can set all other builders to a certain item +-- Does not build anything, but can set all other builders to a certain item -- OR make all other builders perform read & save operation. -- First function is handy e.g. for farming combines, the second is handy for templates. -- The formspec is reused, but the buttons are behaving differently from regular builder: @@ -448,7 +448,7 @@ minetest.register_node("digtron:master_builder", { "digtron_plate.png^digtron_master_builder.png^[colorize:" .. digtron.auto_controller_colorize, "digtron_plate.png^digtron_master_builder.png^[colorize:" .. digtron.auto_controller_colorize, }, - + drawtype = "nodebox", node_box = { type = "fixed", @@ -467,59 +467,59 @@ minetest.register_node("digtron:master_builder", { {-0.3125, -0.5, -0.5, 0.3125, -0.3125, -0.3125}, } }, - + on_construct = function(pos) local meta = minetest.get_meta(pos) - meta:set_int("period", 1) - meta:set_int("offset", 0) + meta:set_int("period", 1) + meta:set_int("offset", 0) meta:set_int("build_facing", 0) meta:set_int("extrusion", 1) - + local inv = meta:get_inventory() inv:set_size("main", 1) end, - + on_rightclick = builder_on_rightclick, - + on_destruct = function(pos) digtron.remove_builder_item(pos) end, - + after_place_node = function(pos) digtron.update_builder_item(pos) 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() - + if minetest.get_item_group(stack_name, "digtron") ~= 0 then return 0 -- don't allow builders to be set to build Digtron nodes, they'll just clog the output. - end - + end + local stack_def = minetest.registered_nodes[stack_name] if not stack_def and not digtron.whitelisted_on_place(stack_name) then return 0 -- don't allow craft items unless their on_place is whitelisted. end - + node_inventory_table.pos = pos local inv = minetest.get_inventory(node_inventory_table) inv:set_stack(listname, index, stack:take_item(1)) - + -- If we're adding a wallmounted item and the build facing is greater than 5, reset it to 0 local meta = minetest.get_meta(pos) if stack_def ~= nil and stack_def.paramtype2 == "wallmounted" and tonumber(meta:get_int("build_facing")) > 5 then meta:set_int("build_facing", 0) end - + return 0 end, - - allow_metadata_inventory_take = function(pos, listname, index, stack, player) + + allow_metadata_inventory_take = function(pos, listname, index) node_inventory_table.pos = pos local inv = minetest.get_inventory(node_inventory_table) inv:set_stack(listname, index, ItemStack("")) return 0 end, - + }) diff --git a/nodes/node_controllers.lua b/nodes/node_controllers.lua index 8e20919..f7503a7 100644 --- a/nodes/node_controllers.lua +++ b/nodes/node_controllers.lua @@ -1,6 +1,6 @@ -- internationalization boilerplate 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 ={ {-0.3125, -0.3125, -0.3125, 0.3125, 0.3125, 0.3125}, -- Core @@ -39,20 +39,20 @@ minetest.register_node("digtron:controller", { "digtron_plate.png", "digtron_plate.png^digtron_control.png", }, - + drawtype = "nodebox", node_box = { type = "fixed", fixed = controller_nodebox, }, - + on_construct = function(pos) local meta = minetest.get_meta(pos) meta:set_float("fuel_burning", 0.0) meta:set_string("infotext", S("Heat remaining in controller furnace: @1", 0)) end, - - on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + + on_rightclick = function(pos, _, clicker) local meta = minetest.get_meta(pos) -- new delay code without nodetimer (lost on crating) @@ -62,28 +62,28 @@ minetest.register_node("digtron:controller", { -- if meta:get_string("waiting") == "true" then if last_time + digtron.config.cycle_time > now then -- Been too soon since last time the digtron did a cycle. - + -- added for clarity meta:set_string("infotext", S("repetition delay")) - + return 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) if status ~= nil then meta:set_string("infotext", status) end - + -- Start the delay before digtron can run again. minetest.get_meta(newpos):set_string("waiting", "true") -- minetest.get_node_timer(newpos):start(digtron.config.cycle_time) -- new delay code meta:set_string("last_time",tostring(minetest.get_gametime())) end, - - on_timer = function(pos, elapsed) + + on_timer = function(pos) minetest.get_meta(pos):set_string("waiting", nil) end, }) @@ -97,15 +97,18 @@ local auto_formspec = "size[8,6.2]" .. default.gui_slots .. "container[2.0,0]" .. "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").. "]" .. "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").. "]" .. "tooltip[execute;" .. S("Begins executing the given number of cycles").. "]" .. "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}]" .. - "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}]" .. "tooltip[period;" .. S("Number of seconds to wait between each cycle").. "]" .. "list[current_name;stop;3.0,0.7;1,1;]" .. @@ -121,7 +124,7 @@ if minetest.get_modpath("doc") then auto_formspec = auto_formspec .. "button_exit[7.0,0.5;1,0.1;help;" .. S("Help") .. "]" .. "tooltip[help;" .. S("Show documentation about this block").. "]" -end +end local function auto_cycle(pos) local node = minetest.get_node(pos) @@ -134,11 +137,11 @@ local function auto_cycle(pos) local cycle = meta:get_int("cycles") local slope = meta:get_int("slope") - + if meta:get_string("lateral_done") ~= "true" and slope ~= 0 and (pos[controlling_coordinate] + meta:get_int("offset")) % slope == 0 then --Do a downward dig cycle. Don't update the "cycles" count, these don't count towards that. local newpos, status, return_code = digtron.execute_downward_dig_cycle(pos, player) - + if vector.equals(pos, newpos) then status = status .. "\n" .. S("Cycles remaining: @1", cycle) .. "\n" .. S("Halted!") meta:set_string("infotext", status) @@ -174,14 +177,14 @@ local function auto_cycle(pos) end return end - + meta = minetest.get_meta(newpos) cycle = meta:get_int("cycles") - 1 meta:set_int("cycles", cycle) status = status .. "\n" .. S("Cycles remaining: @1", cycle) meta:set_string("infotext", status) meta:set_string("lateral_done", nil) - + if cycle > 0 then minetest.after(meta:get_int("period"), auto_cycle, newpos) else @@ -211,13 +214,13 @@ minetest.register_node("digtron:auto_controller", { "digtron_plate.png^[colorize:" .. digtron.auto_controller_colorize, "digtron_plate.png^digtron_control.png^[colorize:" .. digtron.auto_controller_colorize, }, - + drawtype = "nodebox", node_box = { type = "fixed", fixed = controller_nodebox, }, - + on_construct = function(pos) local meta = minetest.get_meta(pos) meta:set_float("fuel_burning", 0.0) @@ -228,35 +231,35 @@ minetest.register_node("digtron:auto_controller", { meta:set_int("offset", 0) meta:set_int("cycles", 0) meta:set_int("slope", 0) - + local inv = meta:get_inventory() inv:set_size("stop", 1) 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 return 0 -- pointless setting a Digtron node as a stop block - end + end node_inventory_table.pos = pos local inv = minetest.get_inventory(node_inventory_table) inv:set_stack(listname, index, stack:take_item(1)) return 0 end, - - allow_metadata_inventory_take = function(pos, listname, index, stack, player) + + allow_metadata_inventory_take = function(pos, listname, index) node_inventory_table.pos = pos local inv = minetest.get_inventory(node_inventory_table) inv:set_stack(listname, index, ItemStack("")) return 0 end, - - on_receive_fields = function(pos, formname, fields, sender) + + on_receive_fields = function(pos, _, fields, sender) local meta = minetest.get_meta(pos) local offset = tonumber(fields.offset) local period = tonumber(fields.period) local slope = tonumber(fields.slope) local cycles = tonumber(fields.cycles) - + if period and period > 0 then meta:set_int("period", math.max(digtron.config.cycle_time, math.floor(period))) end @@ -264,11 +267,11 @@ minetest.register_node("digtron:auto_controller", { if offset then meta:set_int("offset", offset) end - + if slope and slope >= 0 then meta:set_int("slope", slope) end - + if cycles and cycles >= 0 then meta:set_int("cycles", math.floor(cycles)) if sender:is_player() and cycles > 0 then @@ -284,7 +287,7 @@ minetest.register_node("digtron:auto_controller", { if fields.set and slope and slope > 0 then local node = minetest.get_node(pos) local controlling_coordinate = digtron.get_controlling_coordinate(pos, node.param2) - + offset = offset or 0 local newpos = pos local markerpos = {x=newpos.x, y=newpos.y, z=newpos.z} @@ -299,14 +302,14 @@ minetest.register_node("digtron:auto_controller", { markerpos[controlling_coordinate] = x_pos + slope minetest.add_entity(markerpos, "digtron:marker_vertical") end - end - + end + if fields.help and minetest.get_modpath("doc") then --check for mod in case someone disabled it after this digger was built minetest.after(0.5, doc.show_entry, sender:get_player_name(), "nodes", "digtron:auto_controller", true) end - end, - - on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + end, + + on_rightclick = function(pos) local meta = minetest.get_meta(pos) meta:set_string("infotext", meta:get_string("infotext") .. "\n" .. S("Interrupted!")) meta:set_string("waiting", "true") @@ -338,30 +341,30 @@ minetest.register_node("digtron:pusher", { "digtron_plate.png^[colorize:" .. digtron.pusher_controller_colorize, "digtron_plate.png^digtron_control.png^[colorize:" .. digtron.pusher_controller_colorize, }, - + drawtype = "nodebox", node_box = { type = "fixed", fixed = controller_nodebox, }, - - on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + + on_rightclick = function(pos, _, clicker) local meta = minetest.get_meta(pos) if meta:get_string("waiting") == "true" then -- Been too soon since last time the digtron did a cycle. return 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:set_string("infotext", status_text) - + -- Start the delay before digtron can run again. minetest.get_meta(newpos):set_string("waiting", "true") minetest.get_node_timer(newpos):start(digtron.config.cycle_time) end, - - on_timer = function(pos, elapsed) + + on_timer = function(pos) minetest.get_meta(pos):set_string("waiting", nil) end, }) diff --git a/nodes/node_crate.lua b/nodes/node_crate.lua index d0dc7fd..e64e8f2 100644 --- a/nodes/node_crate.lua +++ b/nodes/node_crate.lua @@ -1,6 +1,6 @@ -- internationalization boilerplate 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") @@ -23,14 +23,14 @@ local player_permitted = function(pos, player) end 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_suffix = "" if protected then protection_prefix = S("Digtron Crate") .. "\n" .. S("Owned by @1", clicker:get_player_name() or "") protection_suffix = S("Owned by @1", clicker:get_player_name() or "") end - + if layout.contains_protected_node then local meta = minetest.get_meta(pos) minetest.sound_play("buzzer", {gain=0.5, pos=pos}) @@ -38,7 +38,7 @@ local store_digtron = function(pos, clicker, loaded_node_name, protected) -- no stealing other peoples' digtrons return end - + if #layout.all == 1 then local meta = minetest.get_meta(pos) minetest.sound_play("buzzer", {gain=0.5, pos=pos}) @@ -47,34 +47,34 @@ local store_digtron = function(pos, clicker, loaded_node_name, protected) end digtron.award_crate(layout, clicker:get_player_name()) - + local layout_string = layout:serialize() - + -- destroy everything. Note that this includes the empty crate, which will be bundled up with the layout. for _, node_image in pairs(layout.all) do local old_pos = node_image.pos local old_node = node_image.node minetest.remove_node(old_pos) - + if modpath_awards then -- We're about to tell the awards mod that we're digging a node, but we -- don't want it to count toward any actual awards. Pre-decrement. local data = awards.player(clicker:get_player_name()) awards.increment_item_counter(data, "dig", old_node.name, -1) end - + for _, callback in ipairs(minetest.registered_on_dignodes) do -- Copy pos and node because callback can modify them local pos_copy = {x=old_pos.x, y=old_pos.y, z=old_pos.z} local oldnode_copy = {name=old_node.name, param1=old_node.param1, param2=old_node.param2} callback(pos_copy, oldnode_copy, clicker) - end + end end - + -- Create the loaded crate node minetest.set_node(pos, {name=loaded_node_name}) minetest.sound_play("machine1", {gain=1.0, pos=pos}) - + local meta = minetest.get_meta(pos) meta:set_string("crated_layout", layout_string) @@ -107,12 +107,12 @@ minetest.register_node("digtron:empty_crate", { }, }, paramtype = "light", - + can_dig = function(pos, player) return player and not minetest.is_protected(pos, player:get_player_name()) end, - on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + on_rightclick = function(pos, _, clicker) store_digtron(pos, clicker, "digtron:loaded_crate") end }) @@ -147,7 +147,7 @@ minetest.register_node("digtron:empty_locked_crate", { can_dig = function(pos,player) return player and not minetest.is_protected(pos, player:get_player_name()) and player_permitted(pos, player) end, - on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + on_rightclick = function(pos, _, clicker) if player_permitted(pos,clicker) then store_digtron(pos, clicker, "digtron:loaded_locked_crate", true) end @@ -186,7 +186,7 @@ else "tooltip[unpack;" .. S("Attempts to unpack the Digtron on this location") .. "]" end -local loaded_formspec = function(pos, meta) +local loaded_formspec = function() return loaded_formspec_string end @@ -198,14 +198,14 @@ local loaded_on_recieve = function(pos, fields, sender, protected) end local title = meta:get_string("title") local infotext - + if protected then infotext = title .. "\n" .. S("Owned by @1", sender:get_player_name()) else infotext = title end meta:set_string("infotext", infotext) - + if fields.help and minetest.get_modpath("doc") then --check for mod in case someone disabled it after this digger was built minetest.after(0.5, doc.show_entry, sender:get_player_name(), "nodes", "digtron:loaded_crate", true) end @@ -213,20 +213,20 @@ local loaded_on_recieve = function(pos, fields, sender, protected) if not (fields.unpack or fields.show) then return end - + 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 meta:set_string("infotext", infotext .. "\n" .. S("Unable to read layout from crate metadata, regrettably this Digtron may be corrupted.")) - minetest.sound_play("buzzer", {gain=0.5, pos=pos}) + minetest.sound_play("buzzer", {gain=0.5, pos=pos}) -- Something went horribly wrong return end - + local protected_node = false local obstructed_node = false - + local pos_diff = vector.subtract(pos, layout.controller) layout.controller = pos for _, node_image in pairs(layout.all) do @@ -243,23 +243,23 @@ local loaded_on_recieve = function(pos, fields, sender, protected) end end end - + if not fields.unpack then return end - + if protected_node then meta:set_string("infotext", infotext .. "\n" .. S("Unable to deploy Digtron due to protected blocks in target area")) minetest.sound_play("buzzer", {gain=0.5, pos=pos}) return end - + if obstructed_node then meta:set_string("infotext", infotext .. "\n" .. S("Unable to deploy Digtron due to obstruction in target area")) minetest.sound_play("buzzer", {gain=0.5, pos=pos}) return end - + -- build digtron. Since the empty crate was included in the layout, that will overwrite this loaded crate and destroy it. minetest.sound_play("machine2", {gain=1.0, pos=pos}) layout:write_layout_image(sender) @@ -267,18 +267,18 @@ end local loaded_on_dig = function(pos, player, loaded_node_name) local meta = minetest.get_meta(pos) - + local stack = ItemStack({name=loaded_node_name, count=1, wear=0}) local stack_meta = stack:get_meta() stack_meta:set_string("crated_layout", meta:get_string("crated_layout")) stack_meta:set_string("description", meta:get_string("title")) local inv = player:get_inventory() - local stack = inv:add_item("main", stack) + stack = inv:add_item("main", stack) if stack:get_count() > 0 then -- prevent crash by not dropping loaded crate (see #44) -- minetest.add_item(pos, stack) return false - end + end -- call on_dignodes callback minetest.remove_node(pos) end @@ -302,7 +302,7 @@ local loaded_after_place = function(pos, itemstack) local title = stack_meta:get_string("description") if layout ~= "" then local meta = minetest.get_meta(pos) - + meta:set_string("crated_layout", layout) meta:set_string("title", title) meta:set_string("infotext", title) @@ -320,26 +320,26 @@ minetest.register_node("digtron:loaded_crate", { sounds = default.node_sound_wood_defaults(), tiles = {"digtron_plate.png^digtron_crate.png"}, is_ground_content = false, - + on_construct = function(pos) local meta = minetest.get_meta(pos) meta:set_string("formspec", loaded_formspec(pos, meta)) end, - - on_receive_fields = function(pos, formname, fields, sender) + + on_receive_fields = function(pos, _, fields, sender) return loaded_on_recieve(pos, fields, sender) 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 return loaded_on_dig(pos, player, "digtron:loaded_crate") end end, - - after_place_node = function(pos, placer, itemstack, pointed_thing) + + after_place_node = function(pos, _, itemstack) loaded_after_place(pos, itemstack) 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", { @@ -349,32 +349,36 @@ minetest.register_node("digtron:loaded_locked_crate", { groups = {cracky = 3, oddly_breakable_by_hand=3, not_in_creative_inventory=1, digtron_protected=1}, stack_max = 1, 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, - + on_construct = function(pos) local meta = minetest.get_meta(pos) meta:set_string("owner", "") end, --- can_dig = function(pos,node,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) + on_dig = function(pos, _, player) 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") else return false end end, - - after_place_node = function(pos, placer, itemstack, pointed_thing) + + after_place_node = function(pos, placer, itemstack) local meta = minetest.get_meta(pos) meta:set_string("owner", placer:get_player_name() or "") loaded_after_place(pos, itemstack) meta:set_string("infotext", meta:get_string("infotext") .. "\n" .. S("Owned by @1", meta:get_string("owner"))) end, - - on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + + on_rightclick = function(pos, _, clicker) if player_permitted(pos,clicker) then local meta = minetest.get_meta(pos) minetest.show_formspec( @@ -383,7 +387,7 @@ minetest.register_node("digtron:loaded_locked_crate", { loaded_formspec_string:gsub("${title}", meta:get_string("title"), 1)) 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) diff --git a/nodes/node_diggers.lua b/nodes/node_diggers.lua index 38ba539..85f4620 100644 --- a/nodes/node_diggers.lua +++ b/nodes/node_diggers.lua @@ -1,6 +1,6 @@ -- internationalization boilerplate 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. @@ -36,7 +36,8 @@ local intermittent_formspec_string = default.gui_bg .. "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.") .. "]" .. "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") .. "]" .. "tooltip[set;" .. S("Saves settings") .. "]" @@ -48,7 +49,7 @@ if modpath_doc then intermittent_formspec_string = "size[3.5,1]" .. intermittent_formspec_string end -local intermittent_formspec = function(pos, meta) +local intermittent_formspec = function(_, meta) return intermittent_formspec_string :gsub("${period}", meta:get_int("period"), 1) :gsub("${offset}", meta:get_int("offset"), 1) @@ -56,11 +57,11 @@ local intermittent_formspec = function(pos, meta) local intermittent_on_construct = function(pos) local meta = minetest.get_meta(pos) - meta:set_int("period", 1) - meta:set_int("offset", 0) + meta:set_int("period", 1) + meta:set_int("offset", 0) 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() 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) @@ -69,7 +70,7 @@ local intermittent_on_rightclick = function(pos, node, clicker, itemstack, point end return returnstack, success end - local meta = minetest.get_meta(pos) + local meta = minetest.get_meta(pos) minetest.show_formspec(clicker:get_player_name(), "digtron:intermittent_digger"..minetest.pos_to_string(pos), intermittent_formspec(pos, meta)) @@ -111,13 +112,13 @@ minetest.register_node("digtron:digger", { sounds = digtron.metal_sounds, paramtype = "light", paramtype2= "facedir", - is_ground_content = false, + is_ground_content = false, drawtype="nodebox", node_box = { type = "fixed", fixed = digger_nodebox, }, - + -- Aims in the +Z direction by default tiles = { "digtron_plate.png^[transformR90", @@ -137,18 +138,18 @@ minetest.register_node("digtron:digger", { }, -- 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 digpos = digtron.find_new_pos(pos, facing) if protected_nodes:get(digpos.x, digpos.y, digpos.z) then return 0 end - + return digtron.mark_diggable(digpos, nodes_dug, player) end, - - damage_creatures = function(player, pos, controlling_coordinate, items_dropped) + + damage_creatures = function(player, pos, _, items_dropped) local facing = minetest.get_node(pos).param2 digtron.damage_creatures(player, pos, digtron.find_new_pos(pos, facing), damage_hp, items_dropped) end, @@ -165,13 +166,13 @@ minetest.register_node("digtron:intermittent_digger", { sounds = digtron.metal_sounds, paramtype = "light", paramtype2= "facedir", - is_ground_content = false, + is_ground_content = false, drawtype="nodebox", node_box = { type = "fixed", fixed = digger_nodebox, }, - + -- Aims in the +Z direction by default tiles = { "digtron_plate.png^[transformR90", @@ -189,9 +190,9 @@ minetest.register_node("digtron:intermittent_digger", { }, "digtron_plate.png^digtron_intermittent.png^digtron_motor.png", }, - + on_construct = intermittent_on_construct, - + on_rightclick = intermittent_on_rightclick, -- returns fuel_cost, item_produced (a table or nil) @@ -206,15 +207,15 @@ minetest.register_node("digtron:intermittent_digger", { if protected_nodes:get(digpos.x, digpos.y, digpos.z) then return 0 end - + local meta = minetest.get_meta(pos) if (digpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") ~= 0 then return 0 end - + return digtron.mark_diggable(digpos, nodes_dug, player) end, - + damage_creatures = function(player, pos, controlling_coordinate, items_dropped) local facing = minetest.get_node(pos).param2 local targetpos = digtron.find_new_pos(pos, facing) @@ -242,7 +243,7 @@ minetest.register_node("digtron:soft_digger", { type = "fixed", fixed = digger_nodebox, }, - + -- Aims in the +Z direction by default tiles = { "digtron_plate.png^[transformR90^[colorize:" .. digtron.soft_digger_colorize, @@ -260,23 +261,23 @@ minetest.register_node("digtron:soft_digger", { }, "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 digpos = digtron.find_new_pos(pos, facing) - + if protected_nodes:get(digpos.x, digpos.y, digpos.z) then return 0 end - + if digtron.is_soft_material(digpos) then return digtron.mark_diggable(digpos, nodes_dug, player) end - + return 0 end, - damage_creatures = function(player, pos, controlling_coordinate, items_dropped) + damage_creatures = function(player, pos, _, items_dropped) local facing = minetest.get_node(pos).param2 digtron.damage_creatures(player, pos, digtron.find_new_pos(pos, facing), damage_hp_half, items_dropped) end, @@ -299,7 +300,7 @@ minetest.register_node("digtron:intermittent_soft_digger", { type = "fixed", fixed = digger_nodebox, }, - + -- Aims in the +Z direction by default tiles = { "digtron_plate.png^[transformR90^[colorize:" .. digtron.soft_digger_colorize, @@ -317,11 +318,11 @@ minetest.register_node("digtron:intermittent_soft_digger", { }, "digtron_plate.png^digtron_intermittent.png^digtron_motor.png^[colorize:" .. digtron.soft_digger_colorize, }, - + on_construct = intermittent_on_construct, - + on_rightclick = intermittent_on_rightclick, - + execute_dig = function(pos, protected_nodes, nodes_dug, controlling_coordinate, lateral_dig, player) if lateral_dig == true then return 0 @@ -329,27 +330,27 @@ minetest.register_node("digtron:intermittent_soft_digger", { local facing = minetest.get_node(pos).param2 local digpos = digtron.find_new_pos(pos, facing) - + if protected_nodes:get(digpos.x, digpos.y, digpos.z) then return 0 end - + local meta = minetest.get_meta(pos) if (digpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") ~= 0 then return 0 end - + if digtron.is_soft_material(digpos) then return digtron.mark_diggable(digpos, nodes_dug, player) end - + return 0 end, damage_creatures = function(player, pos, controlling_coordinate, items_dropped) local meta = minetest.get_meta(pos) local facing = minetest.get_node(pos).param2 - local targetpos = digtron.find_new_pos(pos, facing) + local targetpos = digtron.find_new_pos(pos, facing) if (targetpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") == 0 then digtron.damage_creatures(player, pos, targetpos, damage_hp_half, items_dropped) end @@ -366,13 +367,13 @@ minetest.register_node("digtron:dual_digger", { sounds = digtron.metal_sounds, paramtype = "light", paramtype2= "facedir", - is_ground_content = false, + is_ground_content = false, drawtype="nodebox", node_box = { type = "fixed", fixed = dual_digger_nodebox, }, - + -- Aims in the +Z and -Y direction by default tiles = { "digtron_plate.png^digtron_motor.png", @@ -400,14 +401,14 @@ minetest.register_node("digtron:dual_digger", { }, -- 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 digpos = digtron.find_new_pos(pos, facing) local digdown = digtron.find_new_pos_downward(pos, facing) local items = {} local cost = 0 - + if protected_nodes:get(digpos.x, digpos.y, digpos.z) ~= true then local forward_cost, forward_items = digtron.mark_diggable(digpos, nodes_dug, player) if forward_items ~= nil then @@ -426,11 +427,11 @@ minetest.register_node("digtron:dual_digger", { end cost = cost + down_cost end - + return cost, items end, - - damage_creatures = function(player, pos, controlling_coordinate, items_dropped) + + damage_creatures = function(player, pos, _, items_dropped) 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_downward(pos, facing), damage_hp, items_dropped) @@ -448,13 +449,13 @@ minetest.register_node("digtron:dual_soft_digger", { use_texture_alpha = use_texture_alpha, paramtype = "light", paramtype2= "facedir", - is_ground_content = false, + is_ground_content = false, drawtype="nodebox", node_box = { type = "fixed", fixed = dual_digger_nodebox, }, - + -- Aims in the +Z and -Y direction by default tiles = { "digtron_plate.png^digtron_motor.png^[colorize:" .. digtron.soft_digger_colorize, @@ -482,14 +483,14 @@ minetest.register_node("digtron:dual_soft_digger", { }, -- 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 digpos = digtron.find_new_pos(pos, facing) local digdown = digtron.find_new_pos_downward(pos, facing) local items = {} local cost = 0 - + if protected_nodes:get(digpos.x, digpos.y, digpos.z) ~= true and digtron.is_soft_material(digpos) then local forward_cost, forward_items = digtron.mark_diggable(digpos, nodes_dug, player) if forward_items ~= nil then @@ -508,11 +509,11 @@ minetest.register_node("digtron:dual_soft_digger", { end cost = cost + down_cost end - + return cost, items end, - - damage_creatures = function(player, pos, controlling_coordinate, items_dropped) + + damage_creatures = function(player, pos, _, items_dropped) 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_downward(pos, facing), damage_hp_half, items_dropped) diff --git a/nodes/node_duplicator.lua b/nodes/node_duplicator.lua index 506aa44..95f12bb 100644 --- a/nodes/node_duplicator.lua +++ b/nodes/node_duplicator.lua @@ -1,6 +1,6 @@ -- internationalization boilerplate 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 = "size[9,9.3]" .. @@ -29,7 +29,8 @@ minetest.register_node("digtron:duplicator", { _doc_items_usagehelp = digtron.doc.duplicator_usagehelp, groups = {cracky = 3, oddly_breakable_by_hand=3}, 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", "digtron_plate.png^(digtron_axel_side.png^[transformR180)", @@ -68,13 +69,13 @@ minetest.register_node("digtron:duplicator", { inv:set_size("main", 8*4) end, - can_dig = function(pos,player) + can_dig = function(pos) local meta = minetest.get_meta(pos) local inv = meta:get_inventory() return inv:is_empty("main") 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 return stack:get_count() else @@ -82,7 +83,7 @@ minetest.register_node("digtron:duplicator", { end end, - on_receive_fields = function(pos, formname, fields, sender) + on_receive_fields = function(pos, _, fields, sender) local player_name = sender:get_player_name() if fields.help then minetest.after(0.5, doc.show_entry, player_name, "nodes", "digtron:duplicator", true) @@ -113,7 +114,7 @@ minetest.register_node("digtron:duplicator", { return end - local layout = DigtronLayout.create(pos, sender) + local layout = digtron.DigtronLayout.create(pos, sender) if layout.contains_protected_node then minetest.sound_play("buzzer", {gain=0.5, pos=pos}) diff --git a/nodes/node_item_ejector.lua b/nodes/node_item_ejector.lua index be71537..1bee4b8 100644 --- a/nodes/node_item_ejector.lua +++ b/nodes/node_item_ejector.lua @@ -1,13 +1,13 @@ -- internationalization boilerplate 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 local pipeworks_path = minetest.get_modpath("pipeworks") local doc_path = minetest.get_modpath("doc") local formspec_width = 1.5 -local ejector_formspec_string = +local ejector_formspec_string = default.gui_bg .. default.gui_bg_img .. default.gui_slots @@ -19,9 +19,9 @@ if doc_path then formspec_width = formspec_width + 1.5 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 if pipeworks_path then return_string = return_string .. "checkbox[0,0.5;nonpipe;"..S("Eject into world")..";"..meta:get_string("nonpipe").."]" .. @@ -36,9 +36,9 @@ local function eject_items(pos, node, player, eject_even_without_pipeworks, layo local destination_pos = vector.add(pos, dir) local destination_node_name = minetest.get_node(destination_pos).name local destination_node_def = minetest.registered_nodes[destination_node_name] - + if not pipeworks_path then eject_even_without_pipeworks = true end -- if pipeworks is not installed, always eject into world (there's no other option) - + local insert_into_pipe = false local eject_into_world = false if pipeworks_path and minetest.get_item_group(destination_node_name, "tubedevice") > 0 then @@ -52,10 +52,10 @@ local function eject_items(pos, node, player, eject_even_without_pipeworks, layo end else return false - end + end if layout == nil then - layout = DigtronLayout.create(pos, player) + layout = digtron.DigtronLayout.create(pos, player) end -- Build a list of all the items that builder nodes want to use. @@ -65,7 +65,7 @@ local function eject_items(pos, node, player, eject_even_without_pipeworks, layo filter_items[node_image.meta.inventory.main[1]:get_name()] = true end end - + -- Look through the inventories and find an item that's not on that list. local source_node = nil local source_index = nil @@ -85,11 +85,11 @@ local function eject_items(pos, node, player, eject_even_without_pipeworks, layo end if source_node then break end end - + if source_node then local meta = minetest.get_meta(source_node.pos) local inv = meta:get_inventory() - + if insert_into_pipe then local from_pos = vector.add(pos, vector.multiply(dir, 0.5)) local start_pos = pos @@ -129,46 +129,46 @@ minetest.register_node("digtron:inventory_ejector", { {-0.1875, -0.1875, 0.3125, 0.1875, 0.1875, 0.5}, -- NodeBox3 } }, - + on_construct = function(pos) local meta = minetest.get_meta(pos) meta:set_string("autoeject", "true") meta:set_string("formspec", ejector_formspec(pos, meta)) end, - + tube = (function() if pipeworks_path then return { connect_sides = {back = 1} } end end)(), - + on_punch = function(pos, node, player) eject_items(pos, node, player, true) end, - + execute_eject = function(pos, node, player, layout) local meta = minetest.get_meta(pos) eject_items(pos, node, player, meta:get_string("nonpipe") == "true", layout) end, - - on_receive_fields = function(pos, formname, fields, sender) + + on_receive_fields = function(pos, _, fields, sender) 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 local node_name = minetest.get_node(pos).name minetest.after(0.5, doc.show_entry, sender:get_player_name(), "nodes", node_name, true) end - + if fields.nonpipe then meta:set_string("nonpipe", fields.nonpipe) end - + if fields.autoeject then meta:set_string("autoeject", fields.autoeject) end - + meta:set_string("formspec", ejector_formspec(pos, meta)) - + end, - + after_place_node = (function() if pipeworks_path then return pipeworks.after_place end end)(), after_dig_node = (function() if pipeworks_path then return pipeworks.after_dig end end)() }) diff --git a/nodes/node_misc.lua b/nodes/node_misc.lua index cea823e..fbf15bb 100644 --- a/nodes/node_misc.lua +++ b/nodes/node_misc.lua @@ -1,6 +1,6 @@ -- internationalization boilerplate 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. minetest.register_node("digtron:structure", { diff --git a/nodes/node_power_connector.lua b/nodes/node_power_connector.lua index 6763b69..4347233 100644 --- a/nodes/node_power_connector.lua +++ b/nodes/node_power_connector.lua @@ -1,6 +1,6 @@ -- internationalization boilerplate 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 @@ -28,17 +28,21 @@ minetest.register_node("digtron:power_connector", { _doc_items_longdesc = digtron.doc.power_connector_longdesc, _doc_items_usagehelp = digtron.doc.power_connector_usagehelp, 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", - "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", - }, + tiles = { + "digtron_plate.png^digtron_power_connector_top.png^digtron_digger_yb_frame.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"}, drawtype = "nodebox", sounds = digtron.metal_sounds, paramtype = "light", paramtype2 = "facedir", is_ground_content = false, - + connects_to = {"group:technic_hv_cable"}, node_box = { type = "connected", @@ -53,45 +57,45 @@ minetest.register_node("digtron:power_connector", { connect_left = {-0.5, -size, -size, size, size, size}, -- x- connect_right = {-size, -size, -size, 0.5, size, size}, -- x+ }, - + on_construct = function(pos) local meta = minetest.get_meta(pos) meta:set_string("formspec", get_formspec_string(0,0)) end, - technic_run = function(pos, node) + technic_run = function(pos) local meta = minetest.get_meta(pos) local eu_input = meta:get_int("HV_EU_input") local demand = meta:get_int("HV_EU_demand") meta:set_string("infotext", S("Digtron Power @1/@2", eu_input, demand)) end, - - on_receive_fields = function(pos, formname, fields, sender) - local layout = DigtronLayout.create(pos, sender) + + on_receive_fields = function(pos, _, fields, sender) + local layout = digtron.DigtronLayout.create(pos, sender) local max_cost = 0 if layout.builders ~= nil then for _, node_image in pairs(layout.builders) do max_cost = max_cost + (digtron.config.build_cost * (node_image.meta.fields.extrusion or 1)) - end + end end 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 end end local current_max = max_cost * digtron.config.power_ratio - + local meta = minetest.get_meta(pos) - + if fields.maximize then meta:set_int("HV_EU_demand", current_max) elseif fields.value ~= nil then 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) end - - meta:set_string("formspec", get_formspec_string(meta:get_int("HV_EU_demand"), current_max)) + + meta:set_string("formspec", get_formspec_string(meta:get_int("HV_EU_demand"), current_max)) end, }) diff --git a/nodes/node_storage.lua b/nodes/node_storage.lua index 6237e66..f13d81e 100644 --- a/nodes/node_storage.lua +++ b/nodes/node_storage.lua @@ -1,10 +1,10 @@ -- internationalization boilerplate 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 inventory_formspec_string = +local inventory_formspec_string = "size[8,9.3]" .. default.gui_bg .. default.gui_bg_img .. @@ -17,7 +17,7 @@ local inventory_formspec_string = "listring[current_player;main]" .. default.get_hotbar_bg(0,5.15) -local inventory_formspec = function(pos, meta) +local inventory_formspec = function() return inventory_formspec_string end @@ -56,23 +56,23 @@ minetest.register_node("digtron:inventory", { local inv = meta:get_inventory() inv:set_size("main", 8*4) end, - - can_dig = function(pos,player) + + can_dig = function(pos) local meta = minetest.get_meta(pos) local inv = meta:get_inventory() return inv:is_empty("main") end, - + -- Pipeworks compatibility ---------------------------------------------------------------- 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 inv = meta:get_inventory() return inv:add_item("main", stack) end, - can_insert = function(pos, node, stack, direction) + can_insert = function(pos, _, stack) local meta = minetest.get_meta(pos) local inv = meta:get_inventory() return inv:room_for_item("main", stack) @@ -80,12 +80,12 @@ minetest.register_node("digtron:inventory", { input_inventory = "main", connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1, top = 1} } end end)(), - + after_place_node = (function() if pipeworks_path then return pipeworks.after_place end end)(), after_dig_node = (function() if pipeworks_path then return pipeworks.after_dig end end)() }) -local fuelstore_formspec_string = +local fuelstore_formspec_string = "size[8,9.3]" .. default.gui_bg .. default.gui_bg_img .. @@ -98,10 +98,10 @@ local fuelstore_formspec_string = "listring[current_player;main]" .. default.get_hotbar_bg(0,5.15) -local fuelstore_formspec = function(pos, meta) +local fuelstore_formspec = function() return fuelstore_formspec_string end - + -- Fuel storage. Controller node draws fuel from here. -- Note that fuel stores are digtron group 5. minetest.register_node("digtron:fuelstore", { @@ -137,9 +137,9 @@ minetest.register_node("digtron:fuelstore", { local inv = meta:get_inventory() inv:set_size("fuel", 8*4) end, - + -- 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 minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then return stack:get_count() @@ -149,18 +149,18 @@ minetest.register_node("digtron:fuelstore", { end return 0 end, - - can_dig = function(pos,player) + + can_dig = function(pos) local meta = minetest.get_meta(pos) local inv = meta:get_inventory() return inv:is_empty("fuel") end, - + -- Pipeworks compatibility ---------------------------------------------------------------- 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 local meta = minetest.get_meta(pos) local inv = meta:get_inventory() @@ -168,7 +168,7 @@ minetest.register_node("digtron:fuelstore", { end return stack 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 local meta = minetest.get_meta(pos) local inv = meta:get_inventory() @@ -179,7 +179,7 @@ minetest.register_node("digtron:fuelstore", { input_inventory = "fuel", connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1, top = 1} } end end)(), - + after_place_node = (function() if pipeworks_path then return pipeworks.after_place end end)(), after_dig_node = (function() if pipeworks_path then return pipeworks.after_dig end end)() }) @@ -199,7 +199,7 @@ local combined_storage_formspec_string = "listring[current_player;main]" .. default.get_hotbar_bg(0,5.75) -local combined_storage_formspec = function(pos, meta) +local combined_storage_formspec = function() return combined_storage_formspec_string end @@ -224,7 +224,8 @@ minetest.register_node("digtron:combined_storage", { is_ground_content = false, 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^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", @@ -236,9 +237,9 @@ minetest.register_node("digtron:combined_storage", { inv:set_size("main", 8*3) inv:set_size("fuel", 8*1) end, - + -- 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 minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then return stack:get_count() @@ -248,12 +249,12 @@ minetest.register_node("digtron:combined_storage", { end return stack:get_count() -- otherwise, allow all drops 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 return count end - + local meta = minetest.get_meta(pos) local inv = meta:get_inventory() local stack = inv:get_stack(from_list, from_index) @@ -262,17 +263,17 @@ minetest.register_node("digtron:combined_storage", { end return 0 end, - - can_dig = function(pos,player) + + can_dig = function(pos) local meta = minetest.get_meta(pos) local inv = meta:get_inventory() return inv:is_empty("fuel") and inv:is_empty("main") end, - + -- Pipeworks compatibility ---------------------------------------------------------------- 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 inv = meta:get_inventory() 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 return inv:add_item("main", stack) end, - can_insert = function(pos, node, stack, direction) + can_insert = function(pos, _, stack, direction) local meta = minetest.get_meta(pos) local inv = meta:get_inventory() if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 and direction.y == 1 then @@ -291,7 +292,7 @@ minetest.register_node("digtron:combined_storage", { input_inventory = "main", connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1, top = 1} } end end)(), - + after_place_node = (function() if pipeworks_path then return pipeworks.after_place end end)(), after_dig_node = (function() if pipeworks_path then return pipeworks.after_dig end end)() }) @@ -306,7 +307,7 @@ if minetest.get_modpath("hopper") and hopper ~= nil and hopper.add_container ~= {"top", "digtron:fuelstore", "fuel"}, {"bottom", "digtron:fuelstore", "fuel"}, {"side", "digtron:fuelstore", "fuel"}, - + {"top", "digtron:combined_storage", "main"}, {"bottom", "digtron:combined_storage", "main"}, {"side", "digtron:combined_storage", "fuel"}, diff --git a/nodes/recipes.lua b/nodes/recipes.lua index a907cbf..ce10303 100644 --- a/nodes/recipes.lua +++ b/nodes/recipes.lua @@ -1,6 +1,6 @@ -- internationalization boilerplate 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", { description = S("Digtron Core"), @@ -120,7 +120,7 @@ if minetest.get_modpath("technic") then {"","default:steel_ingot",""} } }) - + minetest.register_craft({ output = "digtron:power_connector", recipe = { diff --git a/upgrades.lua b/upgrades.lua index dc19053..fb289e5 100644 --- a/upgrades.lua +++ b/upgrades.lua @@ -28,19 +28,19 @@ minetest.register_lbm({ minetest.register_lbm({ name = "digtron:fuelstore_upgrade", nodenames = {"digtron:fuelstore"}, - action = function(pos, node) + action = function(pos) local meta = minetest.get_meta(pos) local inv = meta:get_inventory() local list = inv:get_list("main") inv:set_list("main", {}) - inv:set_list("fuel", list) + inv:set_list("fuel", list) end }) minetest.register_lbm({ name = "digtron:autocontroller_lateral_upgrade", nodenames = {"digtron:auto_controller"}, - action = function(pos, node) + action = function(pos) local meta = minetest.get_meta(pos) local cycles = meta:get_int("offset") meta:set_int("cycles", cycles) @@ -52,7 +52,7 @@ minetest.register_lbm({ minetest.register_lbm({ name = "digtron:builder_extrusion_upgrade", nodenames = {"digtron:builder"}, - action = function(pos, node) + action = function(pos) local meta = minetest.get_meta(pos) meta:set_int("extrusion", 1) end diff --git a/util.lua b/util.lua index 2ce2492..1818ae0 100644 --- a/util.lua +++ b/util.lua @@ -43,7 +43,7 @@ digtron.mark_diggable = function(pos, nodes_dug, player) -- returns fuel cost and what will be dropped by digging these nodes. local target = minetest.get_node(pos) - + -- prevent digtrons from being marked for digging. if minetest.get_item_group(target.name, "digtron") ~= 0 or minetest.get_item_group(target.name, "digtron_protected") ~= 0 or @@ -57,7 +57,7 @@ digtron.mark_diggable = function(pos, nodes_dug, player) if target.name ~= "air" then local in_known_group = false local material_cost = 0 - + if digtron.config.uses_resources then if minetest.get_item_group(target.name, "cracky") ~= 0 then in_known_group = true @@ -75,13 +75,13 @@ digtron.mark_diggable = function(pos, nodes_dug, player) material_cost = digtron.config.dig_cost_default end end - + return material_cost, minetest.get_node_drops(target.name, "") end end return 0 end - + digtron.can_build_to = function(pos, protected_nodes, dug_nodes) -- Returns whether a space is clear to have something put into it @@ -115,7 +115,7 @@ digtron.place_in_inventory = function(itemname, inventory_positions, fallback_po --tries placing the item in each inventory node in turn. If there's no room, drop it at fallback_pos local itemstack = ItemStack(itemname) if inventory_positions ~= nil then - for k, location in pairs(inventory_positions) do + for _, location in pairs(inventory_positions) do node_inventory_table.pos = location.pos local inv = minetest.get_inventory(node_inventory_table) itemstack = inv:add_item("main", itemstack) @@ -147,7 +147,7 @@ digtron.take_from_inventory = function(itemname, inventory_positions) if inventory_positions == nil then return nil end --tries to take an item from each inventory node in turn. Returns location of inventory item was taken from on success, nil on failure local itemstack = ItemStack(itemname) - for k, location in pairs(inventory_positions) do + for _, location in pairs(inventory_positions) do node_inventory_table.pos = location.pos local inv = minetest.get_inventory(node_inventory_table) local output = inv:remove_item("main", itemstack) @@ -158,8 +158,8 @@ digtron.take_from_inventory = function(itemname, inventory_positions) return nil end --- Used to determine which coordinate is being checked for periodicity. eg, if the digtron is moving in the z direction, then periodicity is checked for every n nodes in the z axis. -digtron.get_controlling_coordinate = function(pos, facedir) +-- Used to determine which coordinate is being checked for periodicity. eg, if the digtron is moving in the z direction, then periodicity is checked for every n nodes in the z axis +digtron.get_controlling_coordinate = function(_, facedir) -- used for determining builder period and offset local dir = digtron.facedir_to_dir_map[facedir] if dir == 1 or dir == 3 then @@ -172,7 +172,7 @@ digtron.get_controlling_coordinate = function(pos, facedir) end local fuel_craft = {method="fuel", width=1, items={}} -- reusable crafting recipe table for get_craft_result calls below --- Searches fuel store inventories for burnable items and burns them until target is reached or surpassed +-- Searches fuel store inventories for burnable items and burns them until target is reached or surpassed -- (or there's nothing left to burn). Returns the total fuel value burned -- if the "test" parameter is set to true, doesn't actually take anything out of inventories. -- We can get away with this sort of thing for fuel but not for builder inventory because there's just one @@ -183,7 +183,7 @@ digtron.burn = function(fuelstore_positions, target, test) end local current_burned = 0 - for k, location in pairs(fuelstore_positions) do + for _, location in pairs(fuelstore_positions) do if current_burned > target then break end @@ -194,8 +194,8 @@ digtron.burn = function(fuelstore_positions, target, test) if invlist == nil then -- This check shouldn't be needed, it's yet another guard against https://github.com/minetest/minetest/issues/8067 break end - - for i, itemstack in pairs(invlist) do + + for _, itemstack in pairs(invlist) do fuel_craft.items[1] = itemstack:peek_item(1) local fuel_per_item = minetest.get_craft_result(fuel_craft).time if fuel_per_item ~= 0 then @@ -222,8 +222,8 @@ digtron.burn = function(fuelstore_positions, target, test) end -- Consume energy from the batteries --- The same as burning coal, except that instead of destroying the items in the inventory, we merely drain --- the charge in them, leaving them empty. The charge is converted into "coal heat units" by a downscaling +-- The same as burning coal, except that instead of destroying the items in the inventory, we merely drain +-- the charge in them, leaving them empty. The charge is converted into "coal heat units" by a downscaling -- factor, since if taken at face value (10000 EU), the batteries would be the ultimate power source barely -- ever needing replacement. digtron.tap_batteries = function(battery_positions, target, test) @@ -237,20 +237,20 @@ digtron.tap_batteries = function(battery_positions, target, test) -- An RE battery holds 10000 EU of charge -- local power_ratio = 100 -- How much charge equals 1 unit of PU from coal -- setting Moved to digtron.config.power_ratio - - for k, location in pairs(battery_positions) do + + for _, location in pairs(battery_positions) do if current_burned > target then break end node_inventory_table.pos = location.pos local inv = minetest.get_inventory(node_inventory_table) local invlist = inv:get_list("batteries") - + if (invlist == nil) then -- This check shouldn't be needed, it's yet another guard against https://github.com/minetest/minetest/issues/8067 break end - - for i, itemstack in pairs(invlist) do + + for _, itemstack in pairs(invlist) do local meta = minetest.deserialize(itemstack:get_metadata()) if (meta ~= nil) then local power_available = math.floor(meta.charge / digtron.config.power_ratio) @@ -265,14 +265,13 @@ digtron.tap_batteries = function(battery_positions, target, test) end current_burned = current_burned + actual_burned end - end - + if current_burned > target then break end end - + if test ~= true then -- only update the list if we're doing this for real. inv:set_list("batteries", invlist) @@ -363,7 +362,7 @@ digtron.damage_creatures = function(player, source_pos, target_pos, amount, item obj:remove() end end - end + end end end @@ -382,8 +381,8 @@ end -- If someone sets very large offsets or intervals for the offset markers they might be added too far -- away. safe_add_entity causes these attempts to be ignored rather than crashing the game. -- returns the entity if successful, nil otherwise -function safe_add_entity(pos, name) - success, ret = pcall(minetest.add_entity, pos, name) +local function safe_add_entity(pos, name) + local success, ret = pcall(minetest.add_entity, pos, name) if success then return ret else return nil end end @@ -411,13 +410,13 @@ digtron.show_offset_markers = function(pos, offset, period) local entity = safe_add_entity({x=buildpos.x, y=buildpos.y, z=z_pos}, "digtron:marker") if entity ~= nil then entity:setyaw(1.5708) end - + if z_pos >= buildpos.z then - local entity = safe_add_entity({x=buildpos.x, y=buildpos.y, z=z_pos - period}, "digtron:marker") + entity = safe_add_entity({x=buildpos.x, y=buildpos.y, z=z_pos - period}, "digtron:marker") if entity ~= nil then entity:setyaw(1.5708) end end if z_pos <= buildpos.z then - local entity = safe_add_entity({x=buildpos.x, y=buildpos.y, z=z_pos + period}, "digtron:marker") + entity = safe_add_entity({x=buildpos.x, y=buildpos.y, z=z_pos + period}, "digtron:marker") if entity ~= nil then entity:setyaw(1.5708) end end end diff --git a/util_execute_cycle.lua b/util_execute_cycle.lua index eea6476..5d6a629 100644 --- a/util_execute_cycle.lua +++ b/util_execute_cycle.lua @@ -1,6 +1,6 @@ -- internationalization boilerplate 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 direction = minetest.facedir_to_dir(facing) @@ -50,15 +50,15 @@ local function neighbour_test(layout, status_text, dir) minetest.sound_play("buzzer", {gain=0.25, pos=layout.controller}) return S("Digtron is adjacent to unloaded nodes.") .. "\n" .. status_text, 1 end - + if layout.water_touching == true then minetest.sound_play("sploosh", {gain=1.0, pos=layout.controller}) end - + if layout.lava_touching == true then minetest.sound_play("woopwoopwoop", {gain=1.0, pos=layout.controller}) - end - + end + if dir and dir.y ~= -1 and layout.traction * digtron.config.traction_factor < table.getn(layout.all) then -- digtrons can't fly, though they can fall minetest.sound_play("squeal", {gain=1.0, pos=layout.controller}) @@ -117,11 +117,11 @@ digtron.execute_dig_cycle = function(pos, clicker) 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 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 status_text, return_code = neighbour_test(layout, status_text, dir) + local layout = digtron.DigtronLayout.create(pos, clicker) + + local return_code + status_text, return_code = neighbour_test(layout, status_text, dir) if return_code ~= 0 then return pos, status_text, return_code end @@ -130,21 +130,21 @@ digtron.execute_dig_cycle = function(pos, clicker) if size_check_error then return pos, size_check_error, 8 end - + local controlling_coordinate = digtron.get_controlling_coordinate(pos, facing) - + ---------------------------------------------------------------------------------------------------------------------- - + local items_dropped = {} local digging_fuel_cost = 0 local particle_systems = {} - + -- execute the execute_dig method on all digtron components that have one -- This builds a set of nodes that will be dug and returns a list of products that will be generated -- but doesn't actually dig the nodes yet. That comes later. -- If we dug them now, sand would fall and some digtron nodes would die. if layout.diggers ~= nil then - for k, location in pairs(layout.diggers) do + for _, location in pairs(layout.diggers) do local target = minetest.get_node(location.pos) local targetdef = minetest.registered_nodes[target.name] if targetdef.execute_dig ~= nil then @@ -163,9 +163,9 @@ digtron.execute_dig_cycle = function(pos, clicker) end end end - + ---------------------------------------------------------------------------------------------------------------------- - + -- test if any digtrons are obstructed by non-digtron nodes that haven't been marked -- as having been dug. local can_move = true @@ -175,11 +175,11 @@ digtron.execute_dig_cycle = function(pos, clicker) can_move = false end end - + if test_stop_block(pos, items_dropped) then can_move = false end - + if not can_move then -- mark this node as waiting, will clear this flag in digtron.config.cycle_time seconds minetest.get_meta(pos):set_string("waiting", "true") @@ -190,26 +190,26 @@ digtron.execute_dig_cycle = function(pos, clicker) end ---------------------------------------------------------------------------------------------------------------------- - + -- ask each builder node if it can get what it needs from inventory to build this cycle. -- This is a complicated test because each builder needs to actually *take* the item it'll -- 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. 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_fuel_items = {} local test_build_fuel_cost = 0 + local test_build_return_code, test_build_return_items, failed_to_find + if layout.builders ~= nil then - for k, location in pairs(layout.builders) do + for _, location in pairs(layout.builders) do local target = minetest.get_node(location.pos) local targetdef = minetest.registered_nodes[target.name] local test_location = vector.add(location.pos, dir) 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) - for k, return_item in pairs(test_build_return_items) do + test_build_return_code, test_build_return_items, failed_to_find = targetdef.test_build( + location.pos, test_location, layout.inventories, layout.protected, layout.nodes_dug, controlling_coordinate, layout.controller + ) + for _, return_item in pairs(test_build_return_items) do table.insert(test_items, return_item) test_build_fuel_cost = test_build_fuel_cost + digtron.config.build_cost end @@ -222,7 +222,7 @@ digtron.execute_dig_cycle = function(pos, clicker) end end end - + local test_fuel_needed = test_build_fuel_cost + digging_fuel_cost - fuel_burning local test_fuel_burned = 0 @@ -248,7 +248,7 @@ digtron.execute_dig_cycle = function(pos, clicker) power_from_cables = power_from_cables / digtron.config.power_ratio test_fuel_burned = power_from_cables end - + if test_fuel_needed - test_fuel_burned > 0 then -- check for the available electrical power test_fuel_burned = test_fuel_burned + digtron.tap_batteries(layout.battery_holders, test_fuel_needed, true) @@ -257,31 +257,32 @@ digtron.execute_dig_cycle = function(pos, clicker) if (fuel_burning<0) then test_fuel_needed = test_fuel_needed - fuel_burning fuel_burning = 0 - end + end + local exhaust if (test_fuel_needed < test_fuel_burned) then exhaust = 0 -- all power needs met by electricity, don't blow smoke - else + else -- burn combustible fuel if not enough power test_fuel_burned = test_fuel_burned + digtron.burn(layout.fuelstores, test_fuel_needed - test_fuel_burned, true) exhaust = 1 -- burning fuel produces smoke end - + --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) end - + if test_fuel_needed > fuel_burning + test_fuel_burned then minetest.sound_play("buzzer", {gain=0.5, pos=pos}) return pos, S("Digtron needs more fuel."), 4 -- abort, don't dig and don't build. end - + if not can_build then minetest.get_meta(pos):set_string("waiting", "true") minetest.get_node_timer(pos):start(digtron.config.cycle_time) local return_string = nil - local return_code = 5 + return_code = 5 if test_build_return_code == 3 then 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" @@ -292,19 +293,19 @@ digtron.execute_dig_cycle = function(pos, clicker) return_code = 7 end return pos, return_string .. status_text, return_code --Abort, don't dig and don't build. - end + end ---------------------------------------------------------------------------------------------------------------------- - + -- All tests passed, ready to go for real! minetest.sound_play("construction", {gain=1.0, pos=pos}) -- if the player is standing within the array or next to it, move him too. local move_player = move_player_test(layout, clicker) - + -- damage the weak flesh if digtron.config.damage_hp > 0 and layout.diggers ~= nil then - for k, location in pairs(layout.diggers) do + for _, location in pairs(layout.diggers) do local target = minetest.get_node(location.pos) local targetdef = minetest.registered_nodes[target.name] if targetdef.damage_creatures ~= nil then @@ -312,7 +313,7 @@ digtron.execute_dig_cycle = function(pos, clicker) end end end - + --move the array layout:move_layout_image(dir) if not layout:write_layout_image(clicker) then @@ -324,18 +325,18 @@ digtron.execute_dig_cycle = function(pos, clicker) if move_player then clicker:moveto(vector.add(dir, clicker:get_pos()), true) end - + -- store or drop the products of the digger heads for _, itemname in pairs(items_dropped) do digtron.place_in_inventory(itemname, layout.inventories, oldpos) end digtron.award_item_dug(items_dropped, clicker) -- Achievements mod hook - + local building_fuel_cost = 0 local strange_failure = false -- execute_build on all digtron components that have one if layout.builders ~= nil then - for k, location in pairs(layout.builders) do + for _, location in pairs(layout.builders) do local target = minetest.get_node(location.pos) local targetdef = minetest.registered_nodes[target.name] if targetdef.execute_build ~= nil then @@ -346,7 +347,6 @@ digtron.execute_dig_cycle = function(pos, clicker) -- 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. strange_failure = true - build_return = (build_return * -1) - 1 elseif digtron.config.uses_resources then building_fuel_cost = building_fuel_cost + (digtron.config.build_cost * build_return) end @@ -355,9 +355,9 @@ digtron.execute_dig_cycle = function(pos, clicker) end end end - + if layout.auto_ejectors ~= nil then - for k, location in pairs(layout.auto_ejectors) do + for _, location in pairs(layout.auto_ejectors) do local target = minetest.get_node(location.pos) local targetdef = minetest.registered_nodes[target.name] if targetdef.execute_eject ~= nil then @@ -368,16 +368,16 @@ digtron.execute_dig_cycle = function(pos, clicker) end end - local status_text = "" + status_text = "" 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. minetest.sound_play("dingding", {gain=1.0, pos=pos}) minetest.sound_play("buzzer", {gain=0.5, pos=pos}) status_text = S("Digtron unexpectedly failed to execute one or more build operations, likely due to an inventory error.") .. "\n" end - + local total_fuel_cost = math.max(digging_fuel_cost + building_fuel_cost - power_from_cables, 0) - + -- actually burn the fuel needed fuel_burning = fuel_burning - total_fuel_cost if digtron.config.particle_effects and exhaust == 1 then @@ -391,7 +391,7 @@ digtron.execute_dig_cycle = function(pos, clicker) fuel_burning = fuel_burning + digtron.burn(layout.fuelstores, -fuel_burning, false) end end - + meta:set_float("fuel_burning", fuel_burning) meta:set_int("on_coal", exhaust) status_text = status_text .. S("Heat remaining in controller furnace: @1", math.floor(math.max(0, fuel_burning))) @@ -400,13 +400,15 @@ digtron.execute_dig_cycle = function(pos, clicker) for _, particles in pairs(particle_systems) do minetest.add_particlespawner(particles) end - + -- finally, dig out any nodes remaining to be dug. Some of these will have had their flag revoked because -- a builder put something there or because they're another digtron node. local node_to_dig, whether_to_dig = layout.nodes_dug:pop() while node_to_dig ~= nil do if whether_to_dig == true then - minetest.log("action", string.format("%s uses Digtron to dig %s at (%d, %d, %d)", clicker:get_player_name(), minetest.get_node(node_to_dig).name, node_to_dig.x, node_to_dig.y, node_to_dig.z)) + minetest.log("action", string.format( + "%s uses Digtron to dig %s at (%d, %d, %d)", clicker:get_player_name(), minetest.get_node(node_to_dig).name, node_to_dig.x, node_to_dig.y, node_to_dig.z) + ) minetest.remove_node(node_to_dig) end -- all of the digtron's nodes wind up in nodes_dug, so this is an ideal place to stick @@ -420,11 +422,11 @@ end -- Simplified version of the above method that only moves, and doesn't execute diggers or builders. digtron.execute_move_cycle = function(pos, clicker) - local meta = minetest.get_meta(pos) - local layout = DigtronLayout.create(pos, clicker) + local layout = digtron.DigtronLayout.create(pos, clicker) 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 return pos, status_text, return_code end @@ -436,11 +438,10 @@ digtron.execute_move_cycle = function(pos, clicker) local facing = minetest.get_node(pos).param2 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. local move_player = move_player_test(layout, clicker) - + -- test if any digtrons are obstructed by non-digtron nodes layout:move_layout_image(dir) if not layout:can_write_layout_image() then @@ -453,12 +454,12 @@ digtron.execute_move_cycle = function(pos, clicker) end minetest.sound_play("truck", {gain=1.0, pos=pos}) - + --move the array if not layout:write_layout_image(clicker) then return pos, "unrecoverable write_layout_image error", 1 end - + pos = vector.add(pos, dir) if move_player then clicker:moveto(vector.add(clicker:get_pos(), dir), true) @@ -480,11 +481,12 @@ digtron.execute_downward_dig_cycle = function(pos, clicker) 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 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 layout = DigtronLayout.create(pos, clicker) - local status_text, return_code = neighbour_test(layout, status_text, dir) + local layout = digtron.DigtronLayout.create(pos, clicker) + + status_text, return_code = neighbour_test(layout, status_text, dir) if return_code ~= 0 then return pos, status_text, return_code end @@ -494,21 +496,20 @@ digtron.execute_downward_dig_cycle = function(pos, clicker) return pos, size_check_error, 8 end - local controlling_coordinate = digtron.get_controlling_coordinate(pos, facing) - + ---------------------------------------------------------------------------------------------------------------------- - + local items_dropped = {} local digging_fuel_cost = 0 local particle_systems = {} - + -- execute the execute_dig method on all digtron components that have one -- This builds a set of nodes that will be dug and returns a list of products that will be generated -- but doesn't actually dig the nodes yet. That comes later. -- If we dug them now, sand would fall and some digtron nodes would die. if layout.diggers ~= nil then - for k, location in pairs(layout.diggers) do + for _, location in pairs(layout.diggers) do local target = minetest.get_node(location.pos) local targetdef = minetest.registered_nodes[target.name] if targetdef.execute_dig ~= nil then @@ -527,9 +528,9 @@ digtron.execute_downward_dig_cycle = function(pos, clicker) end end end - + ---------------------------------------------------------------------------------------------------------------------- - + -- test if any digtrons are obstructed by non-digtron nodes that haven't been marked -- as having been dug. local can_move = true @@ -554,16 +555,16 @@ digtron.execute_downward_dig_cycle = function(pos, clicker) end ---------------------------------------------------------------------------------------------------------------------- - + -- All tests passed, ready to go for real! minetest.sound_play("construction", {gain=1.0, pos=pos}) -- if the player is standing within the array or next to it, move him too. local move_player = move_player_test(layout, clicker) - + -- damage the weak flesh if digtron.config.damage_hp > 0 and layout.diggers ~= nil then - for k, location in pairs(layout.diggers) do + for _, location in pairs(layout.diggers) do local target = minetest.get_node(location.pos) local targetdef = minetest.registered_nodes[target.name] if targetdef.damage_creatures ~= nil then @@ -571,7 +572,7 @@ digtron.execute_downward_dig_cycle = function(pos, clicker) end end end - + --move the array layout:move_layout_image(digtron.facedir_to_down_dir(facing)) if not layout:write_layout_image(clicker) then @@ -583,15 +584,15 @@ digtron.execute_downward_dig_cycle = function(pos, clicker) if move_player then clicker:moveto(vector.add(clicker:get_pos(), dir), true) end - + -- store or drop the products of the digger heads for _, itemname in pairs(items_dropped) do digtron.place_in_inventory(itemname, layout.inventories, oldpos) end digtron.award_item_dug(items_dropped, clicker) -- Achievements mod hook - - local status_text = "" - + + status_text = "" + -- actually burn the fuel needed fuel_burning = fuel_burning - digging_fuel_cost if digtron.config.particle_effects and exhaust == 1 then @@ -614,13 +615,15 @@ digtron.execute_downward_dig_cycle = function(pos, clicker) for _, particles in pairs(particle_systems) do minetest.add_particlespawner(particles) end - + -- finally, dig out any nodes remaining to be dug. Some of these will have had their flag revoked because -- a builder put something there or because they're another digtron node. local node_to_dig, whether_to_dig = layout.nodes_dug:pop() while node_to_dig ~= nil do if whether_to_dig == true then - minetest.log("action", string.format("%s uses Digtron to dig %s at (%d, %d, %d)", clicker:get_player_name(), minetest.get_node(node_to_dig).name, node_to_dig.x, node_to_dig.y, node_to_dig.z)) + minetest.log("action", string.format( + "%s uses Digtron to dig %s at (%d, %d, %d)", clicker:get_player_name(), minetest.get_node(node_to_dig).name, node_to_dig.x, node_to_dig.y, node_to_dig.z) + ) minetest.remove_node(node_to_dig) end node_to_dig, whether_to_dig = layout.nodes_dug:pop() diff --git a/util_item_place_node.lua b/util_item_place_node.lua index ba6ff37..4a0fc12 100644 --- a/util_item_place_node.lua +++ b/util_item_place_node.lua @@ -36,13 +36,13 @@ digtron.whitelisted_on_place = function (item_name) for listed_item, value in pairs(digtron.builder_on_place_items) do if item_name == listed_item then return value end end - + for prefix, value in pairs(digtron.builder_on_place_prefixes) do if has_prefix(item_name, prefix) then return value end end - + if minetest.get_item_group(item_name, "digtron_on_place") > 0 then return true end - + return false end @@ -86,7 +86,7 @@ digtron.item_place_node = function(itemstack, placer, place_to, param2) pointed_thing.type = "node" pointed_thing.above = {x=place_to.x, y=place_to.y, z=place_to.z} pointed_thing.under = {x=place_to.x, y=place_to.y - 1, z=place_to.z} - + -- Handle node-specific on_place calls as best we can. if def.on_place and def.on_place ~= minetest.nodedef_default.on_place and digtron.whitelisted_on_place(item_name) then if def.paramtype2 == "facedir" then @@ -94,7 +94,7 @@ digtron.item_place_node = function(itemstack, placer, place_to, param2) elseif def.paramtype2 == "wallmounted" then pointed_thing.under = vector.add(place_to, minetest.wallmounted_to_dir(param2)) end - + -- pass a copy of the item stack parameter because on_place might modify it directly and then we can't tell if we succeeded or not -- though note that some mods do "creative_mode" handling within their own on_place methods, which makes it impossible for Digtron -- to know what to do in that case - if you're in creative_mode Digtron will place such items but it will think it failed and not @@ -107,10 +107,10 @@ digtron.item_place_node = function(itemstack, placer, place_to, param2) placed_node.param2 = param2 minetest.set_node(place_to, placed_node) end - + return returnstack, success end - + if minetest.registered_nodes[item_name] == nil then -- Permitted craft items are handled by the node-specific on_place call, above. -- if we are a craft item and we get here then we're not whitelisted and we should fail. @@ -118,7 +118,7 @@ digtron.item_place_node = function(itemstack, placer, place_to, param2) -- but this will protect us just in case. return itemstack, false end - + local oldnode = minetest.get_node_or_nil(place_to) --this should never happen, digtron is testing for adjacent unloaded nodes before getting here. @@ -141,7 +141,7 @@ digtron.item_place_node = function(itemstack, placer, place_to, param2) " can not be placed at " .. minetest.pos_to_string(place_to)) return itemstack, false end - + -- Add node and update minetest.add_node(place_to, newnode) @@ -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, -- which is called before Digtron does any of this building stuff, so it's not necessary -- to update it here. - local _, callback for _, callback in ipairs(minetest.registered_on_placenodes) do -- 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}