Add Solderer block, add items, add crafting recipes

This commit is contained in:
Evert Prants 2018-04-08 19:36:53 +03:00
parent 7a461219b8
commit 4e9ab352df
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
23 changed files with 509 additions and 2 deletions

165
crafting.lua Normal file
View File

@ -0,0 +1,165 @@
-- Soldering
local solderer_recipes = {
{
input = {"", "default:steel_ingot", ""},
output = "holostorage:basic_chip",
time = 4,
},
{
input = {"", "default:gold_ingot", ""},
output = "holostorage:advanced_chip",
time = 4,
},
{
input = {"", "default:diamond", ""},
output = "holostorage:elite_chip",
time = 4,
},
{
input = {"", "holostorage:silicon", ""},
output = "holostorage:silicon_wafer",
time = 4,
},
{
input = {"holostorage:basic_chip", "holostorage:silicon_wafer", "default:mese_crystal"},
output = "holostorage:basic_processor",
time = 6,
},
{
input = {"holostorage:advanced_chip", "holostorage:silicon_wafer", "default:mese_crystal"},
output = "holostorage:advanced_processor",
time = 6,
},
{
input = {"holostorage:elite_chip", "holostorage:silicon_wafer", "default:mese_crystal"},
output = "holostorage:elite_processor",
time = 6,
},
{
input = {"holostorage:elite_chip", "holostorage:grid", "default:mese_crystal"},
output = "holostorage:crafting_grid",
time = 12,
},
{
input = {"holostorage:elite_chip", "dye:dark_green", "default:mese_crystal"},
output = "holostorage:disk_control_circuit",
time = 16,
},
}
for _, recipe in pairs(solderer_recipes) do
holostorage.solderer.register_recipe(recipe)
end
-- Crafting
-- Recipes involving quartz
local quartz = minetest.get_modpath("quartz") ~= nil
if quartz then
minetest.register_craft({
type = "shapeless",
output = "holostorage:quartz_iron",
recipe = {
"default:steel_ingot", "quartz:quartz_crystal", "quartz:quartz_crystal", "quartz:quartz_crystal"
}
})
minetest.register_craft({
type = "cooking",
output = "holostorage:silicon",
recipe = "holostorage:quartz_iron"
})
else
minetest.register_craft({
type = "cooking",
output = "holostorage:silicon",
recipe = "default:desert_sand"
})
end
minetest.register_craft({
output = "holostorage:machine_block",
recipe = {
{"holostorage:quartz_iron", "holostorage:quartz_iron", "holostorage:quartz_iron"},
{"holostorage:quartz_iron", "", "holostorage:quartz_iron"},
{"holostorage:quartz_iron", "holostorage:quartz_iron", "holostorage:quartz_iron"}
}
})
minetest.register_craft({
output = "holostorage:solderer",
recipe = {
{"holostorage:quartz_iron", "holostorage:quartz_iron", "holostorage:quartz_iron"},
{"default:mese_crystal", "holostorage:machine_block", "default:mese_crystal"},
{"holostorage:quartz_iron", "holostorage:quartz_iron", "holostorage:quartz_iron"}
}
})
minetest.register_craft({
output = "holostorage:disk_drive0",
recipe = {
{"holostorage:quartz_iron", "holostorage:advanced_processor", "holostorage:quartz_iron"},
{"holostorage:quartz_iron", "holostorage:machine_block", "holostorage:quartz_iron"},
{"holostorage:quartz_iron", "holostorage:advanced_processor", "holostorage:quartz_iron"}
}
})
minetest.register_craft({
output = "holostorage:grid",
recipe = {
{"holostorage:basic_processor", "holostorage:quartz_iron", "default:glass"},
{"default:mese_crystal", "holostorage:machine_block", "default:glass"},
{"holostorage:basic_processor", "holostorage:quartz_iron", "default:glass"}
}
})
minetest.register_craft({
output = "holostorage:cable 16",
recipe = {
{"holostorage:quartz_iron", "holostorage:quartz_iron", "holostorage:quartz_iron"}
}
})
minetest.register_craft({
output = "holostorage:import_bus",
recipe = {
{"holostorage:advanced_processor", "holostorage:cable"},
{"default:mese_crystal", "holostorage:machine_block"}
}
})
minetest.register_craft({
output = "holostorage:export_bus",
recipe = {
{"holostorage:cable", "holostorage:advanced_processor"},
{"default:mese_crystal", "holostorage:machine_block"}
}
})
minetest.register_craft({
output = "holostorage:controller",
recipe = {
{"default:mese_crystal", "holostorage:quartz_iron", "default:mese_crystal"},
{"default:diamond", "holostorage:machine_block", "default:diamond"},
{"default:mese_crystal", "holostorage:cable", "default:mese_crystal"},
}
})
-- Platters
minetest.register_craft({
output = "holostorage:quartz_platter",
recipe = {
{"", "holostorage:quartz_iron", ""},
{"holostorage:quartz_iron", "default:mese_crystal", "holostorage:quartz_iron"},
{"", "holostorage:quartz_iron", ""},
}
})
-- Disks
minetest.register_craft({
output = "holostorage:storage_disk1",
recipe = {
{"holostorage:advanced_processor", "holostorage:quartz_platter", "holostorage:advanced_processor"},
{"holostorage:quartz_platter", "holostorage:elite_processor", "holostorage:quartz_platter"},
{"holostorage:disk_control_circuit", "holostorage:quartz_iron", "holostorage:disk_control_circuit"},
}
})

View File

@ -15,3 +15,6 @@ dofile(modpath.."/items.lua")
-- Nodes
dofile(modpath.."/nodes.lua")
-- Crafting recipes
dofile(modpath.."/crafting.lua")

View File

@ -2,3 +2,6 @@
-- Drives
dofile(holostorage.modpath.."/items/storage_disk.lua")
-- Crafting Components
dofile(holostorage.modpath.."/items/crafting_components.lua")

View File

@ -0,0 +1,88 @@
-- Chips
minetest.register_craftitem("holostorage:basic_chip", {
description = "Basic Processor Chip",
inventory_image = "holostorage_basic_node.png"
})
minetest.register_craftitem("holostorage:advanced_chip", {
description = "Advanced Processor Chip",
inventory_image = "holostorage_advanced_node.png"
})
minetest.register_craftitem("holostorage:elite_chip", {
description = "Elite Processor Chip",
inventory_image = "holostorage_elite_node.png"
})
-- Silicon
minetest.register_craftitem("holostorage:silicon", {
description = "Silicon",
inventory_image = "holostorage_silicon.png",
groups = {silicon = 1}
})
minetest.register_craftitem("holostorage:silicon_wafer", {
description = "Silicon Wafer",
inventory_image = "holostorage_wafer.png",
groups = {wafer = 1}
})
-- Processors
minetest.register_craftitem("holostorage:basic_processor", {
description = "Basic Processor",
inventory_image = "holostorage_basic_processor.png"
})
minetest.register_craftitem("holostorage:advanced_processor", {
description = "Advanced Processor",
inventory_image = "holostorage_advanced_processor.png"
})
minetest.register_craftitem("holostorage:elite_processor", {
description = "Elite Processor",
inventory_image = "holostorage_elite_processor.png"
})
-- Disk components
minetest.register_craftitem("holostorage:quartz_platter", {
description = "Quartz Platter (1K)",
inventory_image = "holostorage_quartz_platter.png"
})
minetest.register_craftitem("holostorage:resistant_platter", {
description = "Resistant Platter (8K)",
inventory_image = "holostorage_resistant_platter.png"
})
minetest.register_craftitem("holostorage:adapt_platter", {
description = "Adapt Platter (16K)",
inventory_image = "holostorage_adapt_platter.png"
})
minetest.register_craftitem("holostorage:nanostorage_platter", {
description = "Nanostorage Platter (32K)",
inventory_image = "holostorage_nanostorage_platter.png"
})
minetest.register_craftitem("holostorage:elite_platter", {
description = "Elite Nanostorage Platter (64K)",
inventory_image = "holostorage_elite_platter.png"
})
minetest.register_craftitem("holostorage:disk_control_circuit", {
description = "Disk Control Circuit",
inventory_image = "holostorage_disk_control_circuit.png"
})
-- Other
minetest.register_node("holostorage:machine_block", {
description = "Machine Block",
tiles = {"holostorage_machine_block.png"},
groups = {cracky = 2}
})
minetest.register_craftitem("holostorage:quartz_iron", {
description = "Quartz-Enriched Iron",
inventory_image = "holostorage_quartz_iron.png"
})

View File

@ -1,3 +1,4 @@
name = holostorage
description = A solution to your hoarding addiction.
depends = default
depends = default, dye
optional_depends = quartz

View File

@ -18,6 +18,9 @@ dofile(holostorage.modpath.."/nodes/grid.lua")
-- Buses
dofile(holostorage.modpath.."/nodes/bus.lua")
-- Solderer
dofile(holostorage.modpath.."/nodes/solderer.lua")
-- Start the network
holostorage.network.register_abm_controller("holostorage:controller_active")
holostorage.network.register_abm_nodes()

View File

@ -4,10 +4,16 @@ holostorage.helpers = {}
function holostorage.helpers.swap_node(pos, noded)
local node = minetest.get_node(pos)
if type(noded) ~= "table" then
noded = {name = noded}
end
if node.name == noded.name then
return
return false
end
minetest.swap_node(pos, noded)
return true
end
function holostorage.helpers.grid_refresh(pos, n, controller)

238
nodes/solderer.lua Normal file
View File

@ -0,0 +1,238 @@
-- Solderer
holostorage.solderer = {}
holostorage.solderer.recipes = {}
local box = {
type = "fixed",
fixed = {
{-0.4375, -0.5000, -0.4375, 0.4375, -0.2500, 0.4375},
{-0.4375, 0.2500, -0.4375, 0.4375, 0.5000, 0.4375},
{-0.3750, -0.2500, -0.3750, 0.3750, -0.1250, 0.3750},
{-0.3750, 0.1250, -0.3750, 0.3750, 0.2500, 0.3750},
{-0.2500, -0.1250, -0.2500, -0.1250, 0.1250, -0.1250},
{-0.2500, -0.1250, 0.1250, -0.1250, 0.1250, 0.2500},
{0.1250, -0.1250, 0.1250, 0.2500, 0.1250, 0.2500},
{0.1250, -0.1250, -0.2500, 0.2500, 0.1250, -0.1250}
}
}
local collision_box = {
type = "fixed",
fixed = {-1/2.3, -1/2, -1/2.3, 1/2.3, 1/2, 1/2.3},
}
local function get_formspec(min, max)
local bar = "image[3.5,1.5;1,1;gui_furnace_arrow_bg.png^[transformR270]"
if min ~= nil then
local percent = math.floor((min/max)*100)
bar = "image[3.5,1.5;1,1;gui_furnace_arrow_bg.png^[lowpart:"..
(percent)..":gui_furnace_arrow_fg.png^[transformR270]"
end
return "size[8,8.5]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"label[0,0;Solderer]"..
"list[context;src;2.5,0.5;1,3;]"..
bar..
"list[context;dst;4.5,1.5;1,1;]"..
"list[current_player;main;0,4.25;8,1;]"..
"list[current_player;main;0,5.5;8,3;8]"..
"listring[context;src]"..
"listring[context;dst]"..
"listring[current_player;main]"..
default.get_hotbar_bg(0, 4.25)
end
local function allow_metadata_inventory_put (pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
if listname == "dst" then
return 0
end
return stack:get_count()
end
local function allow_metadata_inventory_move (pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local stack = inv:get_stack(from_list, from_index)
return allow_metadata_inventory_put(pos, to_list, to_index, stack, player)
end
local function allow_metadata_inventory_take (pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
return stack:get_count()
end
local function get_recipe_index(items)
if not items or type(items) ~= "table" then return false end
local l = {}
for i, stack in ipairs(items) do
l[i] = ItemStack(stack):get_name()
end
return table.concat(l, "/")
end
function holostorage.solderer.register_recipe(data)
for i, stack in ipairs(data.input) do
data.input[i] = ItemStack(stack):to_string()
end
if type(data.output) == "table" then
for i, v in ipairs(data.output) do
data.output[i] = ItemStack(data.output[i]):to_string()
end
else
data.output = ItemStack(data.output):to_string()
end
local index = get_recipe_index(data.input)
holostorage.solderer.recipes[index] = data
end
function holostorage.solderer.get_recipe(items)
local index = get_recipe_index(items)
local recipe = holostorage.solderer.recipes[index]
if recipe then
local new_input = {}
for i, stack in ipairs(items) do
new_input[i] = ItemStack(stack)
new_input[i]:take_item(1)
end
return {time = recipe.time,
new_input = new_input,
output = recipe.output}
else
return nil
end
end
local function round(v)
return math.floor(v + 0.5)
end
local function run_solderer(pos, _, controller)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local machine_node = "holostorage:solderer"
local machine_speed = 1
while true do
local result = holostorage.solderer.get_recipe(inv:get_list("src"))
if not result then
local swap = holostorage.helpers.swap_node(pos, machine_node)
if swap then
meta:set_string("infotext", "Solderer Idle")
meta:set_string("formspec", get_formspec())
meta:set_int("src_time", 0)
end
return
end
meta:set_int("src_time", meta:get_int("src_time") + round(machine_speed * 10))
holostorage.helpers.swap_node(pos, machine_node.."_active")
meta:set_string("infotext", "Solderer Active")
if meta:get_int("src_time") <= round(result.time*10) then
meta:set_string("formspec", get_formspec(meta:get_int("src_time"), round(result.time*10)))
return
end
local output = result.output
if type(output) ~= "table" then output = { output } end
local output_stacks = {}
for _, o in ipairs(output) do
table.insert(output_stacks, ItemStack(o))
end
local room_for_output = true
inv:set_size("dst_tmp", inv:get_size("dst"))
inv:set_list("dst_tmp", inv:get_list("dst"))
for _, o in ipairs(output_stacks) do
if not inv:room_for_item("dst_tmp", o) then
room_for_output = false
break
end
inv:add_item("dst_tmp", o)
end
if not room_for_output then
holostorage.helpers.swap_node(pos, machine_node)
meta:set_string("infotext", "Solderer Idle")
meta:set_string("formspec", get_formspec())
meta:set_int("src_time", round(result.time*10))
return
end
meta:set_int("src_time", meta:get_int("src_time") - round(result.time*10))
inv:set_list("src", result.new_input)
inv:set_list("dst", inv:get_list("dst_tmp"))
end
end
minetest.register_node("holostorage:solderer", {
description = "Solderer",
drawtype = "nodebox",
node_box = box,
is_ground_content = false,
tiles = {"holostorage_machine_block.png"},
groups = {
cracky = 1,
holostorage_distributor = 1,
holostorage_device = 1,
},
on_construct = function (pos)
holostorage.network.clear_networks(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", get_formspec())
local inv = meta:get_inventory()
inv:set_size("src", 3)
inv:set_size("dst", 1)
end,
on_destruct = holostorage.network.clear_networks,
selection_box = collision_box,
collision_box = collision_box,
allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_take = allow_metadata_inventory_take,
allow_metadata_inventory_move = allow_metadata_inventory_move,
holostorage_run = run_solderer,
})
minetest.register_node("holostorage:solderer_active", {
description = "Solderer",
drawtype = "nodebox",
paramtype = "light",
light_source = 8,
node_box = box,
is_ground_content = false,
drop = "holostorage:solderer",
tiles = {"holostorage_machine_block.png"},
groups = {
cracky = 1,
holostorage_distributor = 1,
holostorage_device = 1,
not_in_creative_inventory = 1,
},
on_destruct = holostorage.network.clear_networks,
selection_box = collision_box,
collision_box = collision_box,
holostorage_disabled_name = "holostorage:solderer",
allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_take = allow_metadata_inventory_take,
allow_metadata_inventory_move = allow_metadata_inventory_move,
holostorage_run = run_solderer,
})
holostorage.devices["holostorage:solderer"] = true
holostorage.devices["holostorage:solderer_active"] = true

Binary file not shown.

After

Width:  |  Height:  |  Size: 399 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 467 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 299 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 458 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 441 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 407 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 454 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 406 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 470 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 396 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 392 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 504 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 B