This repository was archived by the owner on Aug 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMobLib.js
More file actions
162 lines (126 loc) · 4.01 KB
/
MobLib.js
File metadata and controls
162 lines (126 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
__ __ _ _ _ _
| \/ | ___ | |__ | | (_)| |__
| |\/| |/ _ \| '_ \| | | || '_ \
| | | | (_) | |_) | |___| || |_) |
|_| |_|\___/|_.__/|_____|_||_.__/
MobLib
Внимание! Запрещено:
1.Распространение библиотеки на сторонних источниках без указание ссылки на официальное сообщество
2.Изменение кода
3.Явное копирование кода
Используя библиотеку вы автоматически соглашаетесь с этими правилами.
©WolfTeam ( https://vk.com/wolf___team )
*/
LIBRARY({
name: "MobLib",
version: 1,
shared: false,
api: "CoreEngine"
});
var Mob = function(params){
//Создание моба
if(!params instanceof Object)
throw "params должен быть объектом.";
if(!params.sid)
throw "params.sid является обязательным полем.";
this.getID = function(){return params.sid;}
this.getSID = function(){return params.sid;}
if(!params.name) params.name = this.getSID();
this.getName = function(){return params.name};
this.entity = MobRegistry.registerEntity(params.sid);
//Задаем рендер с текстурой
if(!params.render) params.render = 3;
if(!params.skin) params.skin = "textures/entity/zombie/zombie.png";
var render;
if(typeof params.render == "number")
render = new Render(params.render);
else
render = params.render;
var model = new EntityModel();
model.setRender(render);
var skin = new Texture(params.skin);
model.setTexture(skin);
this.entity.customizeVisual({
getModels: function() {
return {
"main": model
};
}
});
//Задаем данные моба
if(!params.health) params.health = 20;
if(!params.loot) params.loot = [];
if(!params.loot instanceof Array)
if(params.loot instanceof Object){
params.loot = [params.loot];
}else{
throw "params.loot должен являться массивом предметов.";
}
if(!params.hitbox){
params.hitbox = {w: 1,h: 2};
}else{
if(params.hitbox instanceof Object || typeof params.hitbox == "object"){
if(params.hitbox instanceof Array)
throw "params.hitbox должен быть объектом.(params.hitbox instanceof Array)";
}else{
if(typeof params.hitbox == "number"){
params.hitbox = {w:params.hitbox, h:params.hitbox};
}else{
throw "params.hitbox должен быть объектом.(typeof params.hitbox == "+typeof params.hitbox+")";
}
}
}
this.entity.customizeDescription({
getHealth:function(){
return params.health;
},
getDrop: function(attacker) {
return params.loot;
},
getHitbox: function(attacker) {
return params.hitbox;
}
});
//AI
if(params.ai){
if(typeof params.ai == "number")
this.entity.setBaseType(params.ai);
else
this.entity.customizeAI({
getAITypes: function() {
return params.ai;
}
});
}
//Спавн по X, Y, Z
this.spawn = function(x,y,z){
Entity.spawnCustom(this.getSID(), x, y, z);
}
//Яйцо спавна
this.egg_id = null;
this.getEggID = function(){
return this.egg_id;
};
this.registerEgg = function(texture){
this.egg_id = "egg_spawn_" + this.getID();
IDRegistry.genItemID(this.getEggID());
if(typeof texture == "string")
texture = {name:texture, meta:0}
Item.createItem(this.getEggID(), "Spawn Egg "+ this.getName(), texture);
var custom_entity = this;
Item.registerUseFunctionForID(ItemID[this.getEggID()], function(coords, item, block) {
coords = coords.relative;
custom_entity.spawn(coords.x + .5, coords.y, coords.z + .5);
});
}
};
/*
Mob.ArmorSets = {
diamonds:,
golds:,
irons:,
clothers:
}
*/
EXPORT("Mob", Mob);