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