Support for nodes customizing
Currently hard-coded only in mapping.lua. Some usefull mappings added, like usage of buckets instead of sources for liquids As usual some small off-topic fixes
This commit is contained in:
parent
3124c5ae8f
commit
75563343c1
@ -15,22 +15,25 @@ CHEST
|
|||||||
--the right value is depend on building size. If the building (or the not builded rest) can full imaginated (less blocks in building then c_npc_imagination) there is the full search potencial active
|
--the right value is depend on building size. If the building (or the not builded rest) can full imaginated (less blocks in building then c_npc_imagination) there is the full search potencial active
|
||||||
local c_npc_imagination = 500
|
local c_npc_imagination = 500
|
||||||
|
|
||||||
|
|
||||||
-- expose api
|
-- expose api
|
||||||
towntest_chest = {}
|
towntest_chest = {}
|
||||||
|
|
||||||
|
-- debug. Used for debug messages. In production the function should be empty
|
||||||
|
local dprint = function(...)
|
||||||
|
-- debug print. Comment out the next line if you don't need debug out
|
||||||
|
-- print(unpack(arg))
|
||||||
|
end
|
||||||
|
towntest_chest.dprint = dprint
|
||||||
|
|
||||||
-- table of non playing characters
|
-- table of non playing characters
|
||||||
towntest_chest.npc = {}
|
towntest_chest.npc = {}
|
||||||
|
|
||||||
|
|
||||||
-- debug. Used for debug messages. In production the function should be empty
|
|
||||||
local function dprint(...)
|
|
||||||
-- debug print. Comment out the next line if you don't need debug out
|
|
||||||
-- print(unpack(arg))
|
|
||||||
end
|
|
||||||
|
|
||||||
local modpath = minetest.get_modpath(minetest.get_current_modname())
|
local modpath = minetest.get_modpath(minetest.get_current_modname())
|
||||||
|
|
||||||
|
-- nodes mapping functions
|
||||||
|
towntest_chest.mapping = {}
|
||||||
|
dofile(modpath.."/".."mapping.lua")
|
||||||
|
|
||||||
-- get worldedit parser load_schematic from worldedit mod
|
-- get worldedit parser load_schematic from worldedit mod
|
||||||
dofile(modpath.."/".."worldedit-serialization.lua")
|
dofile(modpath.."/".."worldedit-serialization.lua")
|
||||||
|
|
||||||
@ -78,28 +81,34 @@ towntest_chest.mapnodes = function(node)
|
|||||||
local node_chk = minetest.registered_items[node.name]
|
local node_chk = minetest.registered_items[node.name]
|
||||||
|
|
||||||
if not node_chk then
|
if not node_chk then
|
||||||
dprint("unknown node in building: "..node.name)
|
local fallbacknode = towntest_chest.mapping.unknown_nodes(node)
|
||||||
return nil
|
if fallbacknode then
|
||||||
else
|
return towntest_chest.mapnodes(fallbacknode)
|
||||||
-- known node. Check for price or if it is free
|
|
||||||
if (node_chk.groups.not_in_creative_inventory and not (node_chk.groups.not_in_creative_inventory == 0)) or
|
|
||||||
(not node_chk.description or node_chk.description == "") then
|
|
||||||
if node_chk.drop then
|
|
||||||
-- use possible drop as payment
|
|
||||||
if type(node_chk.drop) == "table" then -- drop table
|
|
||||||
node.matname = node_chk.drop[1] -- use the first one
|
|
||||||
else
|
|
||||||
node.matname = node_chk.drop
|
|
||||||
end
|
|
||||||
else --something not supported, but known
|
|
||||||
node.matname = "free" -- will be build for free. they are something like doors:hidden or second part of coffee lrfurn:coffeetable_back
|
|
||||||
end
|
|
||||||
else -- build for payment the 1:1
|
|
||||||
node.matname = node.name
|
|
||||||
end
|
end
|
||||||
end
|
else
|
||||||
|
-- known node Map them?
|
||||||
|
local customizednode = towntest_chest.mapping.customize(node)
|
||||||
|
if not customizednode.matname then --no matname override customizied.
|
||||||
|
|
||||||
return node
|
--Check for price or if it is free
|
||||||
|
if (node_chk.groups.not_in_creative_inventory and not (node_chk.groups.not_in_creative_inventory == 0)) or
|
||||||
|
(not node_chk.description or node_chk.description == "") then
|
||||||
|
if node_chk.drop then
|
||||||
|
-- use possible drop as payment
|
||||||
|
if type(node_chk.drop) == "table" then -- drop table
|
||||||
|
customizednode.matname = node_chk.drop[1] -- use the first one
|
||||||
|
else
|
||||||
|
customizednode.matname = node_chk.drop
|
||||||
|
end
|
||||||
|
else --something not supported, but known
|
||||||
|
customizednode.matname = "free" -- will be build for free. they are something like doors:hidden or second part of coffee lrfurn:coffeetable_back
|
||||||
|
end
|
||||||
|
else -- build for payment the 1:1
|
||||||
|
customizednode.matname = customizednode.name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return customizednode
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -454,7 +463,8 @@ towntest_chest.build = function(chestpos)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- create next chunk to be processed. only buildable items
|
-- create next chunk to be processed. only buildable items
|
||||||
if inv:contains_item("builder",v.matname.." 1") then
|
if inv:contains_item("builder",v.matname.." 1") or -- is in builder inventory
|
||||||
|
(v.matname == "free" and next_plan[1]) then -- or free, but builder inventory is not empty
|
||||||
table.insert(next_plan,v)
|
table.insert(next_plan,v)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
67
towntest_chest/mapping.lua
Normal file
67
towntest_chest/mapping.lua
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
local u = {}
|
||||||
|
-- Fallback nodes replacement of unknown nodes
|
||||||
|
-- Maybe it is beter to use aliases for unknown notes. But anyway
|
||||||
|
u["xpanes:pane_glass_10"] = { name = "xpanes:pane_10" }
|
||||||
|
u["xpanes:pane_glass_5"] = { name = "xpanes:pane_5" }
|
||||||
|
u["beds:bed_top_blue"] = { name = "beds:bed_top" }
|
||||||
|
u["beds:bed_bottom_blue"] = { name = "beds:bed_bottom" }
|
||||||
|
|
||||||
|
u["homedecor:table_lamp_max"] = { name = "homedecor:table_lamp_white_max" }
|
||||||
|
u["homedecor:refrigerator"] = { name = "homedecor:refrigerator_steel" }
|
||||||
|
|
||||||
|
towntest_chest.mapping.unknown_nodes_data = u
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local c = {}
|
||||||
|
--syntax sample. name and are matname optional.
|
||||||
|
-- if name is missed it will not be changed.
|
||||||
|
-- if matname is missed it will be determinated as usual (from changed name)
|
||||||
|
-- the sample is: instead of cobble place goldblock, use wood as payment
|
||||||
|
-- c["default:cobble"] = { name = "default:goldblock", matname = "default:wood" }
|
||||||
|
|
||||||
|
c["beds:bed_top"] = { matname = "free" } -- the bottom of the bed is payed
|
||||||
|
|
||||||
|
-- it is hard to get a source in survival, so we use buckets. Note, the bucket is lost after them
|
||||||
|
c["default:lava_source"] = { matname = "bucket:bucket_lava" }
|
||||||
|
c["default:river_water_source"] = { matname = "bucket:bucket_river_water" }
|
||||||
|
c["default:water_source"] = { matname = "bucket:bucket_water" }
|
||||||
|
|
||||||
|
towntest_chest.mapping.customize_data = c
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- Fallback nodes replacement of unknown nodes
|
||||||
|
-- Maybe it is beter to use aliases for unknown notes. But anyway
|
||||||
|
-- TODO: should be editable in game trough a nice gui, to customize the building before build
|
||||||
|
towntest_chest.mapping.unknown_nodes = function(node)
|
||||||
|
|
||||||
|
local map = towntest_chest.mapping.unknown_nodes_data[node.name]
|
||||||
|
if not map or map.name == node.name then -- no fallback mapping. don't use the node
|
||||||
|
towntest_chest.dprint("mapping failed:", node.name, dump(map))
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
towntest_chest.dprint("mapped", node.name, "to", map.name)
|
||||||
|
local mappednode = node
|
||||||
|
mappednode.name = map.name
|
||||||
|
return mappednode
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- Nodes replacement to customizie buildings
|
||||||
|
-- TODO: should be editable in game trough a nice gui, to customize the building before build
|
||||||
|
towntest_chest.mapping.customize = function(node)
|
||||||
|
local map = towntest_chest.mapping.customize_data[node.name]
|
||||||
|
if not map then -- no mapping. return unchanged
|
||||||
|
return node
|
||||||
|
end
|
||||||
|
towntest_chest.dprint("map", node.name, "to", map.name, map.matname)
|
||||||
|
local mappednode = node
|
||||||
|
if map.name then
|
||||||
|
mappednode.name = map.name
|
||||||
|
end
|
||||||
|
if map.matname then
|
||||||
|
mappednode.matname = map.matname
|
||||||
|
end
|
||||||
|
return mappednode
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user