small api change

This commit is contained in:
Evert Prants 2018-05-26 11:52:10 +03:00
parent 2dd09f2b04
commit b1340e953e
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
4 changed files with 106 additions and 83 deletions

View File

@ -99,10 +99,16 @@ local function register_florbfluid(data)
local fluid = fluidity.fluid_name(source_node.description) local fluid = fluidity.fluid_name(source_node.description)
local internal = fluidity.fluid_short(fluid) local internal = fluidity.fluid_short(fluid)
local itemname = data.mod_name..":"..data.florb_name.."_"..internal
if minetest.registered_items[itemname] then
return
end
local stationary_name = source_node.tiles[1].name:gsub("_source_animated", "") local stationary_name = source_node.tiles[1].name:gsub("_source_animated", "")
-- Register base item -- Register base item
minetest.register_craftitem(data.mod_name..":"..data.florb_name.."_"..internal, { minetest.register_craftitem(itemname, {
description = data.florb_description.." ("..fluid..")", description = data.florb_description.." ("..fluid..")",
inventory_image = stationary_name.."^[noalpha^"..data.textures[1].."^"..data.textures[2].."^[makealpha:255,0,0,", inventory_image = stationary_name.."^[noalpha^"..data.textures[1].."^"..data.textures[2].."^[makealpha:255,0,0,",
_florb_capacity = data.capacity, _florb_capacity = data.capacity,
@ -114,21 +120,24 @@ local function register_florbfluid(data)
end end
function fluidity.florbs.register_florb(data) function fluidity.florbs.register_florb(data)
local mod_name = data.mod_name or minetest.get_current_modname() local mod_name = data.mod_name or minetest.get_current_modname()
local florb_name = data.florb_name or 'florb' local florb_name = data.florb_name or 'florb'
local florb_desc = data.florb_description or 'Florb' local florb_desc = data.florb_description or 'Florb'
local textures = data.textures or {"fluidity_florb.png", "fluidity_florb_mask.png"} local textures = data.textures or {"fluidity_florb.png", "fluidity_florb_mask.png"}
local capacity = data.capacity or 1000 local capacity = data.capacity or 1000
local item_name = mod_name..":"..florb_name
-- Register base item if not minetest.registered_items[item_name] then
minetest.register_craftitem(mod_name..":"..florb_name, { -- Register base item
description = florb_desc.." (Empty)\nThis item holds millibuckets of fluid.", minetest.register_craftitem(item_name, {
inventory_image = textures[1].."^[noalpha^"..textures[2].."^[makealpha:255,0,0,", description = florb_desc.." (Empty)\nThis item holds millibuckets of fluid.",
_florb_capacity = capacity, inventory_image = textures[1].."^[noalpha^"..textures[2].."^[makealpha:255,0,0,",
_florb_source = nil, _florb_capacity = capacity,
stack_max = 1, _florb_source = nil,
groups = {florb = 1, florb_blank = 1} stack_max = 1,
}) groups = {florb = 1, florb_blank = 1}
})
end
-- Register for all fluids -- Register for all fluids
if data.fluids then if data.fluids then

View File

@ -232,7 +232,13 @@ local function register_tankfluid(data)
local fluid = fluidity.fluid_name(source_node.description) local fluid = fluidity.fluid_name(source_node.description)
local internal = fluidity.fluid_short(fluid) local internal = fluidity.fluid_short(fluid)
minetest.register_node(data.mod_name..":"..data.tank_name.."_"..internal, { 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..")", description = data.tank_description.." ("..fluid..")",
drawtype = "glasslike_framed_optional", drawtype = "glasslike_framed_optional",
paramtype = "light", paramtype = "light",
@ -260,27 +266,30 @@ function fluidity.tanks.register_fluid_tank(data)
local tankdesc = data.tank_description or 'Fluid Tank' local tankdesc = data.tank_description or 'Fluid Tank'
local tiles = data.tiles or {"default_glass.png", "default_glass_detail.png"} local tiles = data.tiles or {"default_glass.png", "default_glass_detail.png"}
local capacity = data.capacity or 64000 local capacity = data.capacity or 64000
local tanknode = modname..":"..tankname
minetest.register_node(modname..":"..tankname, { if not tanknode then
description = tankdesc, minetest.register_node(tanknode, {
drawtype = "glasslike_framed_optional", description = tankdesc,
paramtype = "light", drawtype = "glasslike_framed_optional",
paramtype2 = "glasslikeliquidlevel", paramtype = "light",
is_ground_content = false, paramtype2 = "glasslikeliquidlevel",
sunlight_propagates = true, is_ground_content = false,
fluidity_fluid = nil, sunlight_propagates = true,
on_construct = function ( pos ) fluidity_fluid = nil,
local meta = minetest.get_meta(pos) on_construct = function ( pos )
meta:set_int("fluid", 0) local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Empty "..tankdesc) meta:set_int("fluid", 0)
end, meta:set_string("infotext", "Empty "..tankdesc)
on_rightclick = bucket_fill, end,
_mod = modname, on_rightclick = bucket_fill,
_dataname = tankname, _mod = modname,
_capacity = capacity, _dataname = tankname,
groups = {cracky = 1, oddly_breakable_by_hand = 3, fluidity_tank = 1, fluid_tank_empty = 1}, _capacity = capacity,
tiles = tiles groups = {cracky = 1, oddly_breakable_by_hand = 3, fluidity_tank = 1, fluid_tank_empty = 1},
}) tiles = tiles
})
end
if data.fluids then if data.fluids then
-- This tank only uses certain fluids -- This tank only uses certain fluids

View File

@ -6,10 +6,8 @@ local num_tools = 0
-- Create base tools -- Create base tools
for m, s in pairs(tinkering.materials) do for m, s in pairs(tinkering.materials) do
for t,_ in pairs(tinkering.tools) do tinkering.register_material_tool(m)
tinkering.create_tool(t, {main=m,binding="wood",rod="wood"}, false, nil) num_tools = num_tools + 1
num_tools = num_tools + 1
end
end end
-- Register tool components -- Register tool components

View File

@ -71,7 +71,7 @@ tinkering.components = {
} }
-- Create component for material -- Create component for material
local function create_material_component(data) function tinkering.create_material_component(data)
local desc = data.description local desc = data.description
local name = data.name local name = data.name
local mod = data.mod_name local mod = data.mod_name
@ -87,51 +87,6 @@ local function create_material_component(data)
}) })
end end
-- Register a new tool component
function tinkering.register_component(name, data)
local mod = data.mod_name or minetest.get_current_modname()
if not tinkering.components[name] then
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 = data.material_cost,
typenames = {name}
})
-- Register pattern
tinkering.register_pattern(name, {
description = comp_desc,
cost = data.material_cost,
mod_name = mod
})
-- Register components for all materials
for m, s in pairs(tinkering.materials) do
local component = m.."_"..name
create_material_component({
name = component,
component = name,
metal = m,
mod_name = mod,
description = data.description:format(s.name),
image = tinkering.color_filter(data.image, s.color)
})
-- Make all components meltable
metal_melter.register_melt(mod..":"..component, m, name)
end
end
-- Register a tool type -- Register a tool type
-- --
--data = { --data = {
@ -363,7 +318,7 @@ function tinkering.create_tool(tool_type, materials, want_tool, custom_name, ove
local internal_name = mod_name..":"..materials.main.."_"..tool_type local internal_name = mod_name..":"..materials.main.."_"..tool_type
-- Register base tool if it doesnt exist already -- Register base tool if it doesnt exist already
if not minetest.registered_items[internal_name] then if not minetest.registered_items[internal_name] and minetest.get_current_modname() then
minetest.register_tool(internal_name, tool_def) minetest.register_tool(internal_name, tool_def)
end end
@ -414,3 +369,55 @@ function tinkering.create_tool(tool_type, materials, want_tool, custom_name, ove
return tool return tool
end end
-- Register new tool material
function tinkering.register_material_tool(material)
for t,_ in pairs(tinkering.tools) do
tinkering.create_tool(t, {main=material,binding="wood",rod="wood"}, false, nil)
end
end
-- Register a new tool component
function tinkering.register_component(name, data)
local mod = data.mod_name or minetest.get_current_modname()
if not tinkering.components[name] then
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 = data.material_cost,
typenames = {name}
})
-- Register pattern
tinkering.register_pattern(name, {
description = comp_desc,
cost = data.material_cost,
mod_name = mod
})
-- Register components for all materials
for m, s in pairs(tinkering.materials) do
local component = m.."_"..name
tinkering.create_material_component({
name = component,
component = name,
metal = m,
mod_name = mod,
description = data.description:format(s.name),
image = tinkering.color_filter(data.image, s.color)
})
-- Make all components meltable
metal_melter.register_melt(mod..":"..component, m, name)
end
end