Register casts, rework some API

This commit is contained in:
Evert 2018-04-05 08:57:30 +03:00
parent 0721c30f0c
commit b3297c2fa4
No known key found for this signature in database
GPG Key ID: 1688DA83D222D0B5
3 changed files with 55 additions and 14 deletions

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

@ -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}
})

@ -91,6 +91,24 @@ function tinkering.register_component(name, data)
tinkering.components[name] = data tinkering.components[name] = data
end 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 -- Register components for all materials
for m, s in pairs(tinkering.materials) do for m, s in pairs(tinkering.materials) do
local component = m.."_"..name local component = m.."_"..name
@ -103,7 +121,6 @@ function tinkering.register_component(name, data)
}) })
-- Make all components meltable -- Make all components meltable
metal_melter.set_spec(name, metal_caster.spec.cast)
metal_melter.register_melt(mod..":"..component, m, name) metal_melter.register_melt(mod..":"..component, m, name)
end end
end end