]> git.lizzy.rs Git - dragonblocks.git/blob - game/torch/init.js
Reset file permissions to defaults
[dragonblocks.git] / game / torch / init.js
1 torch = {};
2 torch.directions = ["floor", "left", "right", "ceiling"];
3 torch.check = function(direction, x, y){
4         switch(direction){
5                 case "floor":
6                         return ! dragonblocks.getNode(x, y + 1) || dragonblocks.getNode(x, y + 1).stable;
7                 case "left":
8                         return ! dragonblocks.getNode(x - 1, y) || dragonblocks.getNode(x - 1, y).stable;
9                 case "right":
10                         return ! dragonblocks.getNode(x + 1, y) || dragonblocks.getNode(x + 1, y).stable;
11                 case "ceiling":
12                         return ! dragonblocks.getNode(x, y - 1) || dragonblocks.getNode(x, y - 1).stable;
13         }
14 }
15 dragonblocks.registerItem({
16         name: "torch:torch",
17         desc: "Torch",
18         texture: "torch_torch_floor.png",
19         onuse: (x, y) => {
20                 for(let direction of torch.directions)
21                         if(dragonblocks.player.place(x, y, dragonblocks.nodes["torch:torch_" + direction]))
22                                 return true;
23         }
24 });
25 for(let direction of torch.directions){
26         dragonblocks.registerNode({
27                 name: "torch:torch_" + direction,
28                 desc: "Torch",
29                 drops: "torch:torch",
30                 stable: true,
31                 mobstable: false,
32                 hardness: 1,
33                 texture: "torch_torch_" + direction + ".png",
34                 groups:["snappy"],
35                 hidden: true,
36                 onactivate: (x, y) => {
37                         if(! torch.check(direction, x, y))
38                                 dragonblocks.setNode(x, y, "air");
39                 },
40                 onplace: (x, y) => {
41                         if(! torch.check(direction, x, y))
42                                 return false;
43                 }
44         });
45 }
46 dragonblocks.registerRecipe({
47         result: "torch:torch 4",
48         recipe: [
49                 ["ores:coal"],
50                 ["tools:stick"],
51         ]
52 });