sorcery  Diff

Differences From Artifact [43b3147bb9]:

To Artifact [87f184e80e]:


    89     89   			end
    90     90   		end do
    91     91   			return
    92     92   		end ::found::
    93     93   
    94     94   		local tposhash = minetest.hash_node_position(tpos)
    95     95   		local live, should_cache
    96         -		local mass_leaves, mass_trunk, topnode, prevalidate
           96  +		local mass_trunk, topnode, prevalidate
    97     97   		if abm_cache.treehash[tposhash] then
    98     98   			live = true
    99     99   			local c = abm_cache.treehash[tposhash]
   100         -			mass_leaves = c.mass_leaves
          100  +			-- mass_leaves = c.mass_leaves
   101    101   			mass_trunk = c.mass_trunk
   102    102   			prevalidate = true
   103    103   		else
   104    104   			local tbody
   105    105   			live, tbody = sorcery.lib.node.tree_is_live(tpos)
   106    106   			if live then
   107    107   				should_cache = tbody.nodes[tbody.trunk]
   108         -				mass_leaves = #(tbody.nodes[tbody.leaves])
          108  +				-- mass_leaves = #(tbody.nodes[tbody.leaves])
   109    109   				mass_trunk = #(tbody.nodes[tbody.trunk]) * 12
   110    110   				topnode = tbody.topnode
   111    111   			end
   112    112   		end
   113    113   
   114    114   		if (not live)
   115    115   			or tree.sap == false
   116    116   			or not tree.sapliq then return end
   117    117   		if mass_trunk < 12*3 then return end -- too small
   118    118   
   119    119   		tapdrip(tree.sapliq,pos)
   120    120   
   121         -		local mass = mass_leaves + mass_trunk
   122         -		local max_mass = 400
   123         -		local ltratio = mass_leaves / mass_trunk
   124         -		local mratio = mass / max_mass
   125         -		local outof = 15 / mratio
   126         -		local chance = math.max(1, math.floor(outof - (25 * ltratio))) / 3
   127         -		local diceroll = math.random(1,chance)
          121  +		local mass = mass_trunk -- + mass_leaves
          122  +		local max_mass = 250 -- 400
          123  +		-- local ltratio = mass_leaves / mass_trunk
          124  +		-- local mratio = mass / max_mass
          125  +		-- local outof = 15 / mratio
          126  +		-- local chance = math.max(1, math.floor(outof - (25 * ltratio))) / 3
          127  +		local chance = mass / max_mass
          128  +		local diceroll = math.random(1,math.ceil(chance))
   128    129   		-- log.act('rolling dice: ', chance,diceroll, '(lt ratio =', ltratio, '; mass ratio = ', mratio, '; tree mass =', mass, '; outof =', outof)
   129    130   		if diceroll ~= 1 then return end -- failed roll
   130    131   
   131         -		if not prevalidate then
   132         -			if minetest.get_natural_light(vector.offset(topnode,0,1,0), 0.5) < 13
   133         -				then return false end
   134         -		end
          132  +		-- if not prevalidate then
          133  +		-- 	if minetest.get_natural_light(vector.offset(topnode,0,1,0), 0.5) < 13
          134  +		-- 		then return false end
          135  +		-- end
          136  +		-- FIXME
   135    137   
   136    138   		for i=1,8 do
   137    139   			local at = vector.offset(pos, 0,-i,0)
   138    140   			if sorcery.lib.node.is_air(at) then goto skip end
   139    141   
   140    142   			local trough = minetest.get_node(at)
   141    143   			if minetest.get_item_group(trough.name, 'sorcery_trough') ~= 0 then
................................................................................
   158    160   							else
   159    161   								node.name = nct.make((ctr.charge or 0) + nct.res,1):get_name()
   160    162   							end
   161    163   							minetest.swap_node(at, node)
   162    164   						end
   163    165   						if should_cache then
   164    166   							for _,v in pairs(should_cache) do
   165         -								abm_cache.treehash[v:to_string()] = {
   166         -									mass_leaves = mass_leaves;
          167  +								abm_cache.treehash[minetest.hash_node_position(v)] = {
          168  +									-- mass_leaves = mass_leaves;
   167    169   									mass_trunk = mass_trunk;
   168    170   								}
   169    171   							end
   170    172   						end
   171    173   					end
   172    174   				else
   173    175   					log.err('item',trough.name,'is marked as a trough but lacks a _sorcery.container property table')
   174    176   				end
   175    177   			end
   176    178   			do return end
   177    179   		::skip::end
   178    180   	end;
   179    181   }