Register casts, rework some API

This commit is contained in:
Evert Prants 2018-04-05 08:57:30 +03:00
parent 0721c30f0c
commit b3297c2fa4
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
3 changed files with 55 additions and 14 deletions

View File

@ -11,9 +11,9 @@ metal_caster.max_metal = 16000
metal_caster.spec = metal_melter.spec
metal_caster.casts = {
ingot_cast = {name = "Ingot Cast", result = "ingot", cost = metal_caster.spec.ingot, typenames = {"ingot"}},
lump_cast = {name = "Lump Cast", result = "lump", cost = metal_caster.spec.lump, typenames = {"lump"}},
gem_cast = {name = "Gem Cast", result = "crystal", cost = metal_caster.spec.crystal, typenames = {"crystal", "gem"}}
ingot = {description = "Ingot", result = "ingot", cost = metal_caster.spec.ingot, typenames = {"ingot"}},
lump = {description = "Lump", result = "lump", cost = metal_caster.spec.lump, typenames = {"lump"}},
gem = {description = "Gem", result = "crystal", cost = metal_caster.spec.crystal, typenames = {"crystal", "gem"}}
}
local metal_cache = {}
@ -204,6 +204,8 @@ local function get_cast_for(item)
end
end
print(typename, cast)
return typename, cast
end
@ -228,8 +230,8 @@ end
local function get_cast_for_name(name)
for index, value in pairs(metal_caster.casts) do
local mod = value.mod or "metal_melter"
if name == mod..":"..index then
local mod = value.mod_name or "metal_melter"
if name == mod..":"..index.."_cast" then
return index
end
end
@ -333,8 +335,8 @@ local function caster_node_timer(pos, elapsed)
local coolant_cost = result_cost / 4
if metal_count >= result_cost and coolant_count >= coolant_cost then
local mtype, ctype = get_cast_for(caststack)
if mtype then
local cmod = metal_caster.casts[ctype].mod or "metal_melter"
if mtype and ctype then
local cmod = metal_caster.casts[ctype].mod_name or "metal_melter"
local stack = ItemStack(cmod..":"..ctype)
local output_stack = inv:get_stack("output", 1)
local cast_stack = inv:get_stack("cast", 1)
@ -404,12 +406,12 @@ end
-- Register a new cast
function metal_caster.register_cast(name, data)
local modname = data.mod or "metal_melter"
local castname = modname..":"..name
local mod = data.mod_name or "metal_melter"
local castname = mod..":"..name.."_cast"
minetest.register_craftitem(castname, {
description = data.name,
inventory_image = "caster_"..name..".png",
description = data.description.." Cast",
inventory_image = "caster_"..name.."_cast.png",
stack_max = 1,
groups = {cast=1}
})

View File

@ -0,0 +1,22 @@
tinkering.pattern = {}
-- Register a new pattern
function tinkering.register_pattern(name, data)
local mod = data.mod_name or "tinkering"
local desc = data.description
tinkering.pattern[name] = data
minetest.register_craftitem(mod..":"..name.."_pattern", {
description = desc.." Pattern",
inventory_image = "tinkering_"..name.."_pattern.png",
groups = {pattern=1}
})
end
-- Create blank pattern
minetest.register_craftitem("tinkering:blank_pattern", {
description = "Blank Pattern",
inventory_image = "tinkering_blank_pattern.png",
groups = {pattern=1}
})

View File

@ -91,6 +91,24 @@ function tinkering.register_component(name, data)
tinkering.components[name] = data
end
local comp_desc = data.description:sub(4)
-- Register cast
metal_melter.set_spec(name, metal_caster.spec.cast)
metal_caster.register_cast(name, {
description = comp_desc,
mod_name = mod,
result = name,
cost = metal_caster.spec.cast,
typenames = {name}
})
-- Register pattern
tinkering.register_pattern(name, {
description = comp_desc,
mod_name = mod
})
-- Register components for all materials
for m, s in pairs(tinkering.materials) do
local component = m.."_"..name
@ -103,7 +121,6 @@ function tinkering.register_component(name, data)
})
-- Make all components meltable
metal_melter.set_spec(name, metal_caster.spec.cast)
metal_melter.register_melt(mod..":"..component, m, name)
end
end