sorcery  Diff

Differences From Artifact [17fb78473a]:

To Artifact [9cfe073fce]:


     1      1   local log = sorcery.logger('tap')
            2  +local sap_interval = 20;
            3  +
            4  +local function tapdrip(liq, pos)
            5  +	return sorcery.vfx.drip(liq, vector.offset(pos, 0, -0.3, 0), math.random(5,12), sap_interval, 2)
            6  +end
            7  +
     2      8   minetest.register_node('sorcery:tap',{
     3      9   	description = 'Tree Tap';
     4     10   	drawtype = 'mesh';
     5     11   	mesh = 'sorcery-tap.obj';
     6     12   	inventory_image = 'sorcery_tap_inv.png';
     7     13   	tiles = {
     8     14   		'default_copper_block.png';
................................................................................
    16     22   	paramtype = 'light', paramtype2 = 'wallmounted';
    17     23   	selection_box = { type='fixed', fixed = {-0.2,-0.5,-0.35; 0.3,0.1,0.4} };
    18     24   	collision_box = { type='fixed', fixed = {-0.2,-0.5,-0.35; 0.3,0.1,0.4} };
    19     25   	node_placement_prediction = '';
    20     26   	on_place = function(stack,who,where)
    21     27   		if where.type ~= 'node' then return end
    22     28   		local bl = minetest.get_node(where.under)
    23         -		-- FIXME prevent tapping 'dead' non-tree wood blocks
    24     29   
    25     30   		local tree = sorcery.tree.get(where.under)
    26         -		if not tree or tree.sap == false then return end;
           31  +		if not tree or tree.def.sap == false then return end;
    27     32   
    28         -		-- disallow vertical attachment
           33  +		-- disallow vertical attachment, bc that makes no sense
    29     34   		if vector.subtract(where.under,where.above).y ~= 0 then return end
    30     35   
    31     36   		minetest.set_node(where.above, {
    32     37   			name = 'sorcery:tap';
    33     38   			param2 = minetest.dir_to_wallmounted(vector.subtract(where.under,where.above))
    34     39   		})
           40  +		
           41  +		if sorcery.lib.node.tree_is_live(where.under) then
           42  +			-- start dripping immediately to indicate the tree is alive
           43  +			tapdrip(tree.def.sapliq, where.above)
           44  +		end
    35     45   
    36     46   		stack:take_item(1)
    37     47   		return stack
    38     48   	end;
           49  +	on_screwdriver = function() return false end;
    39     50   	_sorcery = {
    40     51   		recipe = {
    41     52   			note = 'Extract syrups and oils from trees';
    42     53   		};
    43     54   	};
    44     55   })
    45     56   
................................................................................
    48     59   	recipe = {
    49     60   		{'','sorcery:screw_steel','basic_materials:steel_bar'};
    50     61   		{'sorcery:pipe','sorcery:valve','sorcery:screw_steel'};
    51     62   		{'','sorcery:pipe',''};
    52     63   	};
    53     64   }
    54     65   
    55         -local sap_interval = 60;
    56     66   local abm_cache
    57     67   local abm_cache_time
    58     68   minetest.register_abm {
    59     69   	label = 'Sap drip';
    60     70   	nodenames = {'sorcery:tap'};
    61     71   	neighbors = {'group:tree'};
    62     72   	interval = sap_interval;
    63         -	chance = 7;
           73  +	chance = 4;
    64     74   	catch_up = true;
    65     75   	action = function(pos, node)
    66     76   		local now = os.time()
    67     77   		if abm_cache_time == nil or now > abm_cache_time + (sap_interval-1) then
    68     78   			abm_cache = { treehash = {} }
    69     79   			abm_cache_time = now
    70     80   		end
................................................................................
   101    111   			end
   102    112   		end
   103    113   
   104    114   		if (not live)
   105    115   			or tree.sap == false
   106    116   			or not tree.sapliq then return end
   107    117   		if mass_trunk < 12*3 then return end -- too small
          118  +
          119  +		tapdrip(tree.sapliq,pos)
   108    120   
   109    121   		local mass = mass_leaves + mass_trunk
   110    122   		local max_mass = 400
   111    123   		local ltratio = mass_leaves / mass_trunk
   112    124   		local mratio = mass / max_mass
   113    125   		local outof = 15 / mratio
   114    126   		local chance = math.max(1, math.floor(outof - (25 * ltratio))) / 3