]> git.lizzy.rs Git - Crafter.git/blob - mods/torch/init.lua
remove server debug
[Crafter.git] / mods / torch / init.lua
1 local particle_time = 5 -- how many seconds torches will wait to check if player is near
2 local check_radius = 10
3
4 --get point where particle spawner is added
5 local function get_offset(wdir)
6         local z = 0
7         local x = 0
8         if wdir == 4 then
9                 z = 0.25
10         elseif wdir == 2 then
11                 x = 0.25
12         elseif wdir == 5 then
13                 z = -0.25
14         elseif wdir == 3 then
15                 x = -0.25
16         end
17         return {x = x, y = 0.27, z = z} 
18 end
19 --add in smoke and fire
20 local function create_ps(pos)
21         local dir = get_offset(minetest.get_node(pos).param2)
22         local ppos = vector.add(dir,pos)
23         minetest.add_particle({
24                 pos = ppos,
25                 velocity = vector.new(0,0,0),
26                 acceleration = vector.new(0,0,0),
27                 expirationtime = particle_time*3,
28                 size = 3,
29                 collisiondetection = false,
30                 vertical = true,
31                 texture = "torch_animated.png",
32                 animation = {type = "vertical_frames",
33
34                         aspect_w = 16,
35                         -- Width of a frame in pixels
36
37                         aspect_h = 16,
38                         -- Height of a frame in pixels
39
40                         length =  0.2,
41                         -- Full loop length
42                 },
43         })
44         --[[
45         minetest.add_particlespawner({
46                 amount = particle_time*6,
47                 time = particle_time*2,
48                 minpos = ppos,
49                 maxpos = ppos,
50                 minvel = vector.new(-0.1,0.1,-0.1),
51                 maxvel = vector.new(0.1,0.3,0.1),
52                 minacc = vector.new(0,0,0),
53                 maxacc = vector.new(0,0,0),
54                 minexptime = 1,
55                 maxexptime = 2,
56                 minsize = 1,
57                 maxsize = 2,
58                 collisiondetection = false,
59                 vertical = false,
60                 texture = "smoke.png",
61         })
62         ]]--
63 end
64
65
66 --reload smoke and flame on load
67 --[[
68 minetest.register_abm({
69         label = "Torch Particle",
70         nodenames = {"group:torch"},
71         neighbors = {"air"},
72         interval = particle_time,
73         chance = 1,
74         action = function(pos, node, active_object_count, active_object_count_wider)
75                 local found_player = false
76                 for _,object in ipairs(minetest.get_objects_inside_radius(pos, check_radius)) do
77                         local pos2 = object:getpos()
78                         if object:is_player() then
79                                 found_player = true
80                         end
81                 end
82                 if found_player == true then
83                         create_ps(pos)
84                 end
85         end,
86 })
87 ]]--
88
89 -- Item definitions
90 minetest.register_craftitem("torch:torch", {
91         description = "Torch",
92         inventory_image = "torches_torch.png",
93         wield_image = "torches_torch.png",
94         wield_scale = {x = 1, y = 1, z = 1 + 1/16},
95         liquids_pointable = false,
96         on_place = function(itemstack, placer, pointed_thing)
97                 if pointed_thing.type ~= "node" then
98                         return itemstack
99                 end
100
101                 local buildable = minetest.get_nodedef(minetest.get_node(pointed_thing.under).name, "buildable_to")
102
103                 local wdir
104
105                 if buildable then
106                         wdir = minetest.dir_to_wallmounted(vector.subtract(pointed_thing.under,pointed_thing.under))
107                 else
108                         wdir = minetest.dir_to_wallmounted(vector.subtract(pointed_thing.under,pointed_thing.above))
109                 end
110
111                 local fakestack = itemstack
112                 local retval = false
113                 
114                 if buildable and wdir == 4 then
115                         retval = fakestack:set_name("torch:floor")
116                 elseif wdir < 1 then
117                         return itemstack
118                 elseif wdir == 1 then
119                         retval = fakestack:set_name("torch:floor")
120                 else
121                         retval = fakestack:set_name("torch:wall")
122                 end
123
124                 if not retval then
125                         return itemstack
126                 end
127                 itemstack, retval = minetest.item_place(fakestack, placer, pointed_thing, wdir)
128                 itemstack:set_name("torch:torch")
129
130                 if retval then
131                         minetest.sound_play("wood", {pos=pointed_thing.above, gain = 1.0})
132                 end
133
134                 return itemstack
135         end
136 })
137
138 minetest.register_node("torch:floor", {
139         inventory_image = "torches_torch.png",
140         wield_image = "torches_torch.png",
141         wield_scale = {x = 1, y = 1, z = 1 + 2/16},
142         drawtype = "mesh",
143         mesh = "torch_floor.obj",
144         tiles = {"torches_torch.png"},
145         paramtype = "light",
146         paramtype2 = "none",
147         sunlight_propagates = true,
148         drop = "torch:torch",
149         walkable = false,
150         floodable = true,
151         on_flood = function(pos, oldnode, newnode)
152                 minetest.throw_item(pos, "torch:torch")
153         end,
154         light_source = 13,
155         groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1, torch=1},
156         legacy_wallmounted = true,
157         selection_box = {
158                 type = "fixed",
159                 fixed = {-1/16, -0.5, -1/16, 1/16, 2/16, 1/16},
160         },
161         sounds = main.woodSound(),
162 })
163
164 minetest.register_node("torch:wall", {
165         inventory_image = "torches_torch.png",
166         wield_image = "torches_torch.png",
167         wield_scale = {x = 1, y = 1, z = 1 + 1/16},
168         drawtype = "mesh",
169         mesh = "torch_wall.obj",
170         tiles = {"torches_torch.png"},
171         paramtype = "light",
172         paramtype2 = "wallmounted",
173         floodable = true,
174         on_flood = function(pos, oldnode, newnode)
175                 minetest.throw_item(pos, "torch:torch")
176         end,
177         sunlight_propagates = true,
178         walkable = false,
179         light_source = 13,
180         groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1, torch=1},
181         drop = "torch:torch",
182         selection_box = {
183                 type = "wallmounted",
184                 wall_top = {-0.1, -0.1, -0.1, 0.1, 0.5, 0.1},
185                 wall_bottom = {-0.1, -0.5, -0.1, 0.1, 0.1, 0.1},
186                 wall_side = {-0.5, -0.3, -0.1, -0.2, 0.3, 0.1},
187         },
188         sounds = main.woodSound(),
189 })
190
191 minetest.register_craft({
192         output = "torch:torch 4",
193         recipe = {
194                 {"group:coal"},
195                 {"group:stick"}
196         }
197 })