Depend on fluid_lib

This commit is contained in:
Evert Prants 2018-06-20 19:58:58 +03:00
parent c47f07fbcd
commit 3424d682ed
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
11 changed files with 39 additions and 381 deletions

View File

@ -3,6 +3,8 @@
An in-development mod for [Minetest](http://minetest.net) 0.5.0+ that adds molten metals, melting, casting and creating tools. This mod is inspired by the [Tinkers Construct](https://minecraft.curseforge.com/projects/tinkers-construct) mod for Minecraft, however it's much less-featured due to the current limitations of the Minetest API. None of the components used in this mod have been taken from TC - everything is my original creation.
**Depends on [fluid_lib](https://gitlab.icynet.eu/evert/fluid_lib)!**
## Installation
Just do `git clone https://gitlab.icynet.eu/evert/melterns.git` in your `minetest/mods` directory. You can also [download the repository](https://gitlab.icynet.eu/evert/melterns/archive/master.zip) but in that case you **must** change the folder name from `melterns-master` to `melterns`!

View File

@ -42,8 +42,8 @@ end
function fluidity.florbs.add_fluid(stack, source_name, amount)
if not fluidity.florbs.get_is_florb(stack) then return nil end
local source_node = fluidity.get_fluid_node(source_name)
local fluid = fluidity.fluid_name(source_node.description)
local source_node = minetest.registered_nodes[source_name]
local fluid = fluid_lib.cleanse_node_description(source_name)
local internal = fluidity.fluid_short(fluid)
local florbname = stack:get_name()
@ -95,8 +95,8 @@ function fluidity.florbs.take_fluid(stack, amount)
end
local function register_florbfluid(data)
local source_node = fluidity.get_fluid_node(data.source_name)
local fluid = fluidity.fluid_name(source_node.description)
local source_node = minetest.registered_nodes[data.source_name]
local fluid = fluid_lib.cleanse_node_description(data.source_name)
local internal = fluidity.fluid_short(fluid)
local itemname = data.mod_name..":"..data.florb_name.."_"..internal

View File

@ -1,7 +0,0 @@
function fluidity.fluid_name(name)
return name:gsub("% Source$", "")
end
function fluidity.fluid_short(str)
return string.lower(str):gsub("%s", "_")
end

View File

@ -6,15 +6,13 @@ fluidity = rawget(_G, "fluidity") or {}
local mpath = minetest.get_modpath("fluidity")
fluidity.modpath = mpath
-- Functions
dofile(mpath.."/functions.lua")
function fluidity.fluid_short(str)
return string.lower(str):gsub("%s", "_")
end
-- Molten metals
dofile(mpath.."/molten.lua")
-- Tanks
dofile(mpath.."/tanks.lua")
-- Florbs
dofile(mpath.."/florbs.lua")

View File

@ -1,4 +1,4 @@
name = fluidity
description = Adds Molten versions of commonly occuring metals. Supports default, technic and moreores.
depends = default,bucket
depends = default,fluid_lib,bucket
optional_depends = technic,moreores

View File

@ -7,14 +7,6 @@ for _,v in pairs(metals) do
fluidity.register_molten_metal(v)
end
-- Register tanks for all fluids
fluidity.tanks.register_fluid_tank({
tank_name = "fluid_tank",
tank_description = "Fluid Tank",
capacity = 64000,
tiles = {"default_glass.png", "default_glass_detail.png"}
})
-- Register florbs for all fluids
fluidity.florbs.register_florb({
florb_name = "florb",

View File

@ -1,325 +0,0 @@
-- Register tanks for each fluid
fluidity.bucket_cache = {}
fluidity.tanks = {}
-- 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
-- Ensure that this fluid node exists.
function fluidity.get_fluid_node(name)
return minetest.registered_nodes[name]
end
-- Get a nodedef field.
local function get_nodedef_field(nodename, fieldname)
if not minetest.registered_nodes[nodename] then
return nil
end
return minetest.registered_nodes[nodename][fieldname]
end
-- Ensure that the node is a tank.
function fluidity.tanks.get_is_tank(node)
return minetest.get_item_group(node, "fluidity_tank") > 0
end
-- Ensure that the node is an empty tank.
function fluidity.tanks.get_is_empty_tank(node)
return minetest.get_item_group(node, "fluidity_tank_empty") > 0
end
-- Get tank data at position.
-- Returns fluid name, fluid level, capacity, base tank name and the mod it was added from.
-- Base tank name and mod name are used to construct different variants of this tank type.
function fluidity.tanks.get_tank_at(pos)
local meta = minetest.get_meta(pos)
local node = minetest.get_node(pos)
if not fluidity.tanks.get_is_tank(node.name) then return nil end
local ffluid = get_nodedef_field(node.name, "fluidity_fluid")
local fcapacity = get_nodedef_field(node.name, "_capacity")
local fbasetank = get_nodedef_field(node.name, "_dataname")
local fmod = get_nodedef_field(node.name, "_mod")
local fluidcount = meta:get_int("fluid")
return ffluid, fluidcount, fcapacity, fbasetank, fmod
end
-- Check to see if a fluid can go in the tank and pos.
function fluidity.tanks.can_fluid_go_in_tank(pos, fluid)
local fluid_name, count, capacity, base_tank, mod = fluidity.tanks.get_tank_at(pos)
if not fluid_name then return true end
if fluid_name ~= fluid then return false end
if count == capacity then return false end
local source_node = fluidity.get_fluid_node(fluid)
local fluid_desc = fluidity.fluid_name(source_node.description)
local shorthand_name = fluidity.fluid_short(fluid_desc)
if not minetest.registered_nodes[mod..":"..base_tank.."_"..shorthand_name] then return false end
return true
end
-- Fill the tank at pos with fluid.
-- Overfilling means it will return an integer as the second variable that shows the amount over the capacity.
function fluidity.tanks.fill_tank_at(pos, fluid, amount, overfill)
local fluid_name, count, capacity, base_tank, mod = fluidity.tanks.get_tank_at(pos)
if not fluid_name == fluid and fluid_name ~= nil then return nil end
local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
local node_name = mod..":"..base_tank
local remainder = 0
if count + amount > capacity then
if overfill then
remainder = capacity - count
count = capacity
else
return nil
end
else
count = count + amount
end
local source_node = fluidity.get_fluid_node(fluid)
local fluid_desc = fluidity.fluid_name(source_node.description)
local shorthand_name = fluidity.fluid_short(fluid_desc)
node_name = mod..":"..base_tank.."_"..shorthand_name
if not minetest.registered_nodes[node_name] then return nil end
meta:set_int("fluid", count)
meta:set_string("infotext", "Tank of "..fluid_desc.."("..count.."/"..capacity.." mB)")
local param2 = math.min((count/capacity)*63, 63)
minetest.swap_node(pos, {name=node_name,param1=node.param1,param2=param2})
return fluid, remainder
end
-- Take some fluid from the tank at pos.
-- Underfill returns an integer as the second variable indicating level below zero.
function fluidity.tanks.take_from_tank_at(pos, amount, underfill)
local fluid_name, count, capacity, base_tank, mod = fluidity.tanks.get_tank_at(pos)
if not fluid_name then return nil end
local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
local node_name = mod..":"..base_tank
local fluid = fluid_name
local leftover = 0
if count - amount < 0 then
if underfill then
leftover = (count - amount) * -1
count = 0
else
return nil
end
else
count = count - amount
end
if count == 0 then
fluid = nil
end
meta:set_int("fluid", count)
if fluid then
local source_node = fluidity.get_fluid_node(fluid)
local fluid_desc = fluidity.fluid_name(source_node.description)
local shorthand_name = fluidity.fluid_short(fluid_desc)
node_name = mod..":"..base_tank.."_"..shorthand_name
meta:set_string("infotext", "Tank of "..fluid_desc.."("..count.."/"..capacity.." mB)")
else
meta:set_string("infotext", "Empty Tank")
end
local param2 = math.min((count/capacity)*63, 63)
minetest.swap_node(pos, {name=node_name,param1=node.param1,param2=param2})
return fluid_name, leftover
end
local function bucket_fill(pos, node, clicker, itemstack, pointed_thing)
local stackname = itemstack:get_name()
local stack = "bucket:bucket_empty"
if not stackname:find("bucket") then
return itemstack
end
if stackname == "bucket:bucket_empty" then
if fluidity.tanks.get_is_empty_tank(node.name) then
return itemstack
end
local fluid = fluidity.tanks.take_from_tank_at(pos, 1000)
if not fluid then
return itemstack
end
stack = fluidity.get_bucket_for_fluid(fluid)
else
local srcnode = fluidity.get_fluid_for_bucket(stackname)
if not fluidity.tanks.can_fluid_go_in_tank(pos, srcnode) then
return itemstack
end
local fluid = fluidity.tanks.fill_tank_at(pos, srcnode, 1000)
if fluid == nil then
return itemstack
end
end
return ItemStack(stack)
end
-- Preserve fluid count in the item stack dropped
local function preserve_metadata(pos, oldnode, oldmeta, drops)
local fluid_name, count, capacity = fluidity.tanks.get_tank_at(pos)
local meta = minetest.get_meta(pos)
local fluid_cnt = meta:get_int("fluid")
local nodedesc = get_nodedef_field(oldnode.name, "description")
for i,stack in pairs(drops) do
local stack_meta = stack:get_meta()
stack_meta:set_int("fluid", fluid_cnt)
stack_meta:set_string("description", nodedesc.."\nContains "..count.."/"..capacity.." mB")
drops[i] = stack
end
return drops
end
-- Retrieve fluid count from itemstack when placed
local function after_place_node(pos, placer, itemstack, pointed_thing)
local item_meta = itemstack:get_meta()
local fluid_cnt = item_meta:get_int("fluid")
local fluid = get_nodedef_field(itemstack:get_name(), "fluidity_fluid")
if fluid_cnt then
-- Fill the tank to the count specified in item meta, don't care about overfill or what it returns.
fluidity.tanks.fill_tank_at(pos, fluid, fluid_cnt, true)
end
return false
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)
local nodename = data.mod_name..":"..data.tank_name.."_"..internal
if minetest.registered_nodes[nodename] then
return
end
minetest.register_node(nodename, {
description = data.tank_description.." ("..fluid..")",
drawtype = "glasslike_framed_optional",
paramtype = "light",
paramtype2 = "glasslikeliquidlevel",
fluidity_fluid = data.source_name,
place_param2 = 0,
special_tiles = source_node.tiles,
is_ground_content = false,
sunlight_propagates = true,
on_rightclick = bucket_fill,
preserve_metadata = preserve_metadata,
after_place_node = after_place_node,
_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.tanks.register_fluid_tank(data)
local modname = data.mod_name or minetest.get_current_modname()
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 64000
local tanknode = modname..":"..tankname
if not minetest.registered_nodes[tanknode] then
minetest.register_node(tanknode, {
description = tankdesc,
drawtype = "glasslike_framed_optional",
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, fluid_tank_empty = 1},
tiles = tiles
})
end
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

View File

@ -52,8 +52,8 @@ function metal_caster.get_metal_caster_formspec_default()
end
function metal_caster.get_metal_caster_formspec(data)
local water_percent = data.water_fluid_storage / metal_caster.max_coolant
local metal_percent = data.metal_fluid_storage / metal_caster.max_metal
local water_percent = math.floor(100 * data.water_fluid_storage / metal_caster.max_coolant)
local metal_percent = math.floor(100 * data.metal_fluid_storage / metal_caster.max_metal)
local metal_formspec = "label[0.08,3.75;No Molten Metal]"
@ -69,12 +69,12 @@ function metal_caster.get_metal_caster_formspec(data)
"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_barbg.png"..
"\\^[lowpart\\:" .. water_percent .. "\\:default_water.png\\\\^[resize\\\\:64x128]"..
"image[0.08,0;1.4,2.8;melter_gui_gauge.png]"..
"label[0.08,3.4;Water: "..data.water_fluid_storage.."/"..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_barbg.png"..
"\\^[lowpart\\:" .. metal_percent .. "\\:"..data.metal_texture.."\\\\^[resize\\\\:64x128]"..
"image[6.68,0;1.4,2.8;melter_gui_gauge.png]"..
metal_formspec..
"list[context;bucket_in;4.7,0.2;1,1;]"..
@ -434,8 +434,7 @@ local function caster_node_timer(pos, elapsed)
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)
metal_name = fluid_lib.cleanse_node_description(metal)
infotext = infotext..metal_name..": "..metal_count.."/"..metal_caster.max_metal.." mB"
else
infotext = infotext.."No Molten Metal"
@ -584,8 +583,9 @@ minetest.register_node("metal_melter:metal_caster", {
fluid_buffers = {
water = {
capacity = metal_caster.max_coolant,
accepts = {"default:water_source"}
capacity = metal_caster.max_coolant,
accepts = {"default:water_source"},
drainable = false,
},
metal = {
capacity = metal_caster.max_metal,

View File

@ -65,14 +65,11 @@ minetest.register_node('metal_melter:casting_table', {
is_ground_content = false,
})
fluidity.tanks.register_fluid_tank({
mod_name = "metal_melter",
tank_name = "heated_tank",
tank_description = "Heated Tank",
capacity = 8000,
tiles = {"melter_heated_tank.png"},
fluids = {"default:lava_source"}
fluid_tanks.register_tank("metal_melter:heated_tank",{
description = "Heated Tank",
capacity = 8000,
tiles = {"melter_heated_tank.png"},
accepts = {"default:lava_source"}
})
-- Crafting

View File

@ -82,8 +82,8 @@ function metal_melter.get_metal_melter_formspec_default()
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 lava_percent = math.floor(100 * data.lava_level / metal_melter.max_fuel)
local metal_percent = math.floor(100 * data.metal_level / metal_melter.max_metal)
local metal_formspec = "label[0.08,3.75;No Molten Metal]"
@ -98,12 +98,12 @@ function metal_melter.get_metal_melter_formspec(data)
"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_barbg.png"..
"\\^[lowpart\\:" .. lava_percent .. "\\:default_lava.png\\\\^[resize\\\\:64x128]"..
"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_barbg.png"..
"\\^[lowpart\\:" .. metal_percent .. "\\:"..data.metal_texture.."\\\\^[resize\\\\:64x128]"..
"image[6.68,0;1.4,2.8;melter_gui_gauge.png]"..
metal_formspec..
"list[context;bucket_in;4.7,0.2;1,1;]"..
@ -339,8 +339,7 @@ local function melter_node_timer(pos, elapsed)
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)
metal_name = fluid_lib.cleanse_node_description(metal)
infotext = infotext..metal_name..": "..metal_count.."/"..metal_melter.max_metal.." mB"
else
infotext = infotext.."No Molten Metal"
@ -476,8 +475,9 @@ minetest.register_node("metal_melter:metal_melter", {
fluid_buffers = {
lava = {
capacity = metal_melter.max_fuel,
accepts = {"default:lava_source"}
capacity = metal_melter.max_fuel,
accepts = {"default:lava_source"},
drainable = false,
},
metal = {
capacity = metal_melter.max_metal
@ -525,8 +525,9 @@ minetest.register_node("metal_melter:metal_melter_filled", {
fluid_buffers = {
lava = {
capacity = metal_melter.max_fuel,
accepts = {"default:lava_source"}
capacity = metal_melter.max_fuel,
accepts = {"default:lava_source"},
drainable = false,
},
metal = {
capacity = metal_melter.max_metal

View File

@ -1,4 +1,4 @@
name = metal_melter
description = Melt and cast metals.
depends = default,fluidity,bucket
depends = default,fluidity,bucket,fluid_tanks
optional_depends = pipeworks