Add copper, and the beginnings of a machine system.
This commit is contained in:
parent
30ba6e5385
commit
1e897665bb
69 changed files with 976 additions and 135 deletions
167
mods/rgt_machines/rgt_casting_basin/init.lua
Normal file
167
mods/rgt_machines/rgt_casting_basin/init.lua
Normal file
|
|
@ -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
|
||||
})
|
||||
2
mods/rgt_machines/rgt_casting_basin/mod.conf
Normal file
2
mods/rgt_machines/rgt_casting_basin/mod.conf
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
name = rgt_casting_basin
|
||||
depends = rgt_machines
|
||||
BIN
mods/rgt_machines/rgt_casting_basin/textures/rgt_cast_gear.png
Normal file
BIN
mods/rgt_machines/rgt_casting_basin/textures/rgt_cast_gear.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 167 B |
BIN
mods/rgt_machines/rgt_casting_basin/textures/rgt_cast_plate.png
Normal file
BIN
mods/rgt_machines/rgt_casting_basin/textures/rgt_cast_plate.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 173 B |
BIN
mods/rgt_machines/rgt_casting_basin/textures/rgt_cast_rod.png
Normal file
BIN
mods/rgt_machines/rgt_casting_basin/textures/rgt_cast_rod.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 107 B |
Binary file not shown.
|
After Width: | Height: | Size: 262 B |
Binary file not shown.
|
After Width: | Height: | Size: 303 B |
Loading…
Add table
Add a link
Reference in a new issue