]> git.lizzy.rs Git - Crafter.git/blob - mods/torch/init.lua
add in right clicking places torch with tool in hand
[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 wdir = minetest.dir_to_wallmounted(vector.subtract(pointed_thing.under,pointed_thing.above))
102
103                 local fakestack = itemstack
104                 local retval = false
105                 if wdir < 1 then
106                         return itemstack
107                 elseif wdir == 1 then
108                         retval = fakestack:set_name("torch:floor")
109                 else
110                         retval = fakestack:set_name("torch:wall")
111                 end
112                 if not retval then
113                         return itemstack
114                 end
115                 itemstack, retval = minetest.item_place(fakestack, placer, pointed_thing, wdir)
116                 itemstack:set_name("torch:torch")
117
118                 if retval then
119                         minetest.sound_play("wood", {pos=pointed_thing.above, gain = 1.0})
120                 end
121
122                 return itemstack
123         end
124 })
125
126 minetest.register_node("torch:floor", {
127         inventory_image = "default_torch.png",
128         wield_image = "torches_torch.png",
129         wield_scale = {x = 1, y = 1, z = 1 + 2/16},
130         drawtype = "mesh",
131         mesh = "torch_floor.obj",
132         tiles = {"torches_torch.png"},
133         paramtype = "light",
134         paramtype2 = "none",
135         sunlight_propagates = true,
136         drop = "torch:torch",
137         walkable = false,
138         light_source = 13,
139         groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1, torch=1},
140         legacy_wallmounted = true,
141         selection_box = {
142                 type = "fixed",
143                 fixed = {-1/16, -0.5, -1/16, 1/16, 2/16, 1/16},
144         },
145         sounds = main.woodSound(),
146 })
147
148 minetest.register_node("torch:wall", {
149         inventory_image = "default_torch.png",
150         wield_image = "torches_torch.png",
151         wield_scale = {x = 1, y = 1, z = 1 + 1/16},
152         drawtype = "mesh",
153         mesh = "torch_wall.obj",
154         tiles = {"torches_torch.png"},
155         paramtype = "light",
156         paramtype2 = "wallmounted",
157         sunlight_propagates = true,
158         walkable = false,
159         light_source = 13,
160         groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1, torch=1},
161         drop = "torch:torch",
162         selection_box = {
163                 type = "wallmounted",
164                 wall_top = {-0.1, -0.1, -0.1, 0.1, 0.5, 0.1},
165                 wall_bottom = {-0.1, -0.5, -0.1, 0.1, 0.1, 0.1},
166                 wall_side = {-0.5, -0.3, -0.1, -0.2, 0.3, 0.1},
167         },
168         sounds = main.woodSound(),
169 })
170
171 minetest.register_craft({
172         output = "torch:torch 4",
173         recipe = {
174                 {"main:coal"},
175                 {"main:stick"}
176         }
177 })
178 minetest.register_craft({
179         output = "torch:torch 4",
180         recipe = {
181                 {"main:charcoal"},
182                 {"main:stick"}
183         }
184 })