fix another bunch

This commit is contained in:
BuckarooBanzay 2023-05-24 08:09:42 +02:00
parent ef9a394cba
commit 6db2646b23
13 changed files with 100 additions and 104 deletions

@ -18,5 +18,5 @@ read_globals = {
"dump", "VoxelArea", "dump", "VoxelArea",
-- Deps -- Deps
"default" "default", "awards"
} }

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

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

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

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

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

@ -54,7 +54,7 @@ minetest.register_node("digtron:axle", {
return return
end end
local image = DigtronLayout.create(pos, clicker) local image = digtron.DigtronLayout.create(pos, clicker)
if image:rotate_layout_image(node.param2) == false then if image:rotate_layout_image(node.param2) == false then
-- This should be impossible, but if self-validation fails abort. -- This should be impossible, but if self-validation fails abort.
return return

@ -115,7 +115,7 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields)
if fields.set then if fields.set then
-- copy current settings to all builders -- copy current settings to all builders
local layout = DigtronLayout.create(pos, sender) local layout = digtron.DigtronLayout.create(pos, sender)
if layout.builders ~= nil then if layout.builders ~= nil then
@ -145,7 +145,7 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields)
elseif fields.read then elseif fields.read then
-- make all builders perform read&save -- make all builders perform read&save
local layout = DigtronLayout.create(pos, sender) local layout = digtron.DigtronLayout.create(pos, sender)
if layout.builders ~= nil then if layout.builders ~= nil then
for k, location in pairs(layout.builders) do for k, location in pairs(layout.builders) do

@ -23,7 +23,7 @@ local player_permitted = function(pos, player)
end end
local store_digtron = function(pos, clicker, loaded_node_name, protected) local store_digtron = function(pos, clicker, loaded_node_name, protected)
local layout = DigtronLayout.create(pos, clicker) local layout = digtron.DigtronLayout.create(pos, clicker)
local protection_prefix = "" local protection_prefix = ""
local protection_suffix = "" local protection_suffix = ""
if protected then if protected then
@ -215,7 +215,7 @@ local loaded_on_recieve = function(pos, fields, sender, protected)
end end
local layout_string = meta:get_string("crated_layout") local layout_string = meta:get_string("crated_layout")
local layout = DigtronLayout.deserialize(layout_string) local layout = digtron.DigtronLayout.deserialize(layout_string)
if layout == nil then if layout == nil then
meta:set_string("infotext", infotext .. "\n" .. S("Unable to read layout from crate metadata, regrettably this Digtron may be corrupted.")) meta:set_string("infotext", infotext .. "\n" .. S("Unable to read layout from crate metadata, regrettably this Digtron may be corrupted."))

@ -113,7 +113,7 @@ minetest.register_node("digtron:duplicator", {
return return
end end
local layout = DigtronLayout.create(pos, sender) local layout = digtron.DigtronLayout.create(pos, sender)
if layout.contains_protected_node then if layout.contains_protected_node then
minetest.sound_play("buzzer", {gain=0.5, pos=pos}) minetest.sound_play("buzzer", {gain=0.5, pos=pos})

@ -55,7 +55,7 @@ local function eject_items(pos, node, player, eject_even_without_pipeworks, layo
end end
if layout == nil then if layout == nil then
layout = DigtronLayout.create(pos, player) layout = digtron.DigtronLayout.create(pos, player)
end end
-- Build a list of all the items that builder nodes want to use. -- Build a list of all the items that builder nodes want to use.

@ -67,7 +67,7 @@ minetest.register_node("digtron:power_connector", {
end, end,
on_receive_fields = function(pos, formname, fields, sender) on_receive_fields = function(pos, formname, fields, sender)
local layout = DigtronLayout.create(pos, sender) local layout = digtron.DigtronLayout.create(pos, sender)
local max_cost = 0 local max_cost = 0
if layout.builders ~= nil then if layout.builders ~= nil then
for _, node_image in pairs(layout.builders) do for _, node_image in pairs(layout.builders) do

@ -119,7 +119,7 @@ digtron.execute_dig_cycle = function(pos, clicker)
local status_text = S("Heat remaining in controller furnace: @1", math.floor(math.max(0, fuel_burning))) local status_text = S("Heat remaining in controller furnace: @1", math.floor(math.max(0, fuel_burning)))
local exhaust = meta:get_int("on_coal") local exhaust = meta:get_int("on_coal")
local layout = DigtronLayout.create(pos, clicker) local layout = digtron.DigtronLayout.create(pos, clicker)
local status_text, return_code = neighbour_test(layout, status_text, dir) local status_text, return_code = neighbour_test(layout, status_text, dir)
if return_code ~= 0 then if return_code ~= 0 then
@ -421,7 +421,7 @@ end
-- Simplified version of the above method that only moves, and doesn't execute diggers or builders. -- Simplified version of the above method that only moves, and doesn't execute diggers or builders.
digtron.execute_move_cycle = function(pos, clicker) digtron.execute_move_cycle = function(pos, clicker)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local layout = DigtronLayout.create(pos, clicker) local layout = digtron.DigtronLayout.create(pos, clicker)
local status_text = "" local status_text = ""
local status_text, return_code = neighbour_test(layout, status_text, nil) -- skip traction check for pusher by passing nil for direction local status_text, return_code = neighbour_test(layout, status_text, nil) -- skip traction check for pusher by passing nil for direction
@ -482,7 +482,7 @@ digtron.execute_downward_dig_cycle = function(pos, clicker)
local status_text = S("Heat remaining in controller furnace: @1", math.floor(math.max(0, fuel_burning))) local status_text = S("Heat remaining in controller furnace: @1", math.floor(math.max(0, fuel_burning)))
local exhaust = meta:get_int("on_coal") local exhaust = meta:get_int("on_coal")
local layout = DigtronLayout.create(pos, clicker) local layout = digtron.DigtronLayout.create(pos, clicker)
local status_text, return_code = neighbour_test(layout, status_text, dir) local status_text, return_code = neighbour_test(layout, status_text, dir)
if return_code ~= 0 then if return_code ~= 0 then