Make casts meltable, make wooden and stone components be able to be turned into casts
This commit is contained in:
parent
7b75a2e9d8
commit
0d89ef920a
@ -9,7 +9,6 @@ metal_caster.max_metal = 16000
|
||||
|
||||
-- Use melter values
|
||||
metal_caster.spec = metal_melter.spec
|
||||
metal_caster.spec.cast = 288
|
||||
|
||||
metal_caster.casts = {
|
||||
ingot_cast = {name = "Ingot Cast", result = "ingot", cost = metal_caster.spec.ingot, typenames = {"ingot"}},
|
||||
@ -98,35 +97,6 @@ function metal_caster.get_metal_caster_formspec(data)
|
||||
default.get_hotbar_bg(0, 4.25)
|
||||
end
|
||||
|
||||
local function find_castable(metal_name, cast_name)
|
||||
local cast = metal_caster.casts[cast_name]
|
||||
if not cast then return nil end
|
||||
|
||||
local types = metal_melter.melts[metal_name]
|
||||
|
||||
if not types then return nil end
|
||||
|
||||
local typeres = types[cast.result]
|
||||
if not typeres then return nil end
|
||||
|
||||
if #typeres > 0 then
|
||||
return typeres[1]
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
function metal_caster.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
|
||||
return index
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Check to see if this cast is able to cast this metal type
|
||||
|
||||
local function can_dig(pos, player)
|
||||
@ -200,6 +170,18 @@ local function decrement_stack(stack)
|
||||
return stack
|
||||
end
|
||||
|
||||
local function in_table(t, n)
|
||||
local found = nil
|
||||
|
||||
for _, v in pairs(t) do
|
||||
if v == n then
|
||||
found = v
|
||||
end
|
||||
end
|
||||
|
||||
return found
|
||||
end
|
||||
|
||||
-- Get the corresponding cast for an item
|
||||
local function get_cast_for(item)
|
||||
local cast = nil
|
||||
@ -208,7 +190,7 @@ local function get_cast_for(item)
|
||||
for metal, types in pairs(metal_melter.melts) do
|
||||
if typename ~= nil then break end
|
||||
for t, items in pairs(types) do
|
||||
if items[item] then
|
||||
if in_table(items, item) then
|
||||
typename = t
|
||||
break
|
||||
end
|
||||
@ -225,6 +207,36 @@ local function get_cast_for(item)
|
||||
return typename, cast
|
||||
end
|
||||
|
||||
|
||||
local function find_castable(metal_name, cast_name)
|
||||
local cast = metal_caster.casts[cast_name]
|
||||
if not cast then return nil end
|
||||
|
||||
local types = metal_melter.melts[metal_name]
|
||||
|
||||
if not types then return nil end
|
||||
|
||||
local typeres = types[cast.result]
|
||||
if not typeres then return nil end
|
||||
|
||||
if #typeres > 0 then
|
||||
return typeres[1]
|
||||
end
|
||||
|
||||
return nil
|
||||
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
|
||||
return index
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
local function caster_node_timer(pos, elapsed)
|
||||
local refresh = false
|
||||
local meta = minetest.get_meta(pos)
|
||||
@ -295,7 +307,7 @@ local function caster_node_timer(pos, elapsed)
|
||||
metal_type = fluidity.get_metal_for_fluid(metal)
|
||||
|
||||
local caststack = inv:get_stack("cast", 1):get_name()
|
||||
local castname = metal_caster.get_cast_for_name(caststack)
|
||||
local castname = get_cast_for_name(caststack)
|
||||
if castname ~= nil then
|
||||
-- Cast metal using a cast
|
||||
local cast = metal_caster.casts[castname]
|
||||
@ -392,9 +404,10 @@ end
|
||||
|
||||
-- Register a new cast
|
||||
function metal_caster.register_cast(name, data)
|
||||
local modname = data.mod or "metal_melter"
|
||||
local modname = data.mod or "metal_melter"
|
||||
local castname = modname..":"..name
|
||||
|
||||
minetest.register_craftitem(modname..":"..name, {
|
||||
minetest.register_craftitem(castname, {
|
||||
description = data.name,
|
||||
inventory_image = "caster_"..name..".png",
|
||||
stack_max = 1,
|
||||
@ -404,6 +417,8 @@ function metal_caster.register_cast(name, data)
|
||||
if not metal_caster.casts[name] then
|
||||
metal_caster.casts[name] = data
|
||||
end
|
||||
|
||||
metal_melter.register_melt(castname, "gold", "cast")
|
||||
end
|
||||
|
||||
-- Register the caster
|
||||
|
@ -3,10 +3,6 @@ metal_melter.melts = {}
|
||||
-- fluidity.molten_metals - metals
|
||||
|
||||
function metal_melter.register_melt(item, metal, type)
|
||||
if not fluidity.molten_metals[metal] then
|
||||
return nil
|
||||
end
|
||||
|
||||
if not metal_melter.melts[metal] then
|
||||
metal_melter.melts[metal] = {}
|
||||
end
|
||||
|
@ -1,12 +1,18 @@
|
||||
-- Melts metals using lava as a heat source
|
||||
|
||||
-- Max lava that can be held by the melter
|
||||
metal_melter.max_fuel = 8000
|
||||
|
||||
-- Max metal that can be held by the melter
|
||||
metal_melter.max_metal = 16000
|
||||
|
||||
-- How much metal is given for melting a typename (in millibuckets)
|
||||
metal_melter.spec = {
|
||||
ingot = 144,
|
||||
crystal = 144,
|
||||
block = 1296,
|
||||
lump = 288,
|
||||
cast = 288,
|
||||
ore = 288
|
||||
}
|
||||
|
||||
@ -40,10 +46,6 @@ function metal_melter.get_metal_from_stack(stack)
|
||||
return metal, metal_type
|
||||
end
|
||||
|
||||
function metal_melter.set_spec(specname, value)
|
||||
metal_melter.spec[specname] = value
|
||||
end
|
||||
|
||||
function metal_melter.get_metal_melter_formspec_default()
|
||||
return "size[8,8.5]"..
|
||||
default.gui_bg..
|
||||
@ -242,15 +244,17 @@ local function melter_node_timer(pos, elapsed)
|
||||
if input ~= "" then
|
||||
local mt, t = metal_melter.get_metal_from_stack(input)
|
||||
if mt then
|
||||
local cnt = metal_melter.spec[t]
|
||||
local heat_consume = math.floor(cnt / 2)
|
||||
if metal_count + cnt <= metal_melter.max_metal and heat_count >= heat_consume then
|
||||
local metal_name = fluidity.molten_metals[mt]
|
||||
metal = metal_name
|
||||
metal_count = metal_count + cnt
|
||||
heat_count = heat_count - heat_consume
|
||||
inv:set_stack("input", 1, take_from_stack(inv:get_stack("input", 1), 1))
|
||||
refresh = true
|
||||
local metal_name = fluidity.molten_metals[mt]
|
||||
if metal_name then
|
||||
local cnt = metal_melter.spec[t]
|
||||
local heat_consume = math.floor(cnt / 2)
|
||||
if metal_count + cnt <= metal_melter.max_metal and heat_count >= heat_consume then
|
||||
metal = metal_name
|
||||
metal_count = metal_count + cnt
|
||||
heat_count = heat_count - heat_consume
|
||||
inv:set_stack("input", 1, take_from_stack(inv:get_stack("input", 1), 1))
|
||||
refresh = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -387,3 +391,8 @@ minetest.register_node("metal_melter:metal_melter_filled", {
|
||||
allow_metadata_inventory_move = allow_metadata_inventory_move,
|
||||
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
||||
})
|
||||
|
||||
-- Set a spec
|
||||
function metal_melter.set_spec(specname, value)
|
||||
metal_melter.spec[specname] = value
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user