summaryrefslogtreecommitdiff
path: root/mesecons_whiskers75/init.lua
blob: 15e4785587a18aa19db2cc4d3f4f414a8bb7a343 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
--Whiskers75's code
--AND block

-- Make the block:

minetest.register_node("mesecons_whiskers75:andblock", {
	description = "AND block",
	drawtype = "raillike",
	tile_images = {"whiskers75andblock.png"},
	inventory_image = {"whiskers75andblock.png"},
	sunlight_propagates = true,
	paramtype = 'light',
	walkable = true,
	groups = {dig_immediate=2},
	material = minetest.digprop_constanttime(1.0),
})

minetest.register_on_punchnode(function(pos, node, puncher)
	if node.name=="mesecons_whiskers75:andblock" then
		anode = minetest.env:get_node({x=pos.x-1, y=pos.y, z=pos.z})
		bnode = minetest.env:get_node({x=pos.x+1, y=pos.y, z=pos.z}) 
		if anode.name=="mesecons:mesecon_on" and bnode.name=="mesecons:mesecon_on" then mesecon:receptor_on({x=pos.x, y=pos.y+1, z=pos.z}) end
	end
end)

minetest.register_on_punchnode(function(pos, node, puncher)
	if node.name=="mesecons_whiskers75:andblock" then
		anode = minetest.env:get_node({x=pos.x-1, y=pos.y, z=pos.z})
		bnode = minetest.env:get_node({x=pos.x+1, y=pos.y, z=pos.z}) 
		if anode.name=="mesecons:mesecon_off" then mesecon:receptor_off({x=pos.x, y=pos.y+1, z=pos.z}) end
		if bnode.name=="mesecons:mesecon_off" then mesecon:receptor_off({x=pos.x, y=pos.y+1, z=pos.z}) end
	end
end)

function update(pos, node)
	if node.name=="mesecons_whiskers75:andblock" then
		anode = minetest.env:get_node({x=pos.x-1, y=pos.y, z=pos.z})
		bnode = minetest.env:get_node({x=pos.x+1, y=pos.y, z=pos.z}) 
		if anode.name=="mesecons:mesecon_off" then mesecon:receptor_off({x=pos.x, y=pos.y+1, z=pos.z}) end
		if bnode.name=="mesecons:mesecon_off" then mesecon:receptor_off({x=pos.x, y=pos.y+1, z=pos.z}) end
	end

	if node.name=="mesecons_whiskers75:andblock" then
		anode = minetest.env:get_node({x=pos.x-1, y=pos.y, z=pos.z})
		bnode = minetest.env:get_node({x=pos.x+1, y=pos.y, z=pos.z}) 
		if anode.name=="mesecons:mesecon_on" and bnode.name=="mesecons:mesecon_on" then mesecon:receptor_on({x=pos.x, y=pos.y+1, z=pos.z}) end
	end
end


minetest.register_craft({
	output = '"mesecons_whiskers75:andblock" 2',
	recipe = {
		{'"default:wood"', '', '"default:dirt"'},
	}
})

mesecon:register_on_signal_on(update)
mesecon:register_on_signal_off(update)