sorcery  Diff

Differences From Artifact [17fb78473a]:

To Artifact [9cfe073fce]:


1






2
3
4
5
6
7
8
..
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34





35
36
37
38

39
40
41
42
43
44
45
..
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
...
101
102
103
104
105
106
107


108
109
110
111
112
113
114
local log = sorcery.logger('tap')






minetest.register_node('sorcery:tap',{
	description = 'Tree Tap';
	drawtype = 'mesh';
	mesh = 'sorcery-tap.obj';
	inventory_image = 'sorcery_tap_inv.png';
	tiles = {
		'default_copper_block.png';
................................................................................
	paramtype = 'light', paramtype2 = 'wallmounted';
	selection_box = { type='fixed', fixed = {-0.2,-0.5,-0.35; 0.3,0.1,0.4} };
	collision_box = { type='fixed', fixed = {-0.2,-0.5,-0.35; 0.3,0.1,0.4} };
	node_placement_prediction = '';
	on_place = function(stack,who,where)
		if where.type ~= 'node' then return end
		local bl = minetest.get_node(where.under)
		-- FIXME prevent tapping 'dead' non-tree wood blocks

		local tree = sorcery.tree.get(where.under)
		if not tree or tree.sap == false then return end;

		-- disallow vertical attachment
		if vector.subtract(where.under,where.above).y ~= 0 then return end

		minetest.set_node(where.above, {
			name = 'sorcery:tap';
			param2 = minetest.dir_to_wallmounted(vector.subtract(where.under,where.above))
		})






		stack:take_item(1)
		return stack
	end;

	_sorcery = {
		recipe = {
			note = 'Extract syrups and oils from trees';
		};
	};
})

................................................................................
	recipe = {
		{'','sorcery:screw_steel','basic_materials:steel_bar'};
		{'sorcery:pipe','sorcery:valve','sorcery:screw_steel'};
		{'','sorcery:pipe',''};
	};
}

local sap_interval = 60;
local abm_cache
local abm_cache_time
minetest.register_abm {
	label = 'Sap drip';
	nodenames = {'sorcery:tap'};
	neighbors = {'group:tree'};
	interval = sap_interval;
	chance = 7;
	catch_up = true;
	action = function(pos, node)
		local now = os.time()
		if abm_cache_time == nil or now > abm_cache_time + (sap_interval-1) then
			abm_cache = { treehash = {} }
			abm_cache_time = now
		end
................................................................................
			end
		end

		if (not live)
			or tree.sap == false
			or not tree.sapliq then return end
		if mass_trunk < 12*3 then return end -- too small



		local mass = mass_leaves + mass_trunk
		local max_mass = 400
		local ltratio = mass_leaves / mass_trunk
		local mratio = mass / max_mass
		local outof = 15 / mratio
		local chance = math.max(1, math.floor(outof - (25 * ltratio))) / 3

>
>
>
>
>
>







 







<


|

|






>
>
>
>
>




>







 







<







|







 







>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
..
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
..
59
60
61
62
63
64
65

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
...
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
local log = sorcery.logger('tap')
local sap_interval = 20;

local function tapdrip(liq, pos)
	return sorcery.vfx.drip(liq, vector.offset(pos, 0, -0.3, 0), math.random(5,12), sap_interval, 2)
end

minetest.register_node('sorcery:tap',{
	description = 'Tree Tap';
	drawtype = 'mesh';
	mesh = 'sorcery-tap.obj';
	inventory_image = 'sorcery_tap_inv.png';
	tiles = {
		'default_copper_block.png';
................................................................................
	paramtype = 'light', paramtype2 = 'wallmounted';
	selection_box = { type='fixed', fixed = {-0.2,-0.5,-0.35; 0.3,0.1,0.4} };
	collision_box = { type='fixed', fixed = {-0.2,-0.5,-0.35; 0.3,0.1,0.4} };
	node_placement_prediction = '';
	on_place = function(stack,who,where)
		if where.type ~= 'node' then return end
		local bl = minetest.get_node(where.under)


		local tree = sorcery.tree.get(where.under)
		if not tree or tree.def.sap == false then return end;

		-- disallow vertical attachment, bc that makes no sense
		if vector.subtract(where.under,where.above).y ~= 0 then return end

		minetest.set_node(where.above, {
			name = 'sorcery:tap';
			param2 = minetest.dir_to_wallmounted(vector.subtract(where.under,where.above))
		})
		
		if sorcery.lib.node.tree_is_live(where.under) then
			-- start dripping immediately to indicate the tree is alive
			tapdrip(tree.def.sapliq, where.above)
		end

		stack:take_item(1)
		return stack
	end;
	on_screwdriver = function() return false end;
	_sorcery = {
		recipe = {
			note = 'Extract syrups and oils from trees';
		};
	};
})

................................................................................
	recipe = {
		{'','sorcery:screw_steel','basic_materials:steel_bar'};
		{'sorcery:pipe','sorcery:valve','sorcery:screw_steel'};
		{'','sorcery:pipe',''};
	};
}


local abm_cache
local abm_cache_time
minetest.register_abm {
	label = 'Sap drip';
	nodenames = {'sorcery:tap'};
	neighbors = {'group:tree'};
	interval = sap_interval;
	chance = 4;
	catch_up = true;
	action = function(pos, node)
		local now = os.time()
		if abm_cache_time == nil or now > abm_cache_time + (sap_interval-1) then
			abm_cache = { treehash = {} }
			abm_cache_time = now
		end
................................................................................
			end
		end

		if (not live)
			or tree.sap == false
			or not tree.sapliq then return end
		if mass_trunk < 12*3 then return end -- too small

		tapdrip(tree.sapliq,pos)

		local mass = mass_leaves + mass_trunk
		local max_mass = 400
		local ltratio = mass_leaves / mass_trunk
		local mratio = mass / max_mass
		local outof = 15 / mratio
		local chance = math.max(1, math.floor(outof - (25 * ltratio))) / 3