Improve mapgen, add grass, and include the fill tool.

This commit is contained in:
Signal 2026-01-15 18:54:28 -05:00
parent 1e897665bb
commit 4659a008ac
86 changed files with 1098 additions and 293 deletions

View file

@ -1,2 +0,0 @@
name = rgt_alloy_furnace
depends = rgt_machines

View file

@ -1,2 +0,0 @@
name = rgt_arc_furnace
depends = rgt_machines

View file

@ -1,2 +0,0 @@
name = rgt_casting_basin
depends = rgt_machines

View file

@ -1,2 +0,0 @@
name = rgt_furnace
depends = rgt_machines

View file

@ -1,171 +1,7 @@
--[[
List of machines:
- Arc furnace: Melts materials into their liquid form
--]]
rgt_machines = {
registered_machines = {},
networks = {}
}
local ns = rgt_machines
local db = minetest.get_mod_storage()
function ns.get_network(id)
return minetest.deserialize(db:get(id) or "return nil") or {supply = 0, demand = 0}
end
-- This abstracts away the use of multiple nodes for visual state feedback by
-- copying all node callbacks into each node, so that by default the machine
-- behaves exactly the same regardless of the underlying node type.
--[[
{
states = { ... }, -- Alternate visual states for this node. All properties of the resultant node may be overriden.
...
}
--]]
function ns.register_machine(name, def)
if not def.groups then
def.groups = {}
end
def.groups.machine = 1
def.groups.network_component = 1
def.groups.run_on_activate = 1
def.groups[name] = 1
-- Ensure that we update the network when a machine is placed or removed.
local _on_construct = def.on_construct
def.on_construct = function(pos)
ns.update_network(pos)
if _on_construct then _on_construct(pos) end
end
local _after_destruct = def.after_destruct
def.after_destruct = function(pos)
ns.update_network(pos)
if _after_destruct then _after_destruct(pos) end
end
ns.registered_machines[name] = def
for state, x in pairs(def.states) do
rgt.register_node(name.."_"..state, extend(table.copy(def), x))
end
end
-- Recursively propagate a network reassignment to all connected nodes (ignoring positions in `ignore`).
local function propagate_network_update(pos, net, ignore)
ignore[minetest.hash_node_position(pos)] = true
-- Store the network to the target node.
minetest.get_meta(pos):set_string("network", net)
-- Check each neighboring node for further propagation.
for _, x in ipairs(rgt.adjacent_neighbor_offests) do
-- If we already checked this node, we shouldn't consider it to avoid infinite recursion.
if not ignore[minetest.hash_node_position(pos +x)] then
local cid = minetest.get_node_raw(pos.x +x.x, pos.y +x.y, pos.z +x.z)
-- Ensure that this node can belong to a network and thus is a valid propagation target.
if minetest.get_item_group(rgt.content_ids_to_nodes[cid], "network_component") > 0 then
propagate_network_update(pos +x, net, ignore)
end
end
end
end
-- Called when a pos is added to or removed from a network.
-- Whether an addition or deletion is being performed depends on whether the node at `pos` belongs to the `network_component` group.
function ns.update_network(pos)
-- We're adding a node.
if minetest.get_item_group(minetest.get_node(pos).name, "network_component") > 0 then
-- Find all adjacent networks.
local net
local nets = {}
local num_nets = 0
for _, x in ipairs(rgt.adjacent_neighbor_offests) do
-- Ensure that this is a node that should have a network field.
if minetest.get_item_group(minetest.get_node(pos +x).name, "network_component") > 0 then
local n = minetest.get_meta(pos +x):get("network")
-- If the node doesn't have a network for some reason, we should give it one.
if not n or table.indexof(nets, n) == -1 then
-- Set our network to the first one we find.
if not net then
net = n
-- Store the positions of any other adjacent networks, so we can merge them with ours.
elseif net ~= n then
nets[#nets +1] = x
end
num_nets = num_nets +1
end
end
end
-- Propagate our chosen network to adjacent networks with different IDs.
-- If we didn't find any adjacent networks, this will just do nothing.
local ignore = {[minetest.hash_node_position(pos)] = true}
for _, x in ipairs(nets) do
propagate_network_update(pos +x, net, ignore)
end
-- Create a new unique network ID if none of our neighbors have one.
if not net then
net = string.format("net_%d_%06d", minetest.get_us_time(), math.random(100000, 999999))
end
-- Save our chosen network ID.
minetest.get_meta(pos):set_string("network", net)
-- We're removing a node.
else
-- Find all adjacent networks.
local net
local nets = {}
for _, x in ipairs(rgt.adjacent_neighbor_offests) do
-- Ensure that this is a node that should have a network field.
if minetest.get_item_group(minetest.get_node(pos +x).name, "network_component") > 0 then
local n = minetest.get_meta(pos +x):get("network")
nets[#nets +1] = x
end
end
-- We only need to ensure that these networks are unique, thus one of them can keep its original ID.
if #nets > 1 then table.remove(nets, 1) end
-- Create a new ID for each network and propagate it.
local pos_hash = minetest.hash_node_position(pos)
for _, x in ipairs(nets) do
net = string.format("net_%d_%06d", minetest.get_us_time(), math.random(100000, 999999))
-- Provide a different ignore table each time, to ensure that when the same network abuts this node on multiple edges, all touching nodes get the same network in the end.
propagate_network_update(pos +x, net, {[pos_hash] = true})
end
end
return true
end
function ns.add_network_supply(id, amount)
local net = ns.get_network(id)
net.supply = net.supply +amount
db:set_string(id, minetest.serialize(net))
end
function ns.remove_network_supply(id, amount)
ns.add_network_supply(id, -amount)
end
function ns.change_network_supply(id, from, to)
ns.add_network_supply(id, to -from)
end
function ns.add_network_demand(id, amount)
local net = ns.get_network(id)
net.demand = net.demand +amount
db:set_string(id, minetest.serialize(net))
end
function ns.remove_network_demand(id, amount)
ns.add_network_demand(id, -amount)
end
function ns.change_network_demand(id, from, to)
ns.add_network_demand(id, to -from)
end
include "fluids.lua"
include "cables.lua"
include "pipes.lua"

View file

@ -0,0 +1,2 @@
name = rgt_alloy_furnace
depends = rgt_machines_electric

View file

@ -0,0 +1,2 @@
name = rgt_arc_furnace
depends = rgt_machines_electric

View file

@ -0,0 +1,2 @@
name = rgt_casting_basin
depends = rgt_machines_electric

View file

@ -0,0 +1,2 @@
name = rgt_furnace
depends = rgt_machines_electric

View file

@ -12,7 +12,7 @@ local function push_fluid(pos, node, ctx)
local fluid_type = m:get "fluid_type"
local space = m:get_float "fluid_capacity" -fluid
-- If possible, cast the type of an empty tank to that of the fluid we're pushing; if, however, the tank already contains some amount of a different fluid type, we should not push anything.
-- If possible, cast the type of an empty tank to that of the fluid we're pushing; if, however, the tank already contains some amount of a different fluid type, we should not push anything.
if ctx.type ~= fluid_type then
if not fluid_type or fluid == 0 then
m:set_string("fluid_type", ctx.type)

View file

@ -0,0 +1,170 @@
--[[
List of machines:
- Arc furnace: Melts materials into their liquid form
--]]
local ns = rgt_machines
extend(ns, {
registered_machines = {},
networks = {}
})
local db = minetest.get_mod_storage()
function ns.get_network(id)
return minetest.deserialize(db:get(id) or "return nil") or {supply = 0, demand = 0}
end
-- This abstracts away the use of multiple nodes for visual state feedback by
-- copying all node callbacks into each node, so that by default the machine
-- behaves exactly the same regardless of the underlying node type.
--[[
{
states = { ... }, -- Alternate visual states for this node. All properties of the resultant node may be overriden.
...
}
--]]
function ns.register_machine(name, def)
if not def.groups then
def.groups = {}
end
def.groups.machine = 1
def.groups.network_component = 1
def.groups.run_on_activate = 1
def.groups[name] = 1
-- Ensure that we update the network when a machine is placed or removed.
local _on_construct = def.on_construct
def.on_construct = function(pos)
ns.update_network(pos)
if _on_construct then _on_construct(pos) end
end
local _after_destruct = def.after_destruct
def.after_destruct = function(pos)
ns.update_network(pos)
if _after_destruct then _after_destruct(pos) end
end
ns.registered_machines[name] = def
for state, x in pairs(def.states) do
rgt.register_node(name.."_"..state, extend(table.copy(def), x))
end
end
-- Recursively propagate a network reassignment to all connected nodes (ignoring positions in `ignore`).
local function propagate_network_update(pos, net, ignore)
ignore[minetest.hash_node_position(pos)] = true
-- Store the network to the target node.
minetest.get_meta(pos):set_string("network", net)
-- Check each neighboring node for further propagation.
for _, x in ipairs(rgt.adjacent_neighbor_offests) do
-- If we already checked this node, we shouldn't consider it to avoid infinite recursion.
if not ignore[minetest.hash_node_position(pos +x)] then
local cid = minetest.get_node_raw(pos.x +x.x, pos.y +x.y, pos.z +x.z)
-- Ensure that this node can belong to a network and thus is a valid propagation target.
if minetest.get_item_group(rgt.content_ids_to_nodes[cid], "network_component") > 0 then
propagate_network_update(pos +x, net, ignore)
end
end
end
end
-- Called when a pos is added to or removed from a network.
-- Whether an addition or deletion is being performed depends on whether the node at `pos` belongs to the `network_component` group.
function ns.update_network(pos)
-- We're adding a node.
if minetest.get_item_group(minetest.get_node(pos).name, "network_component") > 0 then
-- Find all adjacent networks.
local net
local nets = {}
local num_nets = 0
for _, x in ipairs(rgt.adjacent_neighbor_offests) do
-- Ensure that this is a node that should have a network field.
if minetest.get_item_group(minetest.get_node(pos +x).name, "network_component") > 0 then
local n = minetest.get_meta(pos +x):get("network")
-- If the node doesn't have a network for some reason, we should give it one.
if not n or table.indexof(nets, n) == -1 then
-- Set our network to the first one we find.
if not net then
net = n
-- Store the positions of any other adjacent networks, so we can merge them with ours.
elseif net ~= n then
nets[#nets +1] = x
end
num_nets = num_nets +1
end
end
end
-- Propagate our chosen network to adjacent networks with different IDs.
-- If we didn't find any adjacent networks, this will just do nothing.
local ignore = {[minetest.hash_node_position(pos)] = true}
for _, x in ipairs(nets) do
propagate_network_update(pos +x, net, ignore)
end
-- Create a new unique network ID if none of our neighbors have one.
if not net then
net = string.format("net_%d_%06d", minetest.get_us_time(), math.random(100000, 999999))
end
-- Save our chosen network ID.
minetest.get_meta(pos):set_string("network", net)
-- We're removing a node.
else
-- Find all adjacent networks.
local net
local nets = {}
for _, x in ipairs(rgt.adjacent_neighbor_offests) do
-- Ensure that this is a node that should have a network field.
if minetest.get_item_group(minetest.get_node(pos +x).name, "network_component") > 0 then
local n = minetest.get_meta(pos +x):get("network")
nets[#nets +1] = x
end
end
-- We only need to ensure that these networks are unique, thus one of them can keep its original ID.
if #nets > 1 then table.remove(nets, 1) end
-- Create a new ID for each network and propagate it.
local pos_hash = minetest.hash_node_position(pos)
for _, x in ipairs(nets) do
net = string.format("net_%d_%06d", minetest.get_us_time(), math.random(100000, 999999))
-- Provide a different ignore table each time, to ensure that when the same network abuts this node on multiple edges, all touching nodes get the same network in the end.
propagate_network_update(pos +x, net, {[pos_hash] = true})
end
end
return true
end
function ns.add_network_supply(id, amount)
local net = ns.get_network(id)
net.supply = net.supply +amount
db:set_string(id, minetest.serialize(net))
end
function ns.remove_network_supply(id, amount)
ns.add_network_supply(id, -amount)
end
function ns.change_network_supply(id, from, to)
ns.add_network_supply(id, to -from)
end
function ns.add_network_demand(id, amount)
local net = ns.get_network(id)
net.demand = net.demand +amount
db:set_string(id, minetest.serialize(net))
end
function ns.remove_network_demand(id, amount)
ns.add_network_demand(id, -amount)
end
function ns.change_network_demand(id, from, to)
ns.add_network_demand(id, to -from)
end
include "fluids.lua"
include "cables.lua"
include "pipes.lua"

View file

@ -0,0 +1,2 @@
name = rgt_machines_electric
depends = rgt_machines

View file

@ -0,0 +1,2 @@
name = rgt_steam_generator
depends = rgt_machines_electric

View file

@ -0,0 +1,22 @@
local ns = rgt_machines
ns.components = {}
--[[
{
name = "...", -- The component's name.
attach_points
}
--]]
function ns.register_component(def)
ns.components[def.name] = def
end
function ns.register_plate(name, def)
rgt.register_item(name, def)
end
rgt.register_node("hand_crank", {
mesh = "rgt_hand_crank.gltf"
})

View file

@ -0,0 +1,2 @@
name = rgt_machines_mechanical
depends = rgt_machines

View file

@ -1,2 +0,0 @@
name = rgt_steam_generator
depends = rgt_machines