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