Add things

This commit is contained in:
Signal 2025-10-27 22:05:23 -04:00
parent 4d8312b79d
commit 00e1fd985d
28 changed files with 395 additions and 31 deletions

View file

@ -0,0 +1,139 @@
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 capacity = m:get_int "fluid_capacity"
if capacity -fluid >= 1 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_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 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") +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--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_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_metadata_inventory_put = function(pos, list)
end,
on_metadata_inventory_take = function(pos, list)
end,
on_timer = update
})

View file

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 357 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 393 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 B