4 * Copyright 2020 Elias Fleckenstein <eliasfleckenstein@web.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24 dragonblocks.Node = class extends dragonblocks.Item
35 this.drops = this.drops || this.drop || this.name;
37 if (this.mobstable == undefined)
38 this.mobstable = this.stable;
43 this.ondig = this.ondig || (_ => {
47 this.onblast = this.onblast || (_ => {
51 let oldOnset = this.onset;
54 this.onset = (x, y) => {
55 let meta = dragonblocks.getNode(x, y).meta;
57 meta.liquidInterval = setInterval(_ => {
58 for(let [ix, iy] of [[x + 1, y], [x - 1, y], [x, y + 1]]){
59 let node = dragonblocks.getNode(ix, iy);
61 if (! node || node.stable || node.toNode().liquid)
64 dragonblocks.setNode(ix, iy, self.name);
66 }, self.liquidTickSpeed || 2000);
74 let oldOnremove = this.onremove;
76 this.onremove = (x, y) => {
77 clearInterval(dragonblocks.getNode(x, y).meta.liquidInterval);
86 dragonblocks.nodes = {};
87 dragonblocks.registeredNodes = [];
88 dragonblocks.registerNode = def => {
89 let nodeDef = new dragonblocks.Node(def);
90 dragonblocks.nodes[nodeDef.name] = nodeDef;
91 dragonblocks.registeredNodes.push(nodeDef);
94 dragonblocks.onSetNodeCallbacks = [];
95 dragonblocks.registerOnSetNode = func => {
96 dragonblocks.onSetNodeCallbacks.push(func);
99 dragonblocks.onRemoveNodeCallbacks = [];
100 dragonblocks.registerOnRemoveNode = func => {
101 dragonblocks.onRemoveNodeCallbacks.push(func);
104 dragonblocks.onPlaceNodeCallbacks = [];
105 dragonblocks.registerOnPlaceNode = func => {
106 dragonblocks.onPlaceNodeCallbacks.push(func);
109 dragonblocks.onDigNodeCallbacks = [];
110 dragonblocks.registerOnDigNode = func => {
111 dragonblocks.onDigNodeCallbacks.push(func);
114 dragonblocks.onClickNodeCallbacks = [];
115 dragonblocks.registerOnClickNode = func => {
116 dragonblocks.onClickNodeCallbacks.push(func);
119 dragonblocks.onActivateNodeCallbacks = [];
120 dragonblocks.registerOnActivateNode = func => {
121 dragonblocks.onActivateNodeCallbacks.push(func);
124 dragonblocks.onPunchNodeCallbacks = [];
125 dragonblocks.registerOnPunchNode = func => {
126 dragonblocks.onPunchNodeCallbacks.push(func);