sorcery  Check-in [641c891754]

Overview
Comment:moretrees compat
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 641c89175442c76615dbb1c6d285837380654dc13716f962deb1615baf12deea
User & Date: lexi on 2021-07-07 12:57:28
Other Links: manifest | tags
Context
2021-07-07
13:08
fug bixes check-in: b9235d8bfa user: lexi tags: trunk
12:57
moretrees compat check-in: 641c891754 user: lexi tags: trunk
12:05
update harvest god gifts check-in: 18f3f28aa2 user: lexi tags: trunk
Changes

Modified data/trees.lua from [4c4b931a13] to [33057bf9f3].

    37     37   		leaves = 'default:acacia_leaves';
    38     38   		sap = 'Acacia Sap';
    39     39   		color = {217, 51, 22};
    40     40   		sapglow = 7;
    41     41   	};
    42     42   	jungle = {
    43     43   		desc = 'Jungle';
    44         -		node = 'default:jungletree';
           44  +		node = {
           45  +			'default:jungletree';
           46  +			'moretrees:jungletree_trunk';
           47  +		};
    45     48   		sapling = 'default:junglesapling';
    46     49   		leaves = 'default:jungleleaves';
    47     50   		sap = 'Tropical Syrup';
    48     51   		color = {86, 39, 71};
    49     52   		imgvariant = 'dull';
    50     53   	};
    51     54   }

Modified lib/node.lua from [3d99ab5529] to [a6a32274e7].

   211    211   		--
   212    212   		--  UPDATE: in pratice this is way too expensive to be functional, and causes servers to hang. we're replacing it with a simpler version
   213    213   
   214    214   		local treetype = force(pos).name
   215    215   		if minetest.get_item_group(treetype, 'tree') == 0 then -- sir this is not a tree
   216    216   			return nil -- 無
   217    217   		end
   218         -		local treedef = sorcery.lib.tbl.select(sorcery.data.trees, 'node', treetype)
          218  +		local treedef = sorcery.lib.tbl.select(sorcery.data.trees, function(ent)
          219  +			return sorcery.lib.tbl.strmatch(ent.node, treetype)
          220  +		end)
   219    221   		local leaftype = treedef and treedef.leaves or nil
   220    222   		if not leaftype then return false end
   221    223   
   222    224   		local uppermost, lowermost
   223    225   		local found_leaves = false
   224    226   
   225    227   		local treemap, treenodes = amass(pos,function(node, where)

Modified lib/tbl.lua from [0fb14e1ea3] to [c7882ede1c].

   200    200   end
   201    201   
   202    202   fn.cond = function(exp, c)
   203    203   	for i, v in ipairs(c) do
   204    204   		if c[1](exp) then return c[2](exp) end
   205    205   	end
   206    206   end
          207  +
          208  +fn.strmatch = function(tbl, str)
          209  +	if tbl == str then return true end
          210  +	if type(tbl) == 'string' then return false end
          211  +	return fn.has(tbl, str)
          212  +end
   207    213   
   208    214   fn.select = function(tbl, prop, ...)
   209    215   	local keycache
   210    216   	local check if type(prop) == 'function' then
   211    217   		check = prop
   212    218   		keycache = ...
   213    219   	else

Modified tap.lua from [eb69eaaf9d] to [451ab2dcbd].

     1      1   local log = sorcery.logger('tap')
     2      2   local sap_interval = 60;
            3  +local L=sorcery.lib
     3      4   
     4      5   local function tapdrip(liq, pos)
     5      6   	return sorcery.vfx.drip(liq, vector.offset(pos, 0, -0.3, 0), math.random(5,12), sap_interval, 2)
     6      7   end
     7      8   
     8      9   minetest.register_node('sorcery:tap',{
     9     10   	description = 'Tap';
................................................................................
    35     36   		if vector.subtract(where.under,where.above).y ~= 0 then return end
    36     37   
    37     38   		minetest.set_node(where.above, {
    38     39   			name = 'sorcery:tap';
    39     40   			param2 = minetest.dir_to_wallmounted(vector.subtract(where.under,where.above))
    40     41   		})
    41     42   		
    42         -		if sorcery.lib.node.tree_is_live(where.under) then
           43  +		if L.node.tree_is_live(where.under) then
    43     44   			-- start dripping immediately to indicate the tree is alive
    44     45   			tapdrip(tree.def.sapliq, where.above)
    45     46   		end
    46     47   
    47     48   		stack:take_item(1)
    48     49   		return stack
    49     50   	end;
................................................................................
    86     87   			abm_cache_time = now
    87     88   		end
    88     89   		local tpos = vector.add(pos,minetest.wallmounted_to_dir(node.param2))
    89     90   		local tnode = minetest.get_node(tpos)
    90     91   		if tnode.name == 'air' then return end --pathological case
    91     92   		local tree
    92     93   		for id,t in pairs(sorcery.data.trees) do
    93         -			if t.node == tnode.name then
           94  +			if L.tbl.strmatch(t.node, tnode.name) then
    94     95   				tree = t
    95     96   				goto found
    96     97   			end
    97     98   		end do
    98     99   			return
    99    100   		end ::found::
   100    101   
................................................................................
   105    106   			live = true
   106    107   			local c = abm_cache.treehash[tposhash]
   107    108   			-- mass_leaves = c.mass_leaves
   108    109   			mass_trunk = c.mass_trunk
   109    110   			prevalidate = true
   110    111   		else
   111    112   			local tbody
   112         -			live, tbody = sorcery.lib.node.tree_is_live(tpos)
          113  +			live, tbody = L.node.tree_is_live(tpos)
   113    114   			if live then
   114    115   				should_cache = tbody.nodes[tbody.trunk]
   115    116   				-- mass_leaves = #(tbody.nodes[tbody.leaves])
   116    117   				mass_trunk = #(tbody.nodes[tbody.trunk]) * 12
   117    118   				topnode = tbody.topnode
   118    119   			end
   119    120   		end
................................................................................
   140    141   		-- 	if minetest.get_natural_light(vector.offset(topnode,0,1,0), 0.5) < 13
   141    142   		-- 		then return false end
   142    143   		-- end
   143    144   		-- FIXME
   144    145   
   145    146   		for i=1,8 do
   146    147   			local at = vector.offset(pos, 0,-i,0)
   147         -			if sorcery.lib.node.is_air(at) then goto skip end
          148  +			if L.node.is_air(at) then goto skip end
   148    149   
   149    150   			local trough = minetest.get_node(at)
   150    151   			if minetest.get_item_group(trough.name, 'sorcery_trough') ~= 0 then
   151    152   				local n = minetest.registered_nodes[trough.name]
   152    153   				local l = sorcery.register.liquid.db[tree.sapliq]
   153    154   				local C = sorcery.liquid.constants
   154    155   				if n._sorcery and n._sorcery.container then

Modified tree.lua from [9824222a51] to [e98976a563].

     7      7   }
     8      8   local log = sorcery.logger('tree')
     9      9   local L = sorcery.lib
    10     10   
    11     11   sorcery.register.trees.foreach('sorcery:treesetup', {}, function(id, t)
    12     12   	-- generates sap and hooks handlers appropriately
    13     13   	if t.node then
    14         -		local def = minetest.registered_nodes[t.node]
    15         -		local nextfn = def.on_place
    16         -		minetest.override_item(t.node, { on_place = function(stack, who, pointed, ...)
    17         -			if nextfn then nextfn(stack, who, pointed, ...) end
    18         -			if who ~= nil and pointed.type == 'node' then
    19         -				-- local pos = pointed.above
    20         -				-- local _, counts = minetest.find_nodes_in_area(
    21         -				-- 	vector.offset(pos, -1,-1,-1),
    22         -				-- 	vector.offset(pos,  1, 1, 1),
    23         -				-- 	t.leaves or 'group:leaves', false)
    24         -				-- if counts[next(counts)] > 0 then
    25         -				local n = minetest.get_node(pointed.above)
    26         -				n.param1 = 1
    27         -				minetest.swap_node(pointed.above, n)
    28         -				-- end
           14  +		local nodes = t.node
           15  +		if type(nodes) == 'string' then nodes = {nodes} end
           16  +		for _, node in pairs(nodes) do
           17  +			local def = minetest.registered_nodes[node]
           18  +			if def then
           19  +				local nextfn = def.on_place
           20  +				minetest.override_item(node, { on_place = function(stack, who, pointed, ...)
           21  +					if nextfn then nextfn(stack, who, pointed, ...) end
           22  +					if who ~= nil and pointed.type == 'node' then
           23  +						-- local pos = pointed.above
           24  +						-- local _, counts = minetest.find_nodes_in_area(
           25  +						-- 	vector.offset(pos, -1,-1,-1),
           26  +						-- 	vector.offset(pos,  1, 1, 1),
           27  +						-- 	t.leaves or 'group:leaves', false)
           28  +						-- if counts[next(counts)] > 0 then
           29  +						local n = minetest.get_node(pointed.above)
           30  +						n.param1 = 1
           31  +						minetest.swap_node(pointed.above, n)
           32  +						-- end
           33  +					end
           34  +				end })
    29     35   			end
    30         -		end })
           36  +		end
    31     37   	end
    32     38   
    33     39   	if t.sap == false then return end
    34     40   	if not t.sapliq then
    35     41   		t.sapliq = string.format('sorcery:sap_%s', id)
    36     42   		local sapdesc = t.sap or (t.desc .. ' Tree Sap')
    37     43   		sorcery.liquid.register {
................................................................................
    56     62   		name = what
    57     63   	else
    58     64   		pos = what
    59     65   		name = sorcery.lib.node.force(what).name
    60     66   	end
    61     67   	
    62     68   	for tn, def in pairs(sorcery.data.trees) do
    63         -		if def.node == name then
           69  +		if L.tbl.strmatch(def.node, name) then
    64     70   			return {
    65     71   				tree = tn;
    66     72   				def = def;
    67     73   				pos = pos;
    68     74   				node = name;
    69     75   			}
    70     76   		end