]> git.lizzy.rs Git - Crafter.git/blob - mods/redstone/torch.lua
Make redstone have 16 states, overhaul performance
[Crafter.git] / mods / redstone / torch.lua
1 local minetest,vector = minetest,vector
2
3 -- Item definitions
4 minetest.register_craftitem("redstone:torch", {
5         description = "Redstone Torch",
6         inventory_image = "redstone_torch.png",
7         wield_image = "redstone_torch.png",
8         wield_scale = {x = 1, y = 1, z = 1 + 1/16},
9         liquids_pointable = false,
10         on_place = function(itemstack, placer, pointed_thing)
11                 if pointed_thing.type ~= "node" then
12                         return itemstack
13                 end
14
15                 local wdir = minetest.dir_to_wallmounted(vector.subtract(pointed_thing.under,pointed_thing.above))
16
17                 local fakestack = itemstack
18                 local retval = false
19                 if wdir < 1 then
20                         return itemstack
21                 elseif wdir == 1 then
22                         retval = fakestack:set_name("redstone:torch_floor")
23                 else
24                         retval = fakestack:set_name("redstone:torch_wall")
25                 end
26                 if not retval then
27                         return itemstack
28                 end
29                 itemstack, retval = minetest.item_place(fakestack, placer, pointed_thing, wdir)
30                 itemstack:set_name("redstone:torch")
31
32                 if retval then
33                         minetest.sound_play("wood", {pos=pointed_thing.above, gain = 1.0})
34                 end
35
36                 return itemstack
37         end
38 })
39
40 minetest.register_node("redstone:torch_floor", {
41         inventory_image = "redstone_torch.png",
42         wield_image = "redstone_torch.png",
43         wield_scale = {x = 1, y = 1, z = 1 + 2/16},
44         drawtype = "mesh",
45         mesh = "torch_floor.obj",
46         tiles = {"redstone_torch.png"},
47         paramtype = "light",
48         paramtype2 = "none",
49         sunlight_propagates = true,
50         drop = "redstone:torch",
51         walkable = false,
52         light_source = 13,
53         groups = {choppy=2, dig_immediate=3, not_in_creative_inventory=1, attached_node=1, torch=1,redstone=1,},
54         legacy_wallmounted = true,
55         selection_box = {
56                 type = "fixed",
57                 fixed = {-1/16, -0.5, -1/16, 1/16, 2/16, 1/16},
58         },
59         
60         on_construct = function(pos)
61                 redstone.inject(pos,{torch=16})
62                 redstone.update(pos)
63         end,
64         after_destruct = function(pos, oldnode)
65                 redstone.inject(pos,nil)
66                 redstone.update(pos)
67         end,
68         sounds = main.woodSound(),
69 })
70
71 minetest.register_node("redstone:torch_wall", {
72         inventory_image = "redstone_torch.png",
73         wield_image = "redstone_torch.png",
74         wield_scale = {x = 1, y = 1, z = 1 + 1/16},
75         drawtype = "mesh",
76         mesh = "torch_wall.obj",
77         tiles = {"redstone_torch.png"},
78         paramtype = "light",
79         paramtype2 = "wallmounted",
80         sunlight_propagates = true,
81         walkable = false,
82         light_source = 13,
83         groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1, torch=1,redstone=1,},
84         drop = "redstone:torch",
85         selection_box = {
86                 type = "wallmounted",
87                 wall_top = {-0.1, -0.1, -0.1, 0.1, 0.5, 0.1},
88                 wall_bottom = {-0.1, -0.5, -0.1, 0.1, 0.1, 0.1},
89                 wall_side = {-0.5, -0.3, -0.1, -0.2, 0.3, 0.1},
90         },
91         on_construct = function(pos)
92                 redstone.inject(pos,{torch=16})
93                 redstone.update(pos)
94         end,
95         after_destruct = function(pos, oldnode)
96                 redstone.inject(pos,nil)
97                 redstone.update(pos)
98         end,
99         sounds = main.woodSound(),
100 })
101
102
103 minetest.register_lbm({
104         name = "redstone:torch_init",
105         nodenames = {"redstone:torch_wall","redstone:torch_floor"},
106         run_at_every_load = true,
107         action = function(pos)
108                 redstone.inject(pos,{torch=16})
109         end,
110 })