put it on GitHub
18
LICENSE.txt
Normal file
@ -0,0 +1,18 @@
|
||||
The MIT License
|
||||
|
||||
Copyright 2018 Evert "Diamond" Prants <evert@lunasqu.ee>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial
|
||||
portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
||||
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2
README.md
Normal file
@ -0,0 +1,2 @@
|
||||
# Melterns
|
||||
A Modpack for [Minetest](http://minetest.net) that adds molten metals, melting and casting.
|
4
fluidity/depends.txt
Normal file
@ -0,0 +1,4 @@
|
||||
default
|
||||
bucket
|
||||
technic?
|
||||
moreores?
|
1
fluidity/description.txt
Normal file
@ -0,0 +1 @@
|
||||
Adds Molten versions of commonly occuring metals. Supports default, technic and moreores.
|
7
fluidity/functions.lua
Normal file
@ -0,0 +1,7 @@
|
||||
function fluidity.fluid_name(name)
|
||||
return name:gsub("% Source$", "")
|
||||
end
|
||||
|
||||
function fluidity.fluid_short(str)
|
||||
return string.lower(str):gsub("%s", "_")
|
||||
end
|
13
fluidity/init.lua
Normal file
@ -0,0 +1,13 @@
|
||||
fluidity = rawget(_G, "fluidity") or {}
|
||||
|
||||
local mpath = minetest.get_modpath("fluidity")
|
||||
fluidity.modpath = mpath
|
||||
|
||||
-- Functions
|
||||
dofile(mpath.."/functions.lua")
|
||||
|
||||
-- Register molten metals
|
||||
dofile(mpath.."/molten.lua")
|
||||
|
||||
-- Register tanks for each fluid
|
||||
dofile(mpath.."/tanks.lua")
|
4
fluidity/mod.conf
Normal file
@ -0,0 +1,4 @@
|
||||
name = fluidity
|
||||
description = Adds Molten versions of commonly occuring metals. Supports default, technic and moreores.
|
||||
depends = default,bucket
|
||||
optional_depends = technic,moreores
|
141
fluidity/molten.lua
Normal file
@ -0,0 +1,141 @@
|
||||
-- Register molten metals
|
||||
|
||||
fluidity.molten_metals = {}
|
||||
|
||||
local function firstToUpper(str)
|
||||
return (str:gsub("^%l", string.upper))
|
||||
end
|
||||
|
||||
function fluidity.get_metal_for_fluid(fluid)
|
||||
for i,v in pairs(fluidity.molten_metals) do
|
||||
if v == fluid then
|
||||
return i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function fluidity.register_molten_metal(metal)
|
||||
local description = firstToUpper(metal)
|
||||
fluidity.molten_metals[metal] = "fluidity:"..metal.."_source"
|
||||
|
||||
minetest.register_node("fluidity:"..metal.."_source", {
|
||||
description = "Molten "..description.." Source",
|
||||
drawtype = "liquid",
|
||||
tiles = {
|
||||
{
|
||||
name = "fluidity_"..metal.."_source_animated.png",
|
||||
animation = {
|
||||
type = "vertical_frames",
|
||||
aspect_w = 16,
|
||||
aspect_h = 16,
|
||||
length = 3.0,
|
||||
},
|
||||
},
|
||||
},
|
||||
special_tiles = {
|
||||
{
|
||||
name = "fluidity_"..metal.."_source_animated.png",
|
||||
animation = {
|
||||
type = "vertical_frames",
|
||||
aspect_w = 16,
|
||||
aspect_h = 16,
|
||||
length = 3.0,
|
||||
},
|
||||
backface_culling = false,
|
||||
},
|
||||
},
|
||||
paramtype = "light",
|
||||
light_source = default.LIGHT_MAX - 1,
|
||||
walkable = false,
|
||||
pointable = false,
|
||||
diggable = false,
|
||||
buildable_to = true,
|
||||
is_ground_content = false,
|
||||
drop = "",
|
||||
drowning = 1,
|
||||
liquidtype = "source",
|
||||
liquid_alternative_flowing = "fluidity:"..metal.."_flowing",
|
||||
liquid_alternative_source = "fluidity:"..metal.."_source",
|
||||
liquid_viscosity = 7,
|
||||
liquid_renewable = false,
|
||||
damage_per_second = 4 * 2,
|
||||
post_effect_color = {a = 191, r = 255, g = 64, b = 0},
|
||||
groups = {molten_metal = 1, lava = 1, liquid = 2, igniter = 1},
|
||||
})
|
||||
|
||||
minetest.register_node("fluidity:"..metal.."_flowing", {
|
||||
description = "Flowing Molten "..description,
|
||||
drawtype = "flowingliquid",
|
||||
tiles = {"fluidity_"..metal..".png"},
|
||||
special_tiles = {
|
||||
{
|
||||
name = "fluidity_"..metal.."_flowing_animated.png",
|
||||
backface_culling = false,
|
||||
animation = {
|
||||
type = "vertical_frames",
|
||||
aspect_w = 16,
|
||||
aspect_h = 16,
|
||||
length = 3.3,
|
||||
},
|
||||
},
|
||||
{
|
||||
name = "fluidity_"..metal.."_flowing_animated.png",
|
||||
backface_culling = true,
|
||||
animation = {
|
||||
type = "vertical_frames",
|
||||
aspect_w = 16,
|
||||
aspect_h = 16,
|
||||
length = 3.3,
|
||||
},
|
||||
},
|
||||
},
|
||||
paramtype = "light",
|
||||
paramtype2 = "flowingliquid",
|
||||
light_source = default.LIGHT_MAX - 1,
|
||||
walkable = false,
|
||||
pointable = false,
|
||||
diggable = false,
|
||||
buildable_to = true,
|
||||
is_ground_content = false,
|
||||
drop = "",
|
||||
drowning = 1,
|
||||
liquidtype = "flowing",
|
||||
liquid_alternative_flowing = "fluidity:"..metal.."_flowing",
|
||||
liquid_alternative_source = "fluidity:"..metal.."_source",
|
||||
liquid_viscosity = 7,
|
||||
liquid_renewable = false,
|
||||
damage_per_second = 4 * 2,
|
||||
post_effect_color = {a = 191, r = 255, g = 64, b = 0},
|
||||
groups = {molten_metal = 1, lava = 1, liquid = 2, igniter = 1,
|
||||
not_in_creative_inventory = 1},
|
||||
})
|
||||
|
||||
bucket.register_liquid(
|
||||
"fluidity:"..metal.."_source",
|
||||
"fluidity:"..metal.."_flowing",
|
||||
"fluidity:bucket_"..metal,
|
||||
"fluidity_bucket_"..metal..".png",
|
||||
"Molten "..description.." Bucket"
|
||||
)
|
||||
end
|
||||
|
||||
-- Default metals
|
||||
fluidity.register_molten_metal("steel")
|
||||
fluidity.register_molten_metal("copper")
|
||||
fluidity.register_molten_metal("tin")
|
||||
fluidity.register_molten_metal("gold")
|
||||
fluidity.register_molten_metal("mese")
|
||||
fluidity.register_molten_metal("obsidian")
|
||||
|
||||
-- Technic metals
|
||||
if minetest.get_modpath("technic") ~= nil then
|
||||
fluidity.register_molten_metal("lead")
|
||||
fluidity.register_molten_metal("chromium")
|
||||
fluidity.register_molten_metal("zinc")
|
||||
end
|
||||
|
||||
-- moreores metals
|
||||
if minetest.get_modpath("moreores") ~= nil then
|
||||
fluidity.register_molten_metal("silver")
|
||||
fluidity.register_molten_metal("mithril")
|
||||
end
|
BIN
fluidity/screenshot.png
Normal file
After Width: | Height: | Size: 148 KiB |
194
fluidity/tanks.lua
Normal file
@ -0,0 +1,194 @@
|
||||
-- Register tanks for each fluid
|
||||
|
||||
fluidity.bucket_cache = {}
|
||||
|
||||
-- Get fluid source block name for bucket item
|
||||
function fluidity.get_fluid_for_bucket(itemname)
|
||||
for i,v in pairs(fluidity.bucket_cache) do
|
||||
if v == itemname then
|
||||
return i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Get bucket item name for fluid source block
|
||||
function fluidity.get_bucket_for_fluid(source)
|
||||
return fluidity.bucket_cache[source]
|
||||
end
|
||||
|
||||
function fluidity.get_fluid_node(name)
|
||||
return minetest.registered_nodes[name]
|
||||
end
|
||||
|
||||
local function get_nodedef_field(nodename, fieldname)
|
||||
if not minetest.registered_nodes[nodename] then
|
||||
return nil
|
||||
end
|
||||
return minetest.registered_nodes[nodename][fieldname]
|
||||
end
|
||||
|
||||
local function bucket_fill(pos, node, clicker, itemstack, pointed_thing)
|
||||
local stackname = itemstack:get_name()
|
||||
local nodename = node.name
|
||||
local stack = "bucket:bucket_empty"
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
if not stackname:find("bucket") then
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local tankfluid = get_nodedef_field(node.name, "fluidity_fluid")
|
||||
local tankname = get_nodedef_field(node.name, "_dataname")
|
||||
local tankcap = get_nodedef_field(node.name, "_capacity")
|
||||
local tankmod = get_nodedef_field(node.name, "_mod")
|
||||
|
||||
local fluidcount = meta:get_int("fluid")
|
||||
if stackname == "bucket:bucket_empty" then
|
||||
if tankfluid == nil then
|
||||
return itemstack
|
||||
end
|
||||
|
||||
fluidcount = fluidcount - 1
|
||||
stack = fluidity.get_bucket_for_fluid(tankfluid)
|
||||
|
||||
if fluidcount == 0 then
|
||||
nodename = tankmod..":"..tankname
|
||||
tankfluid = nil
|
||||
end
|
||||
else
|
||||
local srcnode = fluidity.get_fluid_for_bucket(stackname)
|
||||
|
||||
if (tankfluid ~= srcnode and tankfluid ~= nil) or (fluidcount >= tankcap) then
|
||||
return itemstack
|
||||
end
|
||||
|
||||
if tankfluid == nil then
|
||||
local source_node = fluidity.get_fluid_node(srcnode)
|
||||
local fluid_name = fluidity.fluid_name(source_node.description)
|
||||
local shorthand_name = fluidity.fluid_short(fluid_name)
|
||||
|
||||
nodename = tankmod..":"..tankname.."_"..shorthand_name
|
||||
|
||||
if not minetest.registered_nodes[nodename] then
|
||||
return itemstack
|
||||
end
|
||||
|
||||
tankfluid = srcnode
|
||||
end
|
||||
|
||||
fluidcount = fluidcount + 1
|
||||
end
|
||||
|
||||
meta:set_int("fluid", fluidcount)
|
||||
|
||||
if tankfluid then
|
||||
local source_node = fluidity.get_fluid_node(tankfluid)
|
||||
local fluid_name = fluidity.fluid_name(source_node.description)
|
||||
|
||||
meta:set_string("infotext", "Tank of "..fluid_name.."("..fluidcount.."/"..tankcap..")")
|
||||
else
|
||||
meta:set_string("infotext", "Empty Tank")
|
||||
end
|
||||
|
||||
local param2 = (fluidcount/tankcap)*63
|
||||
|
||||
minetest.swap_node(pos, {name=nodename,param1=node.param1,param2=param2})
|
||||
|
||||
return ItemStack(stack)
|
||||
end
|
||||
|
||||
-- Register a tank for a specific fluid
|
||||
local function register_tankfluid(data)
|
||||
local source_node = fluidity.get_fluid_node(data.source_name)
|
||||
local fluid = fluidity.fluid_name(source_node.description)
|
||||
local internal = fluidity.fluid_short(fluid)
|
||||
|
||||
minetest.register_node(data.mod_name..":"..data.tank_name.."_"..internal, {
|
||||
description = data.tank_description.." ("..fluid..")",
|
||||
drawtype = "glasslike_framed",
|
||||
paramtype = "light",
|
||||
paramtype2 = "glasslikeliquidlevel",
|
||||
drop = data.mod_name..":"..data.tank_name,
|
||||
fluidity_fluid = data.source_name,
|
||||
place_param2 = 0,
|
||||
special_tiles = source_node.tiles,
|
||||
is_ground_content = false,
|
||||
sunlight_propagates = true,
|
||||
on_rightclick = bucket_fill,
|
||||
_mod = data.mod_name,
|
||||
_dataname = data.tank_name,
|
||||
_capacity = data.capacity,
|
||||
groups = {cracky = 1, not_in_creative_inventory = 1, oddly_breakable_by_hand = 3, fluidity_tank = 1},
|
||||
tiles = data.tiles
|
||||
})
|
||||
end
|
||||
|
||||
-- Register a new tank
|
||||
function fluidity.register_fluid_tank(data)
|
||||
local modname = data.mod_name or 'fluidity'
|
||||
local tankname = data.tank_name or 'fluid_tank'
|
||||
local tankdesc = data.tank_description or 'Fluid Tank'
|
||||
local tiles = data.tiles or {"default_glass.png", "default_glass_detail.png"}
|
||||
local capacity = data.capacity or 64
|
||||
|
||||
minetest.register_node(modname..":"..tankname, {
|
||||
description = tankdesc,
|
||||
drawtype = "glasslike_framed",
|
||||
paramtype = "light",
|
||||
paramtype2 = "glasslikeliquidlevel",
|
||||
is_ground_content = false,
|
||||
sunlight_propagates = true,
|
||||
fluidity_fluid = nil,
|
||||
on_construct = function ( pos )
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_int("fluid", 0)
|
||||
meta:set_string("infotext", "Empty "..tankdesc)
|
||||
end,
|
||||
on_rightclick = bucket_fill,
|
||||
_mod = modname,
|
||||
_dataname = tankname,
|
||||
_capacity = capacity,
|
||||
groups = {cracky = 1, oddly_breakable_by_hand = 3, fluidity_tank = 1},
|
||||
tiles = tiles
|
||||
})
|
||||
|
||||
if data.fluids then
|
||||
-- This tank only uses certain fluids
|
||||
for _, v in pairs(data.fluids) do
|
||||
register_tankfluid({
|
||||
mod_name = modname,
|
||||
tank_name = tankname,
|
||||
tank_description = tankdesc,
|
||||
tiles = tiles,
|
||||
capacity = capacity,
|
||||
source_name = v
|
||||
})
|
||||
end
|
||||
else
|
||||
-- Get all fluids and buckets and cache them
|
||||
for i, v in pairs(bucket.liquids) do
|
||||
if (i:find("source") ~= nil) then
|
||||
-- Cache bucket
|
||||
fluidity.bucket_cache[v["source"]] = v.itemname
|
||||
|
||||
-- Add tank
|
||||
register_tankfluid({
|
||||
mod_name = modname,
|
||||
tank_name = tankname,
|
||||
tank_description = tankdesc,
|
||||
tiles = tiles,
|
||||
capacity = capacity,
|
||||
source_name = v["source"]
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
fluidity.register_fluid_tank({
|
||||
mod_name = "fluidity",
|
||||
tank_name = "fluid_tank",
|
||||
tank_description = "Fluid Tank",
|
||||
capacity = 64,
|
||||
tiles = {"default_glass.png", "default_glass_detail.png"}
|
||||
})
|
BIN
fluidity/textures/fluidity_bucket_chromium.png
Normal file
After Width: | Height: | Size: 425 B |
BIN
fluidity/textures/fluidity_bucket_copper.png
Normal file
After Width: | Height: | Size: 441 B |
BIN
fluidity/textures/fluidity_bucket_gold.png
Normal file
After Width: | Height: | Size: 431 B |
BIN
fluidity/textures/fluidity_bucket_lead.png
Normal file
After Width: | Height: | Size: 438 B |
BIN
fluidity/textures/fluidity_bucket_mese.png
Normal file
After Width: | Height: | Size: 423 B |
BIN
fluidity/textures/fluidity_bucket_mithril.png
Normal file
After Width: | Height: | Size: 405 B |
BIN
fluidity/textures/fluidity_bucket_obsidian.png
Normal file
After Width: | Height: | Size: 440 B |
BIN
fluidity/textures/fluidity_bucket_silver.png
Normal file
After Width: | Height: | Size: 425 B |
BIN
fluidity/textures/fluidity_bucket_steel.png
Normal file
After Width: | Height: | Size: 409 B |
BIN
fluidity/textures/fluidity_bucket_tin.png
Normal file
After Width: | Height: | Size: 424 B |
BIN
fluidity/textures/fluidity_bucket_zinc.png
Normal file
After Width: | Height: | Size: 432 B |
BIN
fluidity/textures/fluidity_chromium.png
Normal file
After Width: | Height: | Size: 724 B |
BIN
fluidity/textures/fluidity_chromium_flowing_animated.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
fluidity/textures/fluidity_chromium_source_animated.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
fluidity/textures/fluidity_copper.png
Normal file
After Width: | Height: | Size: 774 B |
BIN
fluidity/textures/fluidity_copper_flowing_animated.png
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
fluidity/textures/fluidity_copper_source_animated.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
fluidity/textures/fluidity_gold.png
Normal file
After Width: | Height: | Size: 660 B |
BIN
fluidity/textures/fluidity_gold_flowing_animated.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
fluidity/textures/fluidity_gold_source_animated.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
fluidity/textures/fluidity_lead.png
Normal file
After Width: | Height: | Size: 784 B |
BIN
fluidity/textures/fluidity_lead_flowing_animated.png
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
fluidity/textures/fluidity_lead_source_animated.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
fluidity/textures/fluidity_mese.png
Normal file
After Width: | Height: | Size: 634 B |
BIN
fluidity/textures/fluidity_mese_flowing_animated.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
fluidity/textures/fluidity_mese_source_animated.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
fluidity/textures/fluidity_mithril.png
Normal file
After Width: | Height: | Size: 450 B |
BIN
fluidity/textures/fluidity_mithril_flowing_animated.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
fluidity/textures/fluidity_mithril_source_animated.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
fluidity/textures/fluidity_obsidian.png
Normal file
After Width: | Height: | Size: 780 B |
BIN
fluidity/textures/fluidity_obsidian_flowing_animated.png
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
fluidity/textures/fluidity_obsidian_source_animated.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
fluidity/textures/fluidity_silver.png
Normal file
After Width: | Height: | Size: 617 B |
BIN
fluidity/textures/fluidity_silver_flowing_animated.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
fluidity/textures/fluidity_silver_source_animated.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
fluidity/textures/fluidity_steel.png
Normal file
After Width: | Height: | Size: 559 B |
BIN
fluidity/textures/fluidity_steel_flowing_animated.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
fluidity/textures/fluidity_steel_source_animated.png
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
fluidity/textures/fluidity_tin.png
Normal file
After Width: | Height: | Size: 737 B |
BIN
fluidity/textures/fluidity_tin_flowing_animated.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
fluidity/textures/fluidity_tin_source_animated.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
fluidity/textures/fluidity_zinc.png
Normal file
After Width: | Height: | Size: 605 B |
BIN
fluidity/textures/fluidity_zinc_flowing_animated.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
fluidity/textures/fluidity_zinc_source_animated.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
473
metal_melter/caster.lua
Normal file
@ -0,0 +1,473 @@
|
||||
-- Casts molten metals into a solid form
|
||||
|
||||
local have_ui = minetest.get_modpath("unified_inventory")
|
||||
|
||||
metal_caster = {}
|
||||
|
||||
metal_caster.max_coolant = 8000
|
||||
metal_caster.max_metal = 16000
|
||||
|
||||
-- Use melter values
|
||||
metal_caster.spec = metal_melter.spec
|
||||
metal_caster.spec.cast = 288
|
||||
|
||||
metal_caster.casts = {
|
||||
ingot_cast = {"Ingot Cast", "%s:%s_ingot", metal_caster.spec.ingot, {"ingot"}},
|
||||
lump_cast = {"Lump Cast", "%s:%s_lump", metal_caster.spec.lump, {"lump"}},
|
||||
gem_cast = {"Gem Cast", "%s:%s_crystal", metal_caster.spec.crystal, {"crystal", "gem"}}
|
||||
}
|
||||
|
||||
local metal_cache = {}
|
||||
|
||||
function metal_caster.get_metal_caster_formspec_default()
|
||||
return "size[8,8.5]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"list[context;cast;2.7,0.2;1,1;]"..
|
||||
"image[2.7,1.35;1,1;gui_furnace_arrow_bg.png^[transformFY]"..
|
||||
"list[context;output;2.7,2.5;1,1;]"..
|
||||
"list[context;coolant;0.25,2.5;1,1;]"..
|
||||
"image[0.08,0;1.4,2.8;melter_gui_barbg.png]"..
|
||||
"image[0.08,0;1.4,2.8;melter_gui_gauge.png]"..
|
||||
"label[0.08,3.4;Water: 0/"..metal_caster.max_coolant.." mB]"..
|
||||
"image[6.68,0;1.4,2.8;melter_gui_barbg.png]"..
|
||||
"image[6.68,0;1.4,2.8;melter_gui_gauge.png]"..
|
||||
"label[0.08,3.75;No Molten Metal]"..
|
||||
"list[context;bucket_in;4.75,0.2;2,2;]"..
|
||||
"list[context;bucket_out;4.75,1.4;2,2;]"..
|
||||
"image[5.75,0.2;1,1;gui_furnace_arrow_bg.png^[transformR270]"..
|
||||
"image[5.75,1.4;1,1;gui_furnace_arrow_bg.png^[transformR90]"..
|
||||
"list[current_player;main;0,4.25;8,1;]"..
|
||||
"list[current_player;main;0,5.5;8,3;8]"..
|
||||
"listring[context;coolant]"..
|
||||
"listring[current_player;main]"..
|
||||
"listring[context;cast]"..
|
||||
"listring[current_player;main]"..
|
||||
"listring[context;output]"..
|
||||
"listring[current_player;main]"..
|
||||
"listring[context;bucket_in]"..
|
||||
"listring[current_player;main]"..
|
||||
"listring[context;bucket_out]"..
|
||||
"listring[current_player;main]"..
|
||||
default.get_hotbar_bg(0, 4.25)
|
||||
end
|
||||
|
||||
function metal_caster.get_metal_caster_formspec(data)
|
||||
local water_percent = data.water_level / metal_caster.max_coolant
|
||||
local metal_percent = data.metal_level / metal_caster.max_metal
|
||||
|
||||
local metal_formspec = "label[0.08,3.75;No Molten Metal]"
|
||||
|
||||
if data.metal ~= "" then
|
||||
metal_formspec = "label[0.08,3.75;"..data.metal..": "..data.metal_level.."/"..metal_caster.max_metal.." mB]"
|
||||
end
|
||||
|
||||
return "size[8,8.5]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"list[context;cast;2.7,0.2;1,1;]"..
|
||||
"image[2.7,1.35;1,1;gui_furnace_arrow_bg.png^[transformFY]"..
|
||||
"list[context;output;2.7,2.5;1,1;]"..
|
||||
"list[context;coolant;0.25,2.5;1,1;]"..
|
||||
"image[0.08,0;1.4,2.8;melter_gui_barbg.png]"..
|
||||
"image[0.08,"..(2.44 - water_percent * 2.44)..";1.4,"..(water_percent * 2.8)..";default_water.png]"..
|
||||
"image[0.08,0;1.4,2.8;melter_gui_gauge.png]"..
|
||||
"label[0.08,3.4;Water: "..data.water_level.."/"..metal_caster.max_coolant.." mB]"..
|
||||
"image[6.68,0;1.4,2.8;melter_gui_barbg.png]"..
|
||||
"image[6.68,"..(2.44 - metal_percent * 2.44)..";1.4,"..(metal_percent * 2.8)..";"..data.metal_texture.."]"..
|
||||
"image[6.68,0;1.4,2.8;melter_gui_gauge.png]"..
|
||||
metal_formspec..
|
||||
"list[context;bucket_in;4.75,0.2;2,2;]"..
|
||||
"list[context;bucket_out;4.75,1.4;2,2;]"..
|
||||
"image[5.75,0.2;1,1;gui_furnace_arrow_bg.png^[transformR270]"..
|
||||
"image[5.75,1.4;1,1;gui_furnace_arrow_bg.png^[transformR90]"..
|
||||
"list[current_player;main;0,4.25;8,1;]"..
|
||||
"list[current_player;main;0,5.5;8,3;8]"..
|
||||
"listring[context;coolant]"..
|
||||
"listring[current_player;main]"..
|
||||
"listring[context;cast]"..
|
||||
"listring[current_player;main]"..
|
||||
"listring[context;output]"..
|
||||
"listring[current_player;main]"..
|
||||
"listring[context;bucket_in]"..
|
||||
"listring[current_player;main]"..
|
||||
"listring[context;bucket_out]"..
|
||||
"listring[current_player;main]"..
|
||||
default.get_hotbar_bg(0, 4.25)
|
||||
end
|
||||
|
||||
-- Find the name of the mod that adds this particular metal into the game.
|
||||
function metal_caster.get_modname_for_metal(metal_type)
|
||||
if not metal_cache[metal_type] then
|
||||
for i, v in pairs(minetest.registered_items) do
|
||||
if i:find(metal_type) and (i:find("ingot") or i:find("block") or i:find("crystal")) and not metal_cache[metal_type] then
|
||||
local modname, metalname = i:match("(%a+):(%a+)")
|
||||
metal_cache[metalname] = modname
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return metal_cache[metal_type]
|
||||
end
|
||||
|
||||
-- Check to see if this cast is able to cast this metal type
|
||||
local function can_cast(metal_name, cast_name)
|
||||
local mod = metal_caster.get_modname_for_metal(metal_name)
|
||||
local castt = metal_caster.casts[cast_name]
|
||||
local item_name = castt[2]:format(mod, metal_name)
|
||||
|
||||
if minetest.registered_items[item_name] ~= nil then
|
||||
return mod
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
local function can_dig(pos, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
return inv:is_empty("cast") and inv:is_empty("coolant") and inv:is_empty("bucket_in") and inv:is_empty("bucket_out") and
|
||||
inv:is_empty("output")
|
||||
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 == "bucket_out" then
|
||||
if stack:get_name() ~= "bucket:bucket_empty" then
|
||||
return 0
|
||||
end
|
||||
|
||||
return 1
|
||||
end
|
||||
|
||||
if listname == "coolant" then
|
||||
if stack:get_name() ~= "bucket:bucket_water" then
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
if listname == "output" 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
|
||||
|
||||
-- Increment a stack by one
|
||||
local function increment_stack(stack, appendix)
|
||||
if stack:is_empty() then
|
||||
return appendix
|
||||
end
|
||||
|
||||
if stack:get_name() ~= appendix:get_name() then
|
||||
return stack
|
||||
end
|
||||
|
||||
stack:set_count(stack:get_count() + 1)
|
||||
return stack
|
||||
end
|
||||
|
||||
-- Decrement a stack by one
|
||||
local function decrement_stack(stack)
|
||||
if stack:get_count() == 1 then
|
||||
return nil
|
||||
end
|
||||
|
||||
stack:set_count(stack:get_count() - 1)
|
||||
return stack
|
||||
end
|
||||
|
||||
-- Get the corresponding cast for an item
|
||||
local function get_cast_for(item)
|
||||
local typename, castname = item:match(":([%a_]+)_(%a+)$")
|
||||
if not typename or not castname then
|
||||
return nil
|
||||
end
|
||||
|
||||
local cast = nil
|
||||
for i, v in pairs(metal_caster.casts) do
|
||||
for _,k in pairs(v[4]) do
|
||||
if castname == k then
|
||||
cast = i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not cast then return nil end
|
||||
return typename, cast
|
||||
end
|
||||
|
||||
local function caster_node_timer(pos, elapsed)
|
||||
local refresh = false
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
|
||||
-- Current amount of water (coolant) in the block
|
||||
local coolant_count = meta:get_int("water_level")
|
||||
|
||||
-- Current amount of metal in the block
|
||||
local metal_count = meta:get_int("metal_level")
|
||||
|
||||
-- Current metal used
|
||||
local metal = meta:get_string("metal")
|
||||
local metal_type = ""
|
||||
|
||||
-- Insert water bucket into tank, return empty bucket
|
||||
if inv:get_stack("coolant", 1):get_name() == "bucket:bucket_water" then
|
||||
if coolant_count + 1000 <= metal_caster.max_coolant then
|
||||
coolant_count = coolant_count + 1000
|
||||
inv:set_list("coolant", {"bucket:bucket_empty"})
|
||||
refresh = true
|
||||
end
|
||||
end
|
||||
|
||||
-- Handle input bucket, only allow a molten metal
|
||||
local bucket_in = inv:get_stack("bucket_in", 1):get_name()
|
||||
if bucket_in:find("bucket") and bucket_in ~= "bucket:bucket_empty" then
|
||||
local bucket_fluid = fluidity.get_fluid_for_bucket(bucket_in)
|
||||
local fluid_is_metal = fluidity.get_metal_for_fluid(bucket_fluid) ~= nil
|
||||
local empty_bucket = false
|
||||
|
||||
if fluid_is_metal then
|
||||
if metal ~= "" and metal == bucket_fluid then
|
||||
if metal_count + 1000 <= metal_caster.max_metal then
|
||||
metal_count = metal_count + 1000
|
||||
empty_bucket = true
|
||||
end
|
||||
elseif metal == "" then
|
||||
metal_count = 1000
|
||||
metal = bucket_fluid
|
||||
empty_bucket = true
|
||||
end
|
||||
end
|
||||
|
||||
if empty_bucket then
|
||||
inv:set_list("bucket_in", {"bucket:bucket_empty"})
|
||||
refresh = true
|
||||
end
|
||||
end
|
||||
|
||||
-- Handle bucket output, only allow empty buckets in this slot
|
||||
local bucket_out = inv:get_stack("bucket_out", 1):get_name()
|
||||
if bucket_out == "bucket:bucket_empty" and metal ~= "" then
|
||||
local bucket = fluidity.get_bucket_for_fluid(metal)
|
||||
if metal_count >= 1000 then
|
||||
metal_count = metal_count - 1000
|
||||
inv:set_list("bucket_out", {bucket})
|
||||
refresh = true
|
||||
|
||||
if metal_count == 0 then
|
||||
metal = ""
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- If we have a cast, check if we can cast right now.
|
||||
if metal ~= "" then
|
||||
metal_type = fluidity.get_metal_for_fluid(metal)
|
||||
|
||||
local castname = inv:get_stack("cast", 1):get_name()
|
||||
castname = castname:gsub("metal_melter:", "")
|
||||
if metal_caster.casts[castname] then
|
||||
-- Cast metal using a cast
|
||||
local cast = metal_caster.casts[castname]
|
||||
local modname = can_cast(metal_type, castname)
|
||||
if modname ~= nil then
|
||||
local result_name = cast[2]:format(modname, metal_type)
|
||||
local result_cost = cast[3]
|
||||
local coolant_cost = result_cost / 4
|
||||
|
||||
if metal_count >= result_cost and coolant_count >= coolant_cost then
|
||||
local stack = ItemStack(result_name)
|
||||
local output_stack = inv:get_stack("output", 1)
|
||||
if output_stack:item_fits(stack) then
|
||||
inv:set_stack("output", 1, increment_stack(output_stack, stack))
|
||||
metal_count = metal_count - result_cost
|
||||
coolant_count = coolant_count - coolant_cost
|
||||
refresh = true
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif castname:find("_ingot") or castname:find("_crystal") or castname:find("_lump") and metal_type == "gold" then
|
||||
-- Create a new cast
|
||||
local result_cost = metal_caster.spec.cast
|
||||
local coolant_cost = result_cost / 4
|
||||
if metal_count >= result_cost and coolant_count >= coolant_cost then
|
||||
local mtype, ctype = get_cast_for(castname)
|
||||
if mtype then
|
||||
local stack = ItemStack("metal_melter:"..ctype)
|
||||
local output_stack = inv:get_stack("output", 1)
|
||||
local cast_stack = inv:get_stack("cast", 1)
|
||||
if output_stack:item_fits(stack) then
|
||||
inv:set_stack("output", 1, increment_stack(output_stack, stack))
|
||||
inv:set_stack("cast", 1, decrement_stack(cast_stack))
|
||||
metal_count = metal_count - result_cost
|
||||
coolant_count = coolant_count - coolant_cost
|
||||
refresh = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if refresh then
|
||||
meta:set_int("water_level", coolant_count)
|
||||
meta:set_int("metal_level", metal_count)
|
||||
meta:set_string("metal", metal)
|
||||
|
||||
local metal_texture = "default_lava.png"
|
||||
local metal_name = ""
|
||||
|
||||
local infotext = "Metal Caster\n"
|
||||
infotext = infotext.."Water: "..coolant_count.."/"..metal_caster.max_coolant.." mB \n"
|
||||
|
||||
if metal ~= "" then
|
||||
metal_texture = "fluidity_"..fluidity.get_metal_for_fluid(metal)..".png"
|
||||
|
||||
local metal_node = minetest.registered_nodes[metal]
|
||||
metal_name = fluidity.fluid_name(metal_node.description)
|
||||
infotext = infotext..metal_name..": "..metal_count.."/"..metal_caster.max_metal.." mB"
|
||||
else
|
||||
infotext = infotext.."No Molten Metal"
|
||||
end
|
||||
|
||||
meta:set_string("infotext", infotext)
|
||||
meta:set_string("formspec", metal_caster.get_metal_caster_formspec(
|
||||
{water_level=coolant_count, metal_level=metal_count, metal_texture=metal_texture, metal=metal_name}))
|
||||
end
|
||||
|
||||
return refresh
|
||||
end
|
||||
|
||||
local function on_construct(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("formspec", metal_caster.get_metal_caster_formspec_default())
|
||||
|
||||
-- Create inventory
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size('cast', 1)
|
||||
inv:set_size('output', 1)
|
||||
inv:set_size('coolant', 1)
|
||||
inv:set_size('bucket_in', 1)
|
||||
inv:set_size('bucket_out', 1)
|
||||
|
||||
-- Fluid buffers
|
||||
meta:set_int('water_level', 0)
|
||||
meta:set_int('metal_level', 0)
|
||||
|
||||
-- Metal source block
|
||||
meta:set_string('metal', '')
|
||||
|
||||
-- Default infotext
|
||||
meta:set_string("infotext", "Metal Caster Inactive")
|
||||
end
|
||||
|
||||
-- Register a new cast
|
||||
function metal_caster.register_cast(name, data)
|
||||
if not metal_caster.casts[name] then
|
||||
metal_caster.casts[name] = data
|
||||
end
|
||||
|
||||
minetest.register_craftitem("metal_melter:"..name, {
|
||||
description = data[1],
|
||||
inventory_image = "caster_"..name..".png",
|
||||
stack_max = 1,
|
||||
groups = {cast=1}
|
||||
})
|
||||
end
|
||||
|
||||
-- Register the caster
|
||||
minetest.register_node("metal_melter:metal_caster", {
|
||||
description = "Metal Caster",
|
||||
tiles = {
|
||||
"melter_side.png", "melter_side.png",
|
||||
"melter_side.png", "melter_side.png",
|
||||
"melter_side.png", "caster_front.png"
|
||||
},
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2},
|
||||
legacy_facedir_simple = true,
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
|
||||
can_dig = can_dig,
|
||||
on_timer = caster_node_timer,
|
||||
on_construct = on_construct,
|
||||
on_metadata_inventory_move = function(pos)
|
||||
minetest.get_node_timer(pos):start(1.0)
|
||||
end,
|
||||
on_metadata_inventory_put = function(pos)
|
||||
minetest.get_node_timer(pos):start(1.0)
|
||||
end,
|
||||
on_metadata_inventory_take = function(pos)
|
||||
minetest.get_node_timer(pos):start(1.0)
|
||||
end,
|
||||
on_blast = function(pos)
|
||||
local drops = {}
|
||||
default.get_inventory_drops(pos, "cast", drops)
|
||||
default.get_inventory_drops(pos, "output", drops)
|
||||
default.get_inventory_drops(pos, "coolant", drops)
|
||||
default.get_inventory_drops(pos, "bucket_in", drops)
|
||||
default.get_inventory_drops(pos, "bucket_out", drops)
|
||||
drops[#drops+1] = "metal_melter:metal_caster"
|
||||
minetest.remove_node(pos)
|
||||
return drops
|
||||
end,
|
||||
|
||||
allow_metadata_inventory_put = allow_metadata_inventory_put,
|
||||
allow_metadata_inventory_move = allow_metadata_inventory_move,
|
||||
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
||||
})
|
||||
|
||||
for i,v in pairs(metal_caster.casts) do
|
||||
metal_caster.register_cast(i, v)
|
||||
end
|
||||
|
||||
-- Support Unified Inventory, partially
|
||||
if have_ui then
|
||||
unified_inventory.register_craft_type("casting", {
|
||||
description = "Casting",
|
||||
width = 2,
|
||||
height = 1,
|
||||
})
|
||||
|
||||
unified_inventory.register_craft({
|
||||
type = "casting",
|
||||
output = "metal_melter:ingot_cast",
|
||||
items = {"fluidity:bucket_gold", "default:steel_ingot"},
|
||||
width = 0,
|
||||
})
|
||||
|
||||
unified_inventory.register_craft({
|
||||
type = "casting",
|
||||
output = "metal_melter:lump_cast",
|
||||
items = {"fluidity:bucket_gold", "default:iron_lump"},
|
||||
width = 0,
|
||||
})
|
||||
|
||||
unified_inventory.register_craft({
|
||||
type = "casting",
|
||||
output = "metal_melter:gem_cast",
|
||||
items = {"fluidity:bucket_gold", "default:mese_crystal"},
|
||||
width = 0,
|
||||
})
|
||||
end
|
157
metal_melter/components.lua
Normal file
@ -0,0 +1,157 @@
|
||||
-- Crafting components
|
||||
|
||||
-- Items
|
||||
|
||||
minetest.register_craftitem("metal_melter:heated_brick", {
|
||||
description = "Heatbrick",
|
||||
inventory_image = "metal_melter_heated_brick.png",
|
||||
groups = {brick=1}
|
||||
})
|
||||
|
||||
-- Nodes
|
||||
|
||||
minetest.register_node("metal_melter:heated_bricks", {
|
||||
description = "Heatbricks",
|
||||
tiles = {"metal_melter_heatbrick.png"},
|
||||
groups = {cracky = 3},
|
||||
paramtype2 = "facedir",
|
||||
place_param2 = 0,
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
})
|
||||
|
||||
minetest.register_node("metal_melter:heat_gravel", {
|
||||
description = "Heat Gravel",
|
||||
tiles = {"metal_melter_heat_gravel.png"},
|
||||
groups = {crumbly = 2, falling_node = 1},
|
||||
sounds = default.node_sound_gravel_defaults()
|
||||
})
|
||||
|
||||
minetest.register_node("metal_melter:heat_exchanger", {
|
||||
description = "Heat Exchanger Plate",
|
||||
tiles = {"metal_melter_heat_exchanger.png"},
|
||||
groups = {cracky = 3},
|
||||
place_param2 = 0,
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
drawtype = "nodebox",
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.5000, -0.5000, -0.5000, 0.5000, -0.4375, 0.5000}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_node('metal_melter:casting_table', {
|
||||
description = "Casting Table",
|
||||
paramtype = "light",
|
||||
drawtype = "nodebox",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.5000, 0.3750, -0.5000, 0.5000, 0.5000, 0.5000},
|
||||
{-0.4375, -0.5000, -0.4375, -0.3125, 0.3750, -0.3125},
|
||||
{0.3125, -0.5000, -0.4375, 0.4375, 0.3750, -0.3125},
|
||||
{-0.4375, -0.5000, 0.3125, -0.3125, 0.3750, 0.4375},
|
||||
{0.3125, -0.5000, 0.3125, 0.4375, 0.3750, 0.4375}
|
||||
}
|
||||
},
|
||||
tiles = {"metal_melter_heat_exchanger.png"},
|
||||
groups = {cracky = 3},
|
||||
sunlight_propagates = true,
|
||||
is_ground_content = false,
|
||||
})
|
||||
|
||||
|
||||
fluidity.register_fluid_tank({
|
||||
mod_name = "metal_melter",
|
||||
tank_name = "heated_tank",
|
||||
tank_description = "Heated Tank",
|
||||
capacity = 8,
|
||||
tiles = {"default_glass.png", "default_glass_detail.png"},
|
||||
fluids = {"default:lava_source"}
|
||||
})
|
||||
|
||||
-- Crafting
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'metal_melter:heat_gravel 4',
|
||||
recipe = {
|
||||
{'default:gravel', 'default:sand', 'default:gravel'},
|
||||
{'default:sand', 'default:clay', 'default:sand'},
|
||||
{'default:gravel', 'default:sand', 'default:gravel'},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'metal_melter:heat_gravel 4',
|
||||
recipe = {
|
||||
{'default:sand', 'default:sand', 'default:sand'},
|
||||
{'default:gravel', 'default:clay', 'default:gravel'},
|
||||
{'default:sand', 'default:sand', 'default:sand'},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'metal_melter:heated_bricks 4',
|
||||
recipe = {
|
||||
{'metal_melter:heated_brick', 'metal_melter:heated_brick'},
|
||||
{'metal_melter:heated_brick', 'metal_melter:heated_brick'},
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'metal_melter:heated_tank',
|
||||
recipe = {
|
||||
{'metal_melter:heated_brick', 'default:glass', 'metal_melter:heated_brick'},
|
||||
{'metal_melter:heated_brick', 'default:glass', 'metal_melter:heated_brick'},
|
||||
{'metal_melter:heated_brick', 'default:glass', 'metal_melter:heated_brick'},
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'metal_melter:heat_exchanger',
|
||||
recipe = {
|
||||
{'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
|
||||
{'metal_melter:heated_brick', 'metal_melter:heated_brick', 'metal_melter:heated_brick'},
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'metal_melter:casting_table',
|
||||
recipe = {
|
||||
{'metal_melter:heated_brick', 'metal_melter:heated_brick', 'metal_melter:heated_brick'},
|
||||
{'metal_melter:heated_brick', '', 'metal_melter:heated_brick'},
|
||||
{'metal_melter:heated_brick', '', 'metal_melter:heated_brick'},
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'metal_melter:metal_melter',
|
||||
recipe = {
|
||||
{'metal_melter:heated_bricks', 'metal_melter:heated_tank', 'metal_melter:heated_bricks'},
|
||||
{'metal_melter:heated_bricks', 'metal_melter:heat_exchanger', 'metal_melter:heated_bricks'},
|
||||
{'metal_melter:heated_bricks', 'metal_melter:heated_tank', 'metal_melter:heated_bricks'},
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'metal_melter:metal_caster',
|
||||
recipe = {
|
||||
{'metal_melter:heated_bricks', 'metal_melter:heated_tank', 'metal_melter:heated_bricks'},
|
||||
{'metal_melter:heated_bricks', 'metal_melter:heat_exchanger', 'metal_melter:casting_table'},
|
||||
{'metal_melter:heated_bricks', 'metal_melter:heated_tank', 'metal_melter:heated_bricks'},
|
||||
}
|
||||
})
|
||||
|
||||
-- Smelting
|
||||
|
||||
minetest.register_craft({
|
||||
type = "cooking",
|
||||
output = "metal_melter:heated_brick",
|
||||
recipe = "metal_melter:heat_gravel",
|
||||
cooktime = 3,
|
||||
})
|
4
metal_melter/depends.txt
Normal file
@ -0,0 +1,4 @@
|
||||
default
|
||||
bucket
|
||||
fluidity
|
||||
unified_inventory?
|
1
metal_melter/description.txt
Normal file
@ -0,0 +1 @@
|
||||
Melt and cast metals.
|
12
metal_melter/init.lua
Normal file
@ -0,0 +1,12 @@
|
||||
-- Melterns mod
|
||||
|
||||
local modpath = minetest.get_modpath("metal_melter")
|
||||
|
||||
-- Crafting components
|
||||
dofile(modpath.."/components.lua")
|
||||
|
||||
-- Melter
|
||||
dofile(modpath.."/melter.lua")
|
||||
|
||||
-- Caster
|
||||
dofile(modpath.."/caster.lua")
|
389
metal_melter/melter.lua
Normal file
@ -0,0 +1,389 @@
|
||||
-- Melts metals using lava as a heat source
|
||||
|
||||
metal_melter = {}
|
||||
|
||||
metal_melter.max_fuel = 8000
|
||||
metal_melter.max_metal = 16000
|
||||
metal_melter.spec = {
|
||||
ingot = 144,
|
||||
crystal = 144,
|
||||
block = 1000,
|
||||
lump = 288,
|
||||
ore = 288
|
||||
}
|
||||
|
||||
function metal_melter.get_metal_from_stack(stack)
|
||||
local metal = nil
|
||||
local metal_type = nil
|
||||
|
||||
-- Find a metal that is in the name
|
||||
for v,_ in pairs(fluidity.molten_metals) do
|
||||
if stack:find(v) then
|
||||
metal = v
|
||||
end
|
||||
end
|
||||
|
||||
if not metal then
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Find type
|
||||
if stack:find("lump") then
|
||||
metal_type = "lump"
|
||||
elseif stack:find("ingot") then
|
||||
metal_type = "ingot"
|
||||
elseif stack:find("ore") then
|
||||
metal_type = "ore"
|
||||
elseif stack:find("crystal") then
|
||||
metal_type = "crystal"
|
||||
else
|
||||
-- Assume block
|
||||
metal_type = "block"
|
||||
end
|
||||
|
||||
return metal, metal_type
|
||||
end
|
||||
|
||||
function metal_melter.get_metal_melter_formspec_default()
|
||||
return "size[8,8.5]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"list[context;input;2.25,0.2;1,1;]"..
|
||||
"list[context;heat;2.25,1.4;1,1;]"..
|
||||
"image[1.3,1.4;1,1;gui_furnace_arrow_bg.png^[transformR90]"..
|
||||
"image[0.08,0;1.4,2.8;melter_gui_barbg.png]"..
|
||||
"image[0.08,0;1.4,2.8;melter_gui_gauge.png]"..
|
||||
"label[0.08,3.4;Lava: 0/"..metal_melter.max_fuel.." mB]"..
|
||||
"image[6.68,0;1.4,2.8;melter_gui_barbg.png]"..
|
||||
"image[6.68,0;1.4,2.8;melter_gui_gauge.png]"..
|
||||
"label[0.08,3.75;No Molten Metal]"..
|
||||
"list[context;bucket_in;4.75,0.2;2,2;]"..
|
||||
"list[context;bucket_out;4.75,1.4;2,2;]"..
|
||||
"image[5.75,0.2;1,1;gui_furnace_arrow_bg.png^[transformR270]"..
|
||||
"image[5.75,1.4;1,1;gui_furnace_arrow_bg.png^[transformR90]"..
|
||||
"list[current_player;main;0,4.25;8,1;]"..
|
||||
"list[current_player;main;0,5.5;8,3;8]"..
|
||||
"listring[context;heat]"..
|
||||
"listring[current_player;main]"..
|
||||
"listring[context;input]"..
|
||||
"listring[current_player;main]"..
|
||||
"listring[context;bucket_in]"..
|
||||
"listring[current_player;main]"..
|
||||
"listring[context;bucket_out]"..
|
||||
"listring[current_player;main]"..
|
||||
default.get_hotbar_bg(0, 4.25)
|
||||
end
|
||||
|
||||
function metal_melter.get_metal_melter_formspec(data)
|
||||
local lava_percent = data.lava_level / metal_melter.max_fuel
|
||||
local metal_percent = data.metal_level / metal_melter.max_metal
|
||||
|
||||
local metal_formspec = "label[0.08,3.75;No Molten Metal]"
|
||||
|
||||
if data.metal ~= "" then
|
||||
metal_formspec = "label[0.08,3.75;"..data.metal..": "..data.metal_level.."/"..metal_melter.max_metal.." mB]"
|
||||
end
|
||||
|
||||
return "size[8,8.5]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"list[context;input;2.25,0.2;1,1;]"..
|
||||
"list[context;heat;2.25,1.4;1,1;]"..
|
||||
"image[1.3,1.4;1,1;gui_furnace_arrow_bg.png^[transformR90]"..
|
||||
"image[0.08,0;1.4,2.8;melter_gui_barbg.png]"..
|
||||
"image[0.08,"..(2.44 - lava_percent * 2.44)..";1.4,"..(lava_percent * 2.8)..";default_lava.png]"..
|
||||
"image[0.08,0;1.4,2.8;melter_gui_gauge.png]"..
|
||||
"label[0.08,3.4;Lava: "..data.lava_level.."/"..metal_melter.max_fuel.." mB]"..
|
||||
"image[6.68,0;1.4,2.8;melter_gui_barbg.png]"..
|
||||
"image[6.68,"..(2.44 - metal_percent * 2.44)..";1.4,"..(metal_percent * 2.8)..";"..data.metal_texture.."]"..
|
||||
"image[6.68,0;1.4,2.8;melter_gui_gauge.png]"..
|
||||
metal_formspec..
|
||||
"list[context;bucket_in;4.75,0.2;1,1;]"..
|
||||
"list[context;bucket_out;4.75,1.4;1,1;]"..
|
||||
"image[5.75,0.2;1,1;gui_furnace_arrow_bg.png^[transformR270]"..
|
||||
"image[5.75,1.4;1,1;gui_furnace_arrow_bg.png^[transformR90]"..
|
||||
"list[current_player;main;0,4.25;8,1;]"..
|
||||
"list[current_player;main;0,5.5;8,3;8]"..
|
||||
"listring[context;heat]"..
|
||||
"listring[current_player;main]"..
|
||||
"listring[context;input]"..
|
||||
"listring[current_player;main]"..
|
||||
"listring[context;bucket_in]"..
|
||||
"listring[current_player;main]"..
|
||||
"listring[context;bucket_out]"..
|
||||
"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 == "bucket_out" then
|
||||
if stack:get_name() ~= "bucket:bucket_empty" then
|
||||
return 0
|
||||
end
|
||||
|
||||
return 1
|
||||
end
|
||||
|
||||
if listname == "heat" then
|
||||
if stack:get_name() ~= "bucket:bucket_lava" then
|
||||
return 0
|
||||
end
|
||||
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 take_from_stack(stack, count)
|
||||
-- Take count from stack, return nil if the item count reaches 0
|
||||
local newcount = stack:get_count() - count
|
||||
if newcount <= 0 then
|
||||
return nil
|
||||
end
|
||||
|
||||
stack:set_count(newcount)
|
||||
return stack
|
||||
end
|
||||
|
||||
local function swap_node(pos, name)
|
||||
local node = minetest.get_node(pos)
|
||||
if node.name == name then
|
||||
return
|
||||
end
|
||||
node.name = name
|
||||
minetest.swap_node(pos, node)
|
||||
end
|
||||
|
||||
local function melter_node_timer(pos, elapsed)
|
||||
local refresh = false
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
|
||||
-- Current amount of lava in the block
|
||||
local heat_count = meta:get_int("lava_level")
|
||||
|
||||
-- Current amount of metal in the block
|
||||
local metal_count = meta:get_int("metal_level")
|
||||
|
||||
-- Current metal used
|
||||
local metal = meta:get_string("metal")
|
||||
|
||||
-- Insert lava bucket into tank, return empty bucket
|
||||
if inv:get_stack("heat", 1):get_name() == "bucket:bucket_lava" then
|
||||
if heat_count + 1000 <= metal_melter.max_fuel then
|
||||
heat_count = heat_count + 1000
|
||||
inv:set_list("heat", {"bucket:bucket_empty"})
|
||||
refresh = true
|
||||
end
|
||||
end
|
||||
|
||||
-- Handle input bucket, only allow a molten metal
|
||||
local bucket_in = inv:get_stack("bucket_in", 1):get_name()
|
||||
if bucket_in:find("bucket") and bucket_in ~= "bucket:bucket_empty" then
|
||||
local bucket_fluid = fluidity.get_fluid_for_bucket(bucket_in)
|
||||
local fluid_is_metal = fluidity.get_metal_for_fluid(bucket_fluid) ~= nil
|
||||
local empty_bucket = false
|
||||
|
||||
if fluid_is_metal then
|
||||
if metal ~= "" and metal == bucket_fluid then
|
||||
if metal_count + 1000 <= metal_melter.max_metal then
|
||||
metal_count = metal_count + 1000
|
||||
empty_bucket = true
|
||||
end
|
||||
elseif metal == "" then
|
||||
metal_count = 1000
|
||||
metal = bucket_fluid
|
||||
empty_bucket = true
|
||||
end
|
||||
end
|
||||
|
||||
if empty_bucket then
|
||||
inv:set_list("bucket_in", {"bucket:bucket_empty"})
|
||||
refresh = true
|
||||
end
|
||||
end
|
||||
|
||||
-- Handle bucket output, only allow empty buckets in this slot
|
||||
local bucket_out = inv:get_stack("bucket_out", 1):get_name()
|
||||
if bucket_out == "bucket:bucket_empty" and metal ~= "" then
|
||||
local bucket = fluidity.get_bucket_for_fluid(metal)
|
||||
if metal_count >= 1000 then
|
||||
metal_count = metal_count - 1000
|
||||
inv:set_list("bucket_out", {bucket})
|
||||
refresh = true
|
||||
|
||||
if metal_count == 0 then
|
||||
metal = ""
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Handle metal input. Must be a: ingot, lump, block or ore.
|
||||
local input = inv:get_stack("input", 1):get_name()
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Refresh metadata and formspec
|
||||
if refresh then
|
||||
meta:set_int("lava_level", heat_count)
|
||||
meta:set_int("metal_level", metal_count)
|
||||
meta:set_string("metal", metal)
|
||||
|
||||
local metal_texture = "default_lava.png"
|
||||
local metal_name = ""
|
||||
|
||||
local infotext = "Metal Melter\n"
|
||||
infotext = infotext.."Lava: "..heat_count.."/"..metal_melter.max_fuel.." mB \n"
|
||||
|
||||
if metal ~= "" then
|
||||
metal_texture = "fluidity_"..fluidity.get_metal_for_fluid(metal)..".png"
|
||||
|
||||
local metal_node = minetest.registered_nodes[metal]
|
||||
metal_name = fluidity.fluid_name(metal_node.description)
|
||||
infotext = infotext..metal_name..": "..metal_count.."/"..metal_melter.max_metal.." mB"
|
||||
else
|
||||
infotext = infotext.."No Molten Metal"
|
||||
end
|
||||
|
||||
if heat_count > 144 then
|
||||
swap_node(pos, "metal_melter:metal_melter_filled")
|
||||
else
|
||||
swap_node(pos, "metal_melter:metal_melter")
|
||||
end
|
||||
|
||||
meta:set_string("infotext", infotext)
|
||||
meta:set_string("formspec", metal_melter.get_metal_melter_formspec(
|
||||
{lava_level=heat_count, metal_level=metal_count, metal_texture=metal_texture, metal=metal_name}))
|
||||
end
|
||||
|
||||
-- If true, calls for another clock cycle.
|
||||
return refresh
|
||||
end
|
||||
|
||||
local function on_construct(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("formspec", metal_melter.get_metal_melter_formspec_default())
|
||||
|
||||
-- Create inventory
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size('input', 1)
|
||||
inv:set_size('heat', 1)
|
||||
inv:set_size('bucket_in', 1)
|
||||
inv:set_size('bucket_out', 1)
|
||||
|
||||
-- Fluid buffers
|
||||
meta:set_int('lava_level', 0)
|
||||
meta:set_int('metal_level', 0)
|
||||
|
||||
-- Metal source block
|
||||
meta:set_string('metal', '')
|
||||
|
||||
-- Default infotext
|
||||
meta:set_string("infotext", "Metal Melter Inactive")
|
||||
end
|
||||
|
||||
local function can_dig(pos, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
return inv:is_empty("input") and inv:is_empty("heat") and inv:is_empty("bucket_in") and inv:is_empty("bucket_out")
|
||||
end
|
||||
|
||||
minetest.register_node("metal_melter:metal_melter", {
|
||||
description = "Metal Melter",
|
||||
tiles = {
|
||||
"melter_side.png", "melter_side.png",
|
||||
"melter_side.png", "melter_side.png",
|
||||
"melter_side.png", "melter_front.png"
|
||||
},
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2},
|
||||
legacy_facedir_simple = true,
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
|
||||
can_dig = can_dig,
|
||||
on_timer = melter_node_timer,
|
||||
on_construct = on_construct,
|
||||
on_metadata_inventory_move = function(pos)
|
||||
minetest.get_node_timer(pos):start(1.0)
|
||||
end,
|
||||
on_metadata_inventory_put = function(pos)
|
||||
minetest.get_node_timer(pos):start(1.0)
|
||||
end,
|
||||
on_blast = function(pos)
|
||||
local drops = {}
|
||||
default.get_inventory_drops(pos, "input", drops)
|
||||
default.get_inventory_drops(pos, "heat", drops)
|
||||
default.get_inventory_drops(pos, "bucket_in", drops)
|
||||
default.get_inventory_drops(pos, "bucket_out", drops)
|
||||
drops[#drops+1] = "metal_melter:metal_melter"
|
||||
minetest.remove_node(pos)
|
||||
return drops
|
||||
end,
|
||||
|
||||
allow_metadata_inventory_put = allow_metadata_inventory_put,
|
||||
allow_metadata_inventory_move = allow_metadata_inventory_move,
|
||||
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
||||
})
|
||||
|
||||
minetest.register_node("metal_melter:metal_melter_filled", {
|
||||
tiles = {
|
||||
"melter_side.png", "melter_side.png",
|
||||
"melter_side.png", "melter_side.png",
|
||||
"melter_side.png", "melter_front.png^melter_front_lava.png"
|
||||
},
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2,not_in_creative_inventory=1},
|
||||
legacy_facedir_simple = true,
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
|
||||
drop = "metal_melter:metal_melter",
|
||||
light_source = 8,
|
||||
can_dig = can_dig,
|
||||
on_timer = melter_node_timer,
|
||||
on_construct = on_construct,
|
||||
|
||||
on_metadata_inventory_move = function(pos)
|
||||
minetest.get_node_timer(pos):start(1.0)
|
||||
end,
|
||||
on_metadata_inventory_put = function(pos)
|
||||
minetest.get_node_timer(pos):start(1.0)
|
||||
end,
|
||||
|
||||
allow_metadata_inventory_put = allow_metadata_inventory_put,
|
||||
allow_metadata_inventory_move = allow_metadata_inventory_move,
|
||||
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
||||
})
|
4
metal_melter/mod.conf
Normal file
@ -0,0 +1,4 @@
|
||||
name = metal_melter
|
||||
description = Melt and cast metals.
|
||||
depends = default,fluidity,bucket
|
||||
optional_depends = unified_inventory
|
BIN
metal_melter/screenshot.png
Normal file
After Width: | Height: | Size: 472 KiB |
BIN
metal_melter/textures/caster_blank_cast.png
Normal file
After Width: | Height: | Size: 525 B |
BIN
metal_melter/textures/caster_front.png
Normal file
After Width: | Height: | Size: 405 B |
BIN
metal_melter/textures/caster_gem_cast.png
Normal file
After Width: | Height: | Size: 626 B |
BIN
metal_melter/textures/caster_ingot_cast.png
Normal file
After Width: | Height: | Size: 550 B |
BIN
metal_melter/textures/caster_lump_cast.png
Normal file
After Width: | Height: | Size: 614 B |
BIN
metal_melter/textures/melter_front.png
Normal file
After Width: | Height: | Size: 385 B |
BIN
metal_melter/textures/melter_front_active.png
Normal file
After Width: | Height: | Size: 474 B |
BIN
metal_melter/textures/melter_front_lava.png
Normal file
After Width: | Height: | Size: 753 B |
BIN
metal_melter/textures/melter_gui_barbg.png
Normal file
After Width: | Height: | Size: 201 B |
BIN
metal_melter/textures/melter_gui_gauge.png
Normal file
After Width: | Height: | Size: 489 B |
BIN
metal_melter/textures/melter_side.png
Normal file
After Width: | Height: | Size: 363 B |
BIN
metal_melter/textures/metal_melter_heat_exchanger.png
Normal file
After Width: | Height: | Size: 397 B |
BIN
metal_melter/textures/metal_melter_heat_gravel.png
Normal file
After Width: | Height: | Size: 773 B |
BIN
metal_melter/textures/metal_melter_heatbrick.png
Normal file
After Width: | Height: | Size: 482 B |
BIN
metal_melter/textures/metal_melter_heated_brick.png
Normal file
After Width: | Height: | Size: 286 B |