mirror of
https://github.com/minetest-mods/digtron.git
synced 2024-07-04 14:55:15 +02:00
fix another bunch
This commit is contained in:
parent
ef9a394cba
commit
6db2646b23
@ -18,5 +18,5 @@ read_globals = {
|
||||
"dump", "VoxelArea",
|
||||
|
||||
-- Deps
|
||||
"default"
|
||||
"default", "awards"
|
||||
}
|
||||
|
16
awards.lua
16
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
|
||||
|
@ -9,8 +9,8 @@
|
||||
-- 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,8 +111,7 @@ 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
|
||||
@ -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
|
100
class_layout.lua
100
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,21 +43,21 @@ 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
|
||||
|
||||
@ -79,12 +77,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 +94,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 +109,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 +145,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 +157,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 +170,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 +243,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 +278,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 +309,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 +323,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 +335,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,7 +353,7 @@ end
|
||||
-----------------------------------------------------------------------------------------------
|
||||
-- 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
|
||||
--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
|
||||
@ -394,14 +392,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 +412,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 +420,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 +450,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
|
||||
@ -481,13 +479,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,7 +500,7 @@ 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
|
||||
@ -515,10 +513,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 +524,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
|
||||
|
@ -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
|
||||
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,24 +37,24 @@ 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
|
||||
@ -63,8 +63,9 @@ function Pointset:pop()
|
||||
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
|
||||
|
||||
|
5
init.lua
5
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" )
|
||||
|
@ -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
|
||||
|
@ -115,7 +115,7 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields)
|
||||
|
||||
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
|
||||
|
||||
@ -145,7 +145,7 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields)
|
||||
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
|
||||
|
@ -23,7 +23,7 @@ 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
|
||||
@ -215,7 +215,7 @@ local loaded_on_recieve = function(pos, fields, sender, protected)
|
||||
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."))
|
||||
|
@ -113,7 +113,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})
|
||||
|
@ -55,7 +55,7 @@ local function eject_items(pos, node, player, eject_even_without_pipeworks, layo
|
||||
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.
|
||||
|
@ -67,7 +67,7 @@ minetest.register_node("digtron:power_connector", {
|
||||
end,
|
||||
|
||||
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
|
||||
if layout.builders ~= nil then
|
||||
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 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)
|
||||
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.
|
||||
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
|
||||
@ -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 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)
|
||||
if return_code ~= 0 then
|
||||
|
Loading…
Reference in New Issue
Block a user