]> git.lizzy.rs Git - Crafter.git/blob - mods/redstone/torch.lua
Stage 2 of redstone virtualization
[Crafter.git] / mods / redstone / torch.lua
1 local minetest,vector = minetest,vector
2
3
4 --add in smoke and fire
5 local function create_ps(pos)
6         local dir = get_offset(minetest.get_node(pos).param2)
7         local ppos = vector.add(dir,pos)
8         local meta = minetest.get_meta(pos)
9         local psf = minetest.add_particlespawner({
10                 amount = 2,
11                 time = 0,
12                 minpos = ppos,
13                 maxpos = ppos,
14                 minvel = vector.new(0,0,0),
15                 maxvel = vector.new(0,0,0),
16                 minacc = {x=0, y=0, z=0},
17                 maxacc = {x=0, y=0, z=0},
18                 minexptime = 1,
19                 maxexptime = 1,
20                 minsize = 3,
21                 maxsize = 3,
22                 collisiondetection = false,
23                 vertical = true,
24                 texture = "redstone_torch_animated.png",
25                 animation = {type = "vertical_frames",
26
27                         aspect_w = 16,
28                         -- Width of a frame in pixels
29
30                         aspect_h = 16,
31                         -- Height of a frame in pixels
32
33                         length =  0.2,
34                         -- Full loop length
35                 },
36         })
37         local pss = minetest.add_particlespawner({
38                 amount = 2,
39                 time = 0,
40                 minpos = ppos,
41                 maxpos = ppos,
42                 minvel = vector.new(-0.1,0.1,-0.1),
43                 maxvel = vector.new(0.1,0.3,0.1),
44                 minacc = vector.new(0,0,0),
45                 maxacc = vector.new(0,0,0),
46                 minexptime = 1,
47                 maxexptime = 2,
48                 minsize = 1,
49                 maxsize = 2,
50                 collisiondetection = false,
51                 vertical = false,
52                 texture = "smoke.png",
53         })
54         meta:set_int("psf", psf)
55         meta:set_int("pss", pss)
56 end
57
58 -- Item definitions
59 minetest.register_craftitem("redstone:torch", {
60         description = "Redstone Torch",
61         inventory_image = "redstone_torch.png",
62         wield_image = "redstone_torch.png",
63         wield_scale = {x = 1, y = 1, z = 1 + 1/16},
64         liquids_pointable = false,
65         power = 9,
66         on_place = function(itemstack, placer, pointed_thing)
67                 if pointed_thing.type ~= "node" then
68                         return itemstack
69                 end
70
71                 local wdir = minetest.dir_to_wallmounted(vector.subtract(pointed_thing.under,pointed_thing.above))
72
73                 local fakestack = itemstack
74                 local retval = false
75                 if wdir < 1 then
76                         return itemstack
77                 elseif wdir == 1 then
78                         retval = fakestack:set_name("redstone:torch_floor")
79                 else
80                         retval = fakestack:set_name("redstone:torch_wall")
81                 end
82                 if not retval then
83                         return itemstack
84                 end
85                 itemstack, retval = minetest.item_place(fakestack, placer, pointed_thing, wdir)
86                 itemstack:set_name("redstone:torch")
87
88                 if retval then
89                         minetest.sound_play("wood", {pos=pointed_thing.above, gain = 1.0})
90                 end
91
92                 return itemstack
93         end
94 })
95
96 minetest.register_node("redstone:torch_floor", {
97         inventory_image = "redstone_torch.png",
98         wield_image = "redstone_torch.png",
99         wield_scale = {x = 1, y = 1, z = 1 + 2/16},
100         drawtype = "mesh",
101         mesh = "torch_floor.obj",
102         tiles = {"redstone_torch.png"},
103         paramtype = "light",
104         paramtype2 = "none",
105         power = 9,
106         sunlight_propagates = true,
107         drop = "redstone:torch",
108         walkable = false,
109         light_source = 13,
110         groups = {choppy=2, dig_immediate=3, not_in_creative_inventory=1, attached_node=1, torch=1,redstone=1,redstone_torch=1,redstone_power=9},
111         legacy_wallmounted = true,
112         selection_box = {
113                 type = "fixed",
114                 fixed = {-1/16, -0.5, -1/16, 1/16, 2/16, 1/16},
115         },
116         
117         on_construct = function(pos)
118                 redstone.inject(pos,{torch=9})
119                 redstone.update(pos)
120         end,
121         after_destruct = function(pos, oldnode)
122                 redstone.inject(pos,nil)
123                 redstone.update(pos)
124         end,
125         sounds = main.woodSound(),
126 })
127
128 minetest.register_node("redstone:torch_wall", {
129         inventory_image = "redstone_torch.png",
130         wield_image = "redstone_torch.png",
131         wield_scale = {x = 1, y = 1, z = 1 + 1/16},
132         drawtype = "mesh",
133         mesh = "torch_wall.obj",
134         tiles = {"redstone_torch.png"},
135         paramtype = "light",
136         paramtype2 = "wallmounted",
137         sunlight_propagates = true,
138         walkable = false,
139         light_source = 13,
140         power = 9,
141         groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1, torch=1,redstone=1,redstone_torch=1,redstone_power=9},
142         drop = "redstone:torch",
143         selection_box = {
144                 type = "wallmounted",
145                 wall_top = {-0.1, -0.1, -0.1, 0.1, 0.5, 0.1},
146                 wall_bottom = {-0.1, -0.5, -0.1, 0.1, 0.1, 0.1},
147                 wall_side = {-0.5, -0.3, -0.1, -0.2, 0.3, 0.1},
148         },
149         on_construct = function(pos)
150                 redstone.inject(pos,{torch=9})
151                 redstone.update(pos)
152         end,
153         after_destruct = function(pos, oldnode)
154                 redstone.inject(pos,nil)
155                 redstone.update(pos)
156         end,
157         sounds = main.woodSound(),
158 })
159