Improve mapgen, add grass, and include the fill tool.
0
mods/rgt_machines/rgt_machines_electric/modpack.conf
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
name = rgt_alloy_furnace
|
||||
depends = rgt_machines_electric
|
||||
145
mods/rgt_machines/rgt_machines_electric/rgt_arc_furnace/init.lua
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
|
||||
local function can_work(node, m, inv)
|
||||
-- Do we have an input item?
|
||||
local input = inv:get_stack("input", 1)
|
||||
if input:get_count() > 0 then
|
||||
-- Would melting this item exceed our fluid capacity?
|
||||
local fluid = m:get_float "fluid"
|
||||
local fluid_type = m:get "fluid_type"
|
||||
local capacity = m:get_float "fluid_capacity"
|
||||
if capacity -fluid >= 1 and (fluid == 0 or input:get_definition().material == fluid_type) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function update_formspec(m, progress)
|
||||
progress = progress or m:get_int "progress"
|
||||
local fluid = m:get_float "fluid"
|
||||
local capacity = m:get_float "fluid_capacity"
|
||||
local progressbar = progress == 0 and "rgt_progress_bg.png^[transformR270" or "rgt_progress_bg.png^[lowpart:"..progress..":rgt_progress_bg_active.png^[transformR270"
|
||||
local fluidcontainer = fluid == 0 and "rgt_fluid_container_bg.png" or "rgt_fluid_container_bg.png^[lowpart:"..(fluid /capacity *100)..":rgt_fluid_container_bg_filled.png"
|
||||
local fs = {"\
|
||||
formspec_version[10]\
|
||||
size[12,12]\
|
||||
", ui.list("context", "input", 2, 2, 1, 1), "\
|
||||
image[4,2;1,1;", progressbar, "]\
|
||||
image[7,1;1,3;", minetest.formspec_escape(fluidcontainer), "]\
|
||||
label[0.5,0.5;", fluid, " / ", capacity, "]\
|
||||
"}
|
||||
fs[#fs +1] = ui.list("current_player", "main", 1.125, 6.5, 8, 4)
|
||||
fs[#fs +1] = "\
|
||||
listring[]"
|
||||
|
||||
m:set_string("formspec", table.concat(fs))
|
||||
end
|
||||
|
||||
local function deactivate(pos, node, m)
|
||||
m:set_string("active", "false")
|
||||
m:set_int("progress", 0)
|
||||
update_formspec(m)
|
||||
node.name = "arc_furnace_idle"
|
||||
minetest.swap_node(pos, node)
|
||||
end
|
||||
|
||||
local function update(pos, elapsed)
|
||||
local node = minetest.get_node(pos)
|
||||
local m = minetest.get_meta(pos)
|
||||
local inv = m:get_inventory()
|
||||
|
||||
local active = m:get_string("active") == "true"
|
||||
|
||||
if can_work(node, m, inv) then
|
||||
if not active then
|
||||
active = true
|
||||
m:set_string("active", "true")
|
||||
node.name = "arc_furnace_active"
|
||||
minetest.swap_node(pos, node)
|
||||
end
|
||||
|
||||
local progress = m:get_int("progress") +50
|
||||
|
||||
if progress >= 100 then
|
||||
local fluid = m:get_float "fluid"
|
||||
fluid = fluid +1
|
||||
if fluid >= 2 then
|
||||
fluid = fluid -rgt_machines.push_fluid(pos, m:get "fluid_type", fluid)
|
||||
end
|
||||
m:set_float("fluid", fluid)
|
||||
|
||||
-- Consume an item.
|
||||
local s = inv:get_stack("input", 1)
|
||||
s:take_item()
|
||||
inv:set_stack("input", 1, s)
|
||||
|
||||
m:set_string("fluid_type", s:get_definition().material)
|
||||
|
||||
progress = 0
|
||||
end
|
||||
m:set_int("progress", progress)
|
||||
|
||||
update_formspec(m, progress)
|
||||
|
||||
elseif active then
|
||||
active = false
|
||||
deactivate(pos, node, m)
|
||||
end
|
||||
|
||||
return true--minetest.get_node_timer(pos):start(active and 1 or 1)
|
||||
end
|
||||
|
||||
rgt_machines.register_machine("arc_furnace", {
|
||||
states = {
|
||||
idle = {
|
||||
tiles = {"rgt_iron_block.png", "rgt_iron_block.png", "rgt_iron_block.png", "rgt_iron_block.png", "rgt_iron_block.png", "rgt_arc_furnace_front.png"}
|
||||
},
|
||||
active = {
|
||||
tiles = {"rgt_iron_block.png", "rgt_iron_block.png", "rgt_iron_block.png", "rgt_iron_block.png", "rgt_iron_block.png", "rgt_arc_furnace_front_active.png"},
|
||||
drop = "arc_furnace_idle",
|
||||
}
|
||||
},
|
||||
paramtype2 = "4dir",
|
||||
groups = {dig_immediate = 3},
|
||||
on_construct = function(pos)
|
||||
local m = minetest.get_meta(pos)
|
||||
local inv = m:get_inventory()
|
||||
inv:set_size("input", 1)
|
||||
|
||||
m:set_float("fluid_capacity", 10)
|
||||
m:set_string("active", "false")
|
||||
|
||||
update_formspec(m)
|
||||
|
||||
minetest.get_node_timer(pos):start(1)
|
||||
end,
|
||||
on_destruct = function(pos)
|
||||
local m = minetest.get_meta(pos)
|
||||
local inv = m:get_inventory()
|
||||
for i = 1, inv:get_size("input") do
|
||||
local item = minetest.add_item(pos, inv:get_stack("input", i))
|
||||
if item then
|
||||
item:set_velocity(vector.random_direction() *math.random(2, 3))
|
||||
end
|
||||
end
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, list, idx, s, p)
|
||||
local inv = minetest.get_meta(pos):get_inventory()
|
||||
local meltable = minetest.registered_items[s:get_name()].groups.arc_furnace_meltable
|
||||
if meltable then
|
||||
if inv:room_for_item("input", s) then
|
||||
return s:get_count()
|
||||
elseif inv:room_for_item("input", s:take_item()) then
|
||||
return s:get_stack_max() -inv:get_stack("input", 1):get_count()
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end,
|
||||
on_metadata_inventory_put = function(pos, list)
|
||||
|
||||
end,
|
||||
on_metadata_inventory_take = function(pos, list)
|
||||
|
||||
end,
|
||||
on_timer = update
|
||||
})
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
name = rgt_arc_furnace
|
||||
depends = rgt_machines_electric
|
||||
|
After Width: | Height: | Size: 116 B |
|
After Width: | Height: | Size: 357 B |
|
After Width: | Height: | Size: 393 B |
|
After Width: | Height: | Size: 116 B |
|
After Width: | Height: | Size: 116 B |
|
|
@ -0,0 +1,167 @@
|
|||
local ns = rgt_machines
|
||||
|
||||
ns.casting_recipes = {
|
||||
{
|
||||
name = "plate",
|
||||
label = "Plate"
|
||||
},
|
||||
{
|
||||
name = "rod",
|
||||
label = "Rod"
|
||||
},
|
||||
{
|
||||
name = "gear",
|
||||
label = "Gear"
|
||||
},
|
||||
}
|
||||
|
||||
local function can_work(node, m, inv)
|
||||
-- Do we have an input item?
|
||||
local fluid = m:get_float "fluid"
|
||||
if m:contains "recipe" and m:contains "fluid_type" and fluid > 0 and inv:get_stack("output", 1):get_free_space() > 0 then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function update_formspec(m, progress)
|
||||
progress = progress or m:get_int "progress"
|
||||
local fluid_type = m:get_string "fluid_type"
|
||||
local fluid = m:get_float "fluid"
|
||||
local capacity = m:get_int "fluid_capacity"
|
||||
local progressbar = progress == 0 and "rgt_progress_bg.png^[transformR270" or "rgt_progress_bg.png^[lowpart:"..progress..":rgt_progress_bg_active.png^[transformR270"
|
||||
local fluidcontainer = fluid == 0 and "rgt_fluid_container_bg.png" or "rgt_fluid_container_bg.png^[lowpart:"..(fluid /capacity *100)..":rgt_fluid_container_bg_filled.png"
|
||||
local fs = {"\
|
||||
formspec_version[10]\
|
||||
size[12,12]\
|
||||
image[3.5,2;1,1;", progressbar, "]\
|
||||
image[2,1;1,3;", minetest.formspec_escape(fluidcontainer), "]\
|
||||
label[0.5,0.5;", fluid, " / ", capacity, "]\
|
||||
", ui.list("context", "output", 5, 2, 1, 1), "\
|
||||
"}
|
||||
fs[#fs +1] = ui.list("current_player", "main", 1.125, 6.5, 8, 4)
|
||||
fs[#fs +1] = "\
|
||||
listring[]"
|
||||
|
||||
local recipe = m:get "recipe"
|
||||
|
||||
local x = 0
|
||||
local y = 0
|
||||
for _, r in ipairs(ns.casting_recipes) do
|
||||
if r.name == recipe then
|
||||
fs[#fs +1] = "style[select_recipe_"..r.name..";bgimg=rgt_other_button_bg.png]"
|
||||
end
|
||||
fs[#fs +1] = "image_button["..(x *1.1 +7)..","..(y +1.5)..";1,1;rgt_cast_"..r.name..".png;select_recipe_"..r.name..";]\
|
||||
tooltip[select_recipe_"..r.name..";"..(r.label or r.name).."]\
|
||||
"
|
||||
x = x +1
|
||||
end
|
||||
|
||||
m:set_string("formspec", table.concat(fs))
|
||||
end
|
||||
|
||||
local function activate(pos, node, m)
|
||||
m:set_string("active", "true")
|
||||
node.name = "casting_basin_active"
|
||||
minetest.swap_node(pos, node)
|
||||
end
|
||||
|
||||
local function deactivate(pos, node, m)
|
||||
m:set_string("active", "false")
|
||||
m:set_int("progress", 0)
|
||||
update_formspec(m)
|
||||
node.name = "casting_basin_idle"
|
||||
minetest.swap_node(pos, node)
|
||||
end
|
||||
|
||||
local function update(pos, elapsed)
|
||||
local node = minetest.get_node(pos)
|
||||
local m = minetest.get_meta(pos)
|
||||
local inv = m:get_inventory()
|
||||
|
||||
local active = m:get_string("active") == "true"
|
||||
|
||||
if can_work(node, m, inv) then
|
||||
if not active then
|
||||
active = true
|
||||
activate(pos, node, m)
|
||||
end
|
||||
|
||||
local progress = m:get_int("progress") +20
|
||||
|
||||
if progress >= 100 then
|
||||
local fluid = m:get_float "fluid"
|
||||
fluid = fluid -1
|
||||
m:set_float("fluid", fluid)
|
||||
|
||||
local s = inv:get_stack("output", 1)
|
||||
if s and s:get_count() > 0 then
|
||||
s:set_count(s:get_count() +1)
|
||||
else
|
||||
s = ItemStack(m:get_string("fluid_type").."_"..m:get_string("recipe"))
|
||||
end
|
||||
inv:set_stack("output", 1, s)
|
||||
|
||||
progress = 0
|
||||
end
|
||||
m:set_int("progress", progress)
|
||||
|
||||
update_formspec(m, progress)
|
||||
|
||||
elseif active then
|
||||
active = false
|
||||
deactivate(pos, node, m)
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
rgt_machines.register_machine("casting_basin", {
|
||||
states = {
|
||||
idle = {
|
||||
tiles = {"rgt_iron_block.png", "rgt_iron_block.png", "rgt_iron_block.png", "rgt_iron_block.png", "rgt_iron_block.png", "rgt_casting_basin_front.png"}
|
||||
},
|
||||
active = {
|
||||
tiles = {"rgt_iron_block.png", "rgt_iron_block.png", "rgt_iron_block.png", "rgt_iron_block.png", "rgt_iron_block.png", "rgt_casting_basin_front_active.png"},
|
||||
drop = "casting_basin_idle",
|
||||
}
|
||||
},
|
||||
paramtype2 = "4dir",
|
||||
groups = {dig_immediate = 3, fluid_sink = 1},
|
||||
on_construct = function(pos)
|
||||
local m = minetest.get_meta(pos)
|
||||
local inv = m:get_inventory()
|
||||
inv:set_size("output", 1)
|
||||
|
||||
m:set_int("fluid_capacity", 10)
|
||||
m:set_string("active", "false")
|
||||
|
||||
update_formspec(m)
|
||||
|
||||
minetest.get_node_timer(pos):start(1)
|
||||
end,
|
||||
on_destruct = function(pos)
|
||||
local m = minetest.get_meta(pos)
|
||||
local inv = m:get_inventory()
|
||||
for i = 1, inv:get_size("input") do
|
||||
local item = minetest.add_item(pos, inv:get_stack("input", i))
|
||||
if item then
|
||||
item:set_velocity(vector.random_direction() *math.random(2, 3))
|
||||
end
|
||||
end
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, list, idx, s, p)
|
||||
return 0
|
||||
end,
|
||||
on_receive_fields = function(pos, form, data, p)
|
||||
for k, v in pairs(data) do
|
||||
if k:find "^select_recipe_" then
|
||||
local m = minetest.get_meta(pos)
|
||||
local recipe = k:match "^select_recipe_(.*)"
|
||||
m:set_string("recipe", recipe)
|
||||
update_formspec(m)
|
||||
end
|
||||
end
|
||||
end,
|
||||
on_timer = update
|
||||
})
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
name = rgt_casting_basin
|
||||
depends = rgt_machines_electric
|
||||
|
After Width: | Height: | Size: 167 B |
|
After Width: | Height: | Size: 173 B |
|
After Width: | Height: | Size: 107 B |
|
After Width: | Height: | Size: 262 B |
|
After Width: | Height: | Size: 303 B |
109
mods/rgt_machines/rgt_machines_electric/rgt_furnace/init.lua
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
|
||||
local function update_formspec(pos)
|
||||
|
||||
end
|
||||
|
||||
local function on_input(pos, m, inv)
|
||||
|
||||
end
|
||||
|
||||
local function on_add_fuel(pos, m, inv)
|
||||
|
||||
end
|
||||
|
||||
local function destination_list(s)
|
||||
return minetest.get_item_group(s:get_name(), "furnace_fuel") > 0 and "fuel" or "input"
|
||||
end
|
||||
|
||||
local function can_run(pos, m, inv)
|
||||
return false
|
||||
end
|
||||
|
||||
rgt_machines.register_machine("fuel_furnace", {
|
||||
states = {
|
||||
idle = {
|
||||
tiles = {"rgt_stone.png"},
|
||||
},
|
||||
active = {
|
||||
tiles = {"rgt_stone.png"},
|
||||
}
|
||||
},
|
||||
on_construct = function(pos)
|
||||
local m = minetest.get_meta(pos)
|
||||
local inv = m:get_inventory()
|
||||
inv:set_size("input", 1)
|
||||
inv:set_size("output", 1)
|
||||
-- Dummy list to handle Shift-adding properly.
|
||||
inv:set_size("sort", 1)
|
||||
inv:set_size("fuel", 1)
|
||||
|
||||
|
||||
end,
|
||||
get_gui = function(pos)
|
||||
local loc = "nodemeta:"..pos.x..","..pos.y..","..pos.z
|
||||
local fs = "\
|
||||
formspec_version[10]\
|
||||
size[12,12]\
|
||||
\
|
||||
image["..(2 -0.0625)..","..(2 -0.0625)..";1.14,1.14;rgt_other_button_bg.png;8,8]\
|
||||
list["..loc..";input;2,2;1,1;]\
|
||||
\
|
||||
image["..(5 -0.0625)..","..(3 -0.0625)..";1.14,1.14;rgt_other_button_bg.png;8,8]\
|
||||
list["..loc..";output;5,3;1,1;]\
|
||||
\
|
||||
image["..(2 -0.0625)..","..(4 -0.0625)..";1.14,1.14;rgt_other_button_bg.png;8,8]\
|
||||
list["..loc..";fuel;2,4;1,1;]\
|
||||
"
|
||||
for x = 0, 7 do
|
||||
for y = 0, 3 do
|
||||
fs = fs.."\
|
||||
image["..(x *1.25 +1.125 -0.0625)..","..(y *1.25 +6.5 -0.0625)..";1.14,1.14;rgt_other_button_bg.png;8,8]\
|
||||
"
|
||||
end
|
||||
end
|
||||
fs = fs.."\
|
||||
list[current_player;main;1.125,6.5;8,4;]\
|
||||
\
|
||||
listring["..loc..";output]\
|
||||
listring[current_player;main]\
|
||||
listring["..loc..";sort]\
|
||||
listring[current_player;main]\
|
||||
listring["..loc..";input]\
|
||||
listring[current_player;main]\
|
||||
listring["..loc..";fuel]\
|
||||
listring[current_player;main]\
|
||||
"
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, list, idx, s, p)
|
||||
local inv = minetest.get_meta(pos):get_inventory()
|
||||
if list == "output" then
|
||||
return 0
|
||||
elseif list == "input" then
|
||||
return s:get_count()
|
||||
elseif list == "fuel" then
|
||||
return minetest.get_item_group(s:get_name(), "furnace_fuel") > 0 and s:get_count() or 0
|
||||
elseif list == "sort" then
|
||||
local dst = destination_list(s)
|
||||
if dst then
|
||||
-- Add everything if we can.
|
||||
if inv:room_for_item(dst, s) then
|
||||
return s:get_count()
|
||||
-- If not, and the stacks are compatible, add as much as possible.
|
||||
elseif inv:room_for_item(dst, s:take_item()) then
|
||||
return s:get_stack_max() -inv:get_stack(dst, 1):get_count()
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
return 0
|
||||
end,
|
||||
on_metadata_inventory_put = function(pos, list, idx, s, p)
|
||||
if list == "sort" then
|
||||
local inv = minetest.get_meta(pos):get_inventory()
|
||||
local dst = destination_list(s)
|
||||
inv:add_item(dst, s)
|
||||
-- Ensure the sorter list never has anything in it.
|
||||
inv:set_stack("sort", 1, ItemStack(""))
|
||||
end
|
||||
end
|
||||
})
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
name = rgt_furnace
|
||||
depends = rgt_machines_electric
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
local ns = rgt_machines
|
||||
|
||||
local nodebox = {
|
||||
type = "connected",
|
||||
disconnected = {1/8, 1/8, 1/8, -1/8, -1/8, -1/8},
|
||||
connect_top = {1/8, 1/2, 1/8, -1/8, -1/8, -1/8},
|
||||
connect_bottom = {1/8, 1/8, 1/8, -1/8, -1/2, -1/8},
|
||||
connect_front = {1/8, 1/8, 1/8, -1/8, -1/8, -1/2},
|
||||
connect_left = {1/8, 1/8, 1/8, -1/2, -1/8, -1/8},
|
||||
connect_back = {1/8, 1/8, 1/2, -1/8, -1/8, -1/8},
|
||||
connect_right = {1/2, 1/8, 1/8, -1/8, -1/8, -1/8}
|
||||
}
|
||||
|
||||
|
||||
function ns.register_cable(type, def)
|
||||
rgt.register_node("cable_"..type, {
|
||||
drawtype = "nodebox",
|
||||
node_box = nodebox,
|
||||
connects_to = {"group:cable", "group:machine"},
|
||||
tiles = {"rgt_cable_"..type..".png"},
|
||||
groups = {cable = 1, dig_immediate = 3, network_component = 1},
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
on_construct = function(pos)
|
||||
ns.update_network(pos)
|
||||
end,
|
||||
after_destruct = function(pos)
|
||||
ns.update_network(pos)
|
||||
end,
|
||||
cable_def = def
|
||||
})
|
||||
end
|
||||
|
||||
ns.register_cable("copper", {
|
||||
resistance = 0,
|
||||
max_transference = 200
|
||||
})
|
||||
-- //lua say(dump(minetest.get_meta(rgt.players.singleplayer.pos:round()):to_table()))
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
local ns = rgt_machines
|
||||
|
||||
-- The recursive funtion that executes a request to push fluid to a network.
|
||||
local function push_fluid(pos, node, ctx)
|
||||
-- Indicate that this node has now been checked.
|
||||
ctx.ignore[minetest.hash_node_position(pos)] = true
|
||||
|
||||
-- If the node is a sink, add as much fluid to it as we can.
|
||||
if minetest.get_item_group(node, "fluid_sink") > 0 then
|
||||
local m = minetest.get_meta(pos)
|
||||
local fluid = m:get_float "fluid"
|
||||
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 ctx.type ~= fluid_type then
|
||||
if not fluid_type or fluid == 0 then
|
||||
m:set_string("fluid_type", ctx.type)
|
||||
else
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- Push as much fluid into the receiver's tank as we can, and decrement the amount awaiting transfer appropriately.
|
||||
if space >= ctx.amount then
|
||||
m:set_float("fluid", fluid +ctx.amount)
|
||||
ctx.amount = 0
|
||||
else
|
||||
m:set_float("fluid", fluid +space)
|
||||
ctx.amount = ctx.amount -space
|
||||
end
|
||||
-- If the node is a pipe, continue pushing to its neighbors.
|
||||
elseif minetest.get_item_group(node, "pipe") > 0 then
|
||||
for _, x in ipairs(rgt.adjacent_neighbor_offests) do
|
||||
-- If we've no fluid left to push, we can just stop.
|
||||
if ctx.amount <= 0 then break end
|
||||
|
||||
if not ctx.ignore[minetest.hash_node_position(pos +x)] then
|
||||
push_fluid(pos +x, node, ctx)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Pushes fluid from `pos` to any connected fluid network.
|
||||
-- Returns the amount of fluid that was successfully pushed.
|
||||
function ns.push_fluid(pos, type, amount)
|
||||
-- Create a master storage table for this push request.
|
||||
local ctx = {
|
||||
ignore = {minetest.hash_node_position(pos)}, -- Nodes we have already checked.
|
||||
type = type, -- The type of the fluid we are sending.
|
||||
amount = amount -- How much fluid remains to be sent.
|
||||
}
|
||||
-- Recursively dispatch the request to all neighbors in sequence.
|
||||
for _, x in ipairs(rgt.adjacent_neighbor_offests) do
|
||||
if ctx.amount > 0 and not ctx.ignore[minetest.hash_node_position(pos +x)] then
|
||||
push_fluid(pos +x, minetest.get_node(pos +x).name, ctx)
|
||||
end
|
||||
end
|
||||
-- Return the amount we were able to transfer (amount requested minus amount left).
|
||||
return amount -ctx.amount
|
||||
end
|
||||
|
||||
-- Pulls fluid into `pos` from any connected fluid network.
|
||||
-- Returns false if no fluid could be pulled, and the amount pulled otherwise.
|
||||
function ns.pull_fluid(pos)
|
||||
|
||||
end
|
||||
|
||||
function ns.register_fluid_tank(name, def)
|
||||
rgt.register_node("fluid_tank_"..name, {
|
||||
|
||||
})
|
||||
end
|
||||
|
|
@ -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"
|
||||
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
name = rgt_machines_electric
|
||||
depends = rgt_machines
|
||||
|
|
@ -0,0 +1 @@
|
|||
{"asset":{"version":"2.0","generator":"Blockbench 4.12.5 glTF exporter"},"scenes":[{"nodes":[1],"name":"blockbench_export"}],"scene":0,"nodes":[{"name":"cube","mesh":0},{"children":[0]}],"bufferViews":[{"buffer":0,"byteOffset":0,"byteLength":288,"target":34962,"byteStride":12},{"buffer":0,"byteOffset":288,"byteLength":288,"target":34962,"byteStride":12},{"buffer":0,"byteOffset":576,"byteLength":192,"target":34962,"byteStride":8},{"buffer":0,"byteOffset":768,"byteLength":72,"target":34963}],"buffers":[{"byteLength":840,"uri":"data:application/octet-stream;base64,AADwPwAA8D8AAKBAAADwPwAA8D8AAKDAAADwPwAA8L8AAKBAAADwPwAA8L8AAKDAAADwvwAA8D8AAKDAAADwvwAA8D8AAKBAAADwvwAA8L8AAKDAAADwvwAA8L8AAKBAAADwvwAA8D8AAKDAAADwPwAA8D8AAKDAAADwvwAA8D8AAKBAAADwPwAA8D8AAKBAAADwvwAA8L8AAKBAAADwPwAA8L8AAKBAAADwvwAA8L8AAKDAAADwPwAA8L8AAKDAAADwvwAA8D8AAKBAAADwPwAA8D8AAKBAAADwvwAA8L8AAKBAAADwPwAA8L8AAKBAAADwPwAA8D8AAKDAAADwvwAA8D8AAKDAAADwPwAA8L8AAKDAAADwvwAA8L8AAKDAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIA+AAAAAAAAAAAAAMA9AACAPgAAwD0AAAAAAADAPQAAgD4AAMA9AAAAAAAAQD4AAIA+AABAPgAAwD0AAOA+AAAAAAAA4D4AAMA9AABAPgAAAAAAAEA+AABAPgAAQD4AAMA9AABAPgAAQD4AAOA+AADAPQAA4D4AAKA+AACwPgAA0D4AALA+AACgPgAA4D4AANA+AADgPgAAoD4AAIA+AADQPgAAgD4AAKA+AACwPgAA0D4AALA+AAACAAEAAgADAAEABAAGAAUABgAHAAUACAAKAAkACgALAAkADAAOAA0ADgAPAA0AEAASABEAEgATABEAFAAWABUAFgAXABUA"}],"accessors":[{"bufferView":0,"componentType":5126,"count":24,"max":[1.875,1.875,5],"min":[-1.875,-1.875,-5],"type":"VEC3"},{"bufferView":1,"componentType":5126,"count":24,"max":[1,1,1],"min":[-1,-1,-1],"type":"VEC3"},{"bufferView":2,"componentType":5126,"count":24,"max":[0.40625,0.4375],"min":[0,0],"type":"VEC2"},{"bufferView":3,"componentType":5123,"count":36,"max":[23],"min":[0],"type":"SCALAR"}],"materials":[{"pbrMetallicRoughness":{"metallicFactor":0,"roughnessFactor":1,"baseColorTexture":{"index":0}},"alphaMode":"MASK","alphaCutoff":0.05,"doubleSided":true}],"textures":[{"sampler":0,"source":0,"name":"rgt_pipe_straight"}],"samplers":[{"magFilter":9728,"minFilter":9728,"wrapS":33071,"wrapT":33071}],"images":[{"mimeType":"image/png","name":"rgt_pipe_straight.png","uri":"rgt_pipe_straight.png"}],"meshes":[{"primitives":[{"mode":4,"attributes":{"POSITION":0,"NORMAL":1,"TEXCOORD_0":2},"indices":3,"material":0}]}]}
|
||||
|
|
@ -0,0 +1 @@
|
|||
{"asset":{"version":"2.0","generator":"Blockbench 4.12.5 glTF exporter"},"scenes":[{"nodes":[2],"name":"blockbench_export"}],"scene":0,"nodes":[{"name":"cube","mesh":0},{"name":"cube","mesh":1},{"children":[0,1]}],"bufferViews":[{"buffer":0,"byteOffset":0,"byteLength":288,"target":34962,"byteStride":12},{"buffer":0,"byteOffset":288,"byteLength":288,"target":34962,"byteStride":12},{"buffer":0,"byteOffset":576,"byteLength":192,"target":34962,"byteStride":8},{"buffer":0,"byteOffset":768,"byteLength":72,"target":34963},{"buffer":0,"byteOffset":840,"byteLength":288,"target":34962,"byteStride":12},{"buffer":0,"byteOffset":1128,"byteLength":288,"target":34962,"byteStride":12},{"buffer":0,"byteOffset":1416,"byteLength":192,"target":34962,"byteStride":8},{"buffer":0,"byteOffset":1608,"byteLength":72,"target":34963}],"buffers":[{"byteLength":1680,"uri":"data:application/octet-stream;base64,AAAgQAAAIEAAAHDAAAAgQAAAIEAAAKDAAAAgQAAAIMAAAHDAAAAgQAAAIMAAAKDAAAAgwAAAIEAAAKDAAAAgwAAAIEAAAHDAAAAgwAAAIMAAAKDAAAAgwAAAIMAAAHDAAAAgwAAAIEAAAKDAAAAgQAAAIEAAAKDAAAAgwAAAIEAAAHDAAAAgQAAAIEAAAHDAAAAgwAAAIMAAAHDAAAAgQAAAIMAAAHDAAAAgwAAAIMAAAKDAAAAgQAAAIMAAAKDAAAAgwAAAIEAAAHDAAAAgQAAAIEAAAHDAAAAgwAAAIMAAAHDAAAAgQAAAIMAAAHDAAAAgQAAAIEAAAKDAAAAgwAAAIEAAAKDAAAAgQAAAIMAAAKDAAAAgwAAAIMAAAKDAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AADAPgAAAAAAANA+AAAAAAAAwD4AAAA+AADQPgAAAD4AANA+AAAAAAAA4D4AAAAAAADQPgAAAD4AAOA+AAAAPgAACD8AAJA+AADQPgAAkD4AAAg/AACAPgAA0D4AAIA+AAAIPwAAkD4AANA+AACQPgAACD8AAKA+AADQPgAAoD4AAIA+AAAAAAAAwD4AAAAAAACAPgAAAD4AAMA+AAAAPgAAQD4AAEA+AACgPgAAQD4AAEA+AACgPgAAoD4AAKA+AAACAAEAAgADAAEABAAGAAUABgAHAAUACAAKAAkACgALAAkADAAOAA0ADgAPAA0AEAASABEAEgATABEAFAAWABUAFgAXABUAAADwPwAA8D8AAKBAAADwPwAA8D8AAHDAAADwPwAA8L8AAKBAAADwPwAA8L8AAHDAAADwvwAA8D8AAHDAAADwvwAA8D8AAKBAAADwvwAA8L8AAHDAAADwvwAA8L8AAKBAAADwvwAA8D8AAHDAAADwPwAA8D8AAHDAAADwvwAA8D8AAKBAAADwPwAA8D8AAKBAAADwvwAA8L8AAKBAAADwPwAA8L8AAKBAAADwvwAA8L8AAHDAAADwPwAA8L8AAHDAAADwvwAA8D8AAKBAAADwPwAA8D8AAKBAAADwvwAA8L8AAKBAAADwPwAA8L8AAKBAAADwPwAA8D8AAHDAAADwvwAA8D8AAHDAAADwPwAA8L8AAHDAAADwvwAA8L8AAHDAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAPQAAAAAAAIA+AAAAAAAAAD0AAMA9AACAPgAAwD0AAAA9AADAPQAAgD4AAMA9AAAAPQAAQD4AAIA+AABAPgAAwD0AANA+AAAAAAAA0D4AAMA9AABAPgAAAAAAAEA+AABAPgAAQD4AAMA9AABAPgAAQD4AANA+AADAPQAA0D4AAKA+AACwPgAA0D4AALA+AACgPgAA4D4AANA+AADgPgAAoD4AAIA+AADQPgAAgD4AAKA+AACwPgAA0D4AALA+AAACAAEAAgADAAEABAAGAAUABgAHAAUACAAKAAkACgALAAkADAAOAA0ADgAPAA0AEAASABEAEgATABEAFAAWABUAFgAXABUA"}],"accessors":[{"bufferView":0,"componentType":5126,"count":24,"max":[2.5,2.5,-3.75],"min":[-2.5,-2.5,-5],"type":"VEC3"},{"bufferView":1,"componentType":5126,"count":24,"max":[1,1,1],"min":[-1,-1,-1],"type":"VEC3"},{"bufferView":2,"componentType":5126,"count":24,"max":[0.53125,0.3125],"min":[0.1875,0],"type":"VEC2"},{"bufferView":3,"componentType":5123,"count":36,"max":[23],"min":[0],"type":"SCALAR"},{"bufferView":4,"componentType":5126,"count":24,"max":[1.875,1.875,5],"min":[-1.875,-1.875,-3.75],"type":"VEC3"},{"bufferView":5,"componentType":5126,"count":24,"max":[1,1,1],"min":[-1,-1,-1],"type":"VEC3"},{"bufferView":6,"componentType":5126,"count":24,"max":[0.40625,0.4375],"min":[0,0],"type":"VEC2"},{"bufferView":7,"componentType":5123,"count":36,"max":[23],"min":[0],"type":"SCALAR"}],"materials":[{"pbrMetallicRoughness":{"metallicFactor":0,"roughnessFactor":1,"baseColorTexture":{"index":0}},"alphaMode":"MASK","alphaCutoff":0.05,"doubleSided":true}],"textures":[{"sampler":0,"source":0,"name":"rgt_pipe_straight"}],"samplers":[{"magFilter":9728,"minFilter":9728,"wrapS":33071,"wrapT":33071}],"images":[{"mimeType":"image/png","name":"rgt_pipe_straight.png","uri":"rgt_pipe_straight.png"}],"meshes":[{"primitives":[{"mode":4,"attributes":{"POSITION":0,"NORMAL":1,"TEXCOORD_0":2},"indices":3,"material":0}]},{"primitives":[{"mode":4,"attributes":{"POSITION":4,"NORMAL":5,"TEXCOORD_0":6},"indices":7,"material":0}]}]}
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
local ns = rgt_machines
|
||||
|
||||
local function update_pipe(pos, leaf)
|
||||
local node = minetest.get_node(pos)
|
||||
local neighbors = {}
|
||||
local dir
|
||||
local pipe
|
||||
|
||||
for _, offset in ipairs(rgt.adjacent_neighbor_offests) do
|
||||
pipe = minetest.get_node(pos +offset)
|
||||
if minetest.get_item_group(pipe.name, "pipe_straight") > 0 then
|
||||
neighbors[#neighbors +1] = offset
|
||||
end
|
||||
end
|
||||
|
||||
if #neighbors == 0 then
|
||||
node.name = "pipe_straight_double_cap"
|
||||
minetest.swap_node(pos, node)
|
||||
elseif #neighbors == 1 then
|
||||
node.name = "pipe_straight_single_cap"
|
||||
node.param2 = minetest.dir_to_facedir(-neighbors[1])
|
||||
minetest.swap_node(pos, node)
|
||||
elseif #neighbors == 2 then
|
||||
node.name = "pipe_straight"
|
||||
node.param2 = minetest.dir_to_facedir(neighbors[1])
|
||||
minetest.swap_node(pos, node)
|
||||
else
|
||||
|
||||
end
|
||||
|
||||
if not leaf then
|
||||
for _, x in ipairs(neighbors) do
|
||||
update_pipe(pos +x, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
rgt.register_node("pipe_straight", {
|
||||
drawtype = "mesh",
|
||||
mesh = "rgt_pipe_straight.gltf",
|
||||
tiles = {"rgt_pipe_straight.png"},
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
paramtype2 = "facedir",
|
||||
groups = {pipe = 1, pipe_straight = 1, dig_immediate = 3},
|
||||
drop = "pipe_straight",
|
||||
on_construct = function(pos)
|
||||
update_pipe(pos)
|
||||
end,
|
||||
after_destruct = function(pos)
|
||||
for _, offset in ipairs(rgt.adjacent_neighbor_offests) do
|
||||
pipe = minetest.get_node(pos +offset)
|
||||
if minetest.get_item_group(pipe.name, "pipe_straight") > 0 then
|
||||
update_pipe(pos +offset, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
rgt.register_node("pipe_straight_single_cap", {
|
||||
drawtype = "mesh",
|
||||
mesh = "rgt_pipe_straight_single_cap.gltf",
|
||||
tiles = {"rgt_pipe_straight.png"},
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
paramtype2 = "facedir",
|
||||
groups = {pipe = 1, pipe_straight = 1, dig_immediate = 3},
|
||||
drop = "pipe_straight",
|
||||
on_construct = function(pos)
|
||||
update_pipe(pos)
|
||||
end,
|
||||
after_destruct = function(pos)
|
||||
for _, offset in ipairs(rgt.adjacent_neighbor_offests) do
|
||||
pipe = minetest.get_node(pos +offset)
|
||||
if minetest.get_item_group(pipe.name, "pipe_straight") > 0 then
|
||||
update_pipe(pos +offset, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
rgt.register_node("pipe_straight_double_cap", {
|
||||
drawtype = "mesh",
|
||||
mesh = "rgt_pipe_straight_double_cap.gltf",
|
||||
tiles = {"rgt_pipe_straight.png"},
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
paramtype2 = "facedir",
|
||||
groups = {pipe = 1, pipe_straight = 1, dig_immediate = 3},
|
||||
drop = "pipe_straight",
|
||||
on_construct = function(pos)
|
||||
update_pipe(pos)
|
||||
end,
|
||||
after_destruct = function(pos)
|
||||
for _, offset in ipairs(rgt.adjacent_neighbor_offests) do
|
||||
pipe = minetest.get_node(pos +offset)
|
||||
if minetest.get_item_group(pipe.name, "pipe_straight") > 0 then
|
||||
update_pipe(pos +offset, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
|
After Width: | Height: | Size: 231 B |
|
After Width: | Height: | Size: 183 B |
|
After Width: | Height: | Size: 204 B |
|
After Width: | Height: | Size: 896 B |
|
After Width: | Height: | Size: 176 B |
|
After Width: | Height: | Size: 187 B |
|
|
@ -0,0 +1,132 @@
|
|||
|
||||
local function can_work(node, m, inv)
|
||||
-- Do we have an input item?
|
||||
local input = inv:get_stack("input", 1)
|
||||
if input:get_count() > 0 then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function update_formspec(m, progress)
|
||||
progress = progress or m:get_int "progress"
|
||||
local fluid = m:get_float "fluid"
|
||||
local capacity = m:get_int "fluid_capacity"
|
||||
local progressbar = progress == 0 and "rgt_progress_bg.png^[transformR270" or "rgt_progress_bg.png^[lowpart:"..progress..":rgt_progress_bg_active.png^[transformR270"
|
||||
local fluidcontainer = fluid == 0 and "rgt_fluid_container_bg.png" or "rgt_fluid_container_bg.png^[lowpart:"..(fluid /capacity *100)..":rgt_fluid_container_bg_filled.png"
|
||||
local fs = {"\
|
||||
formspec_version[10]\
|
||||
size[12,12]\
|
||||
", ui.list("context", "input", 2, 2, 1, 1), "\
|
||||
image[4,2;1,1;", progressbar, "]\
|
||||
image[7,1;1,3;", minetest.formspec_escape(fluidcontainer), "]\
|
||||
label[0.5,0.5;", fluid, " / ", capacity, "]\
|
||||
"}
|
||||
fs[#fs +1] = ui.list("current_player", "main", 1.125, 6.5, 8, 4)
|
||||
fs[#fs +1] = "\
|
||||
listring[]"
|
||||
|
||||
m:set_string("formspec", table.concat(fs))
|
||||
end
|
||||
|
||||
local function activate(pos, node, m)
|
||||
m:set_string("active", "true")
|
||||
node.name = "steam_generator_active"
|
||||
minetest.swap_node(pos, node)
|
||||
end
|
||||
|
||||
local function deactivate(pos, node, m)
|
||||
m:set_string("active", "false")
|
||||
m:set_int("progress", 0)
|
||||
update_formspec(m)
|
||||
node.name = "steam_generator_idle"
|
||||
minetest.swap_node(pos, node)
|
||||
end
|
||||
|
||||
local function update(pos, elapsed)
|
||||
local node = minetest.get_node(pos)
|
||||
local m = minetest.get_meta(pos)
|
||||
local inv = m:get_inventory()
|
||||
|
||||
local active = m:get_string("active") == "true"
|
||||
|
||||
if can_work(node, m, inv) then
|
||||
if not active then
|
||||
active = true
|
||||
activate(pos, node, m)
|
||||
end
|
||||
|
||||
local progress = m:get_int("progress") +20
|
||||
|
||||
if progress >= 100 then
|
||||
local fluid = m:get_float "fluid"
|
||||
fluid = fluid +1
|
||||
m:set_float("fluid", fluid)
|
||||
|
||||
-- Consume an item.
|
||||
local s = inv:get_stack("input", 1)
|
||||
s:take_item()
|
||||
inv:set_stack("input", 1, s)
|
||||
|
||||
progress = 0
|
||||
end
|
||||
m:set_int("progress", progress)
|
||||
|
||||
update_formspec(m, progress)
|
||||
|
||||
elseif active then
|
||||
active = false
|
||||
deactivate(pos, node, m)
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
rgt_machines.register_machine("steam_generator", {
|
||||
states = {
|
||||
idle = {
|
||||
tiles = {"rgt_iron_block.png", "rgt_iron_block.png", "rgt_iron_block.png", "rgt_iron_block.png", "rgt_iron_block.png", "rgt_steam_generator_front.png"}
|
||||
},
|
||||
active = {
|
||||
tiles = {"rgt_iron_block.png", "rgt_iron_block.png", "rgt_iron_block.png", "rgt_iron_block.png", "rgt_iron_block.png", "rgt_steam_generator_front_active.png"},
|
||||
drop = "steam_generator_idle",
|
||||
}
|
||||
},
|
||||
paramtype2 = "4dir",
|
||||
groups = {dig_immediate = 3},
|
||||
on_construct = function(pos)
|
||||
local m = minetest.get_meta(pos)
|
||||
local inv = m:get_inventory()
|
||||
inv:set_size("input", 1)
|
||||
|
||||
m:set_int("fluid_capacity", 10)
|
||||
m:set_string("active", "false")
|
||||
|
||||
update_formspec(m)
|
||||
|
||||
minetest.get_node_timer(pos):start(1)
|
||||
end,
|
||||
on_destruct = function(pos)
|
||||
local m = minetest.get_meta(pos)
|
||||
local inv = m:get_inventory()
|
||||
for i = 1, inv:get_size("input") do
|
||||
local item = minetest.add_item(pos, inv:get_stack("input", i))
|
||||
if item then
|
||||
item:set_velocity(vector.random_direction() *math.random(2, 3))
|
||||
end
|
||||
end
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, list, idx, s, p)
|
||||
local inv = minetest.get_meta(pos):get_inventory()
|
||||
local meltable = minetest.registered_items[s:get_name()].groups.arc_furnace_meltable
|
||||
if meltable then
|
||||
if inv:room_for_item("input", s) then
|
||||
return s:get_count()
|
||||
elseif inv:room_for_item("input", s:take_item()) then
|
||||
return s:get_stack_max() -inv:get_stack("input", 1):get_count()
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end,
|
||||
on_timer = update
|
||||
})
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
name = rgt_steam_generator
|
||||
depends = rgt_machines_electric
|
||||
|
After Width: | Height: | Size: 351 B |
|
After Width: | Height: | Size: 395 B |