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,
23 dragonblocks.Node = class extends dragonblocks.Item{
30 this.drops = this.drops || this.drop || this.name;
31 if(this.mobstable == undefined)
32 this.mobstable = this.stable;
36 let oldOndig = this.ondig;
37 this.ondig = (x, y) => {
39 return oldOndig(x, y);
42 let oldBlast = this.onblast;
43 this.onblast = (x, y) => {
45 return oldBlast(x, y);
48 let oldOnset = this.onset;
49 this.onset = (x, y) => {
50 let meta = dragonblocks.getNode(x, y).meta;
51 meta.liquidInterval = setInterval(_ => {
52 for(let [ix, iy] of [[x + 1, y], [x - 1, y], [x, y + 1]]){
53 let mapNode = dragonblocks.getNode(ix, iy);
54 if(! mapNode || mapNode.stable || mapNode.toNode().liquid)
56 dragonblocks.setNode(ix, iy, self.name);
58 }, self.liquidTickSpeed || 2000);
63 let oldOnremove = this.onremove;
64 this.onremove = (x, y) => {
65 clearInterval(dragonblocks.getNode(x, y).meta.liquidInterval)
70 dragonblocks.nodes[this.name] = this;
71 dragonblocks.registeredNodes.push(this);
74 dragonblocks.nodes = {};
75 dragonblocks.registeredNodes = [];
76 dragonblocks.registerNode = function(obj){
77 new dragonblocks.Node(obj);
79 dragonblocks.onSetNodeFunctions = [];
80 dragonblocks.registerOnSetNode = function(func){
81 dragonblocks.onSetNodeFunctions.push(func);
83 dragonblocks.onRemoveNodeFunctions = [];
84 dragonblocks.registerOnRemoveNode = function(func){
85 dragonblocks.onRemoveNodeFunctions.push(func);
87 dragonblocks.onPlaceNodeFunctions = [];
88 dragonblocks.registerOnPlaceNode = function(func){
89 dragonblocks.onPlaceNodeFunctions.push(func);
91 dragonblocks.onDigNodeFunctions = [];
92 dragonblocks.registerOnDigNode = function(func){
93 dragonblocks.onDigNodeFunctions.push(func);
95 dragonblocks.onClickNodeFunctions = [];
96 dragonblocks.registerOnClickNode = function(func){
97 dragonblocks.onClickNodeFunctions.push(func);
99 dragonblocks.onActivateNodeFunctions = [];
100 dragonblocks.registerOnActivateNode = function(func){
101 dragonblocks.onActivateNodeFunctions.push(func);
103 dragonblocks.onPunchNodeFunctions = [];
104 dragonblocks.registerOnPunchNode = function(func){
105 dragonblocks.onPunchNodeFunctions.push(func);