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