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.Item = class{
26 dragonblocks.error("Can not register item: Missing argument");
27 dblib.copy(this, obj);
29 dragonblocks.error("Can not register item: Missing name");
31 dragonblocks.error("Can not register item: Missing texture");
32 if(dragonblocks.items[this.name])
33 dragonblocks.error("Can not register item '" + this.name + "': Item already exists");
34 if(this.desc != "" && this.description != "")
35 this.desc = this.description || this.desc || this.name;
36 this.stacksize = this.stacksize || dragonblocks.settings.item.defaultStacksize;
37 this.groups = this.groups || [];
38 this.groups.push("default");
39 dragonblocks.items[this.name] = this;
40 dragonblocks.registeredItems.push(this);
43 return (this.groups.indexOf(name) != -1);
46 if(this.sounds && this.sounds[s]){
47 dragonblocks.playSound(this.sounds[s]);
50 else if(this.sounds && this.sounds[s] == "")
52 for(let groupname of this.groups){
53 let group = dragonblocks.groups[groupname];
54 if(group && group.sounds && group.sounds[s]){
55 dragonblocks.playSound(group.sounds[s]);
58 else if(group && group.sounds && group.sounds[s] == "")
63 dragonblocks.registeredItems = [];
64 dragonblocks.items = {};
65 dragonblocks.registerItem = function(obj){
66 new dragonblocks.Item(obj);
68 dragonblocks.onUseItemFunctions = [];
69 dragonblocks.registerOnUseItem = function(func){
70 dragonblocks.onUseItemFunctions.push(func);
72 dragonblocks.itemMatch = function(item1, item2){
73 if(dragonblocks.items[item1])
74 item1 = dragonblocks.items[item1];
75 if(dragonblocks.items[item2])
76 item2 = dragonblocks.items[item2];
77 if(dragonblocks.groups[item1])
78 item1 = dragonblocks.groups[item1];
79 if(dragonblocks.groups[item2])
80 item2 = dragonblocks.groups[item2];
81 return item1 == item2 || item1 && item2 && (item1.name == item2.name || item1.inGroup && item1.inGroup(item2.name) || item2.inGroup && item2.inGroup(item1.name));