aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/Mob.h
blob: 0e1af2be723cdbff82afe1ebabb4966a5168f912 (plain)
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
#pragma once
using namespace std;

#include "Entity.h"
#include "MobType.h"
#include "GoalSelector.h"

class HitResult;
class Level;
class CompoundTag;
class MobEffectInstance;
class DamageSource;
class MobEffect;
class LookControl;
class MoveControl;
class JumpControl;
class BodyControl;
class PathNavigation;
class Sensing;
class Icon;
class Pos;

class Mob : public Entity
{
	friend class MobSpawner;
protected:
	// 4J - added for common ctor code
	void _init();
public:
	Mob(Level* level);
	virtual ~Mob();

	// 4J-PB - added to replace (e instanceof Type), avoiding dynamic casts
	eINSTANCEOF GetType()						{ return eTYPE_MOB;}
	static Entity *create(Level *level) { return NULL; }

public:
	static const int ATTACK_DURATION = 5;
	static const int PLAYER_HURT_EXPERIENCE_TIME = 20 * 3;

public: // 4J Stu - Made public
	static const int DATA_EFFECT_COLOR_ID = 8;

private:
	static const double MIN_MOVEMENT_DISTANCE;

public:
	int invulnerableDuration;
	float timeOffs;
	float rotA;
	float yBodyRot, yBodyRotO;
	float yHeadRot, yHeadRotO;

protected:
	float oRun, run;
	float animStep, animStepO;
	bool hasHair;
	//	wstring textureName;
	int textureIdx;		// 4J changed from wstring textureName
	bool allowAlpha;
	float rotOffs;
	wstring modelName;
	float bobStrength;
	int deathScore;
	float renderOffset;

public:
	float walkingSpeed;
	float flyingSpeed;
	float oAttackAnim, attackAnim;

protected:
	int health;

public:
	int lastHealth;

protected:
	int dmgSpill;

public:
	int ambientSoundTime;
	int hurtTime;
	int hurtDuration;
	float hurtDir;
	int deathTime;
	int attackTime;
	float oTilt, tilt;

protected:
	bool dead;
	int xpReward;

public:
	int modelNum;
	float animSpeed;
	float walkAnimSpeedO;
	float walkAnimSpeed;
	float walkAnimPos;

protected:
	shared_ptr<Player> lastHurtByPlayer;
	int lastHurtByPlayerTime;

private:
	shared_ptr<Mob> lastHurtByMob;
	int lastHurtByMobTime;
	shared_ptr<Mob> lastHurtMob;

public:
	int arrowCount;
	int removeArrowTime;

protected:
	map<int, MobEffectInstance *> activeEffects;

private:
	bool effectsDirty;
	int effectColor;

	LookControl *lookControl;
	MoveControl *moveControl;
	JumpControl *jumpControl;
	BodyControl *bodyControl;
	PathNavigation *navigation;

protected:
	GoalSelector goalSelector;
	GoalSelector targetSelector;

private:
	shared_ptr<Mob> target;
	Sensing *sensing;
	float speed;

	Pos *restrictCenter;
	float restrictRadius;

public:
	virtual LookControl *getLookControl();
	virtual MoveControl *getMoveControl();
	virtual JumpControl *getJumpControl();
	virtual PathNavigation *getNavigation();
	virtual Sensing *getSensing();
	virtual Random *getRandom();
	virtual shared_ptr<Mob> getLastHurtByMob();
	virtual shared_ptr<Mob> getLastHurtMob();
	void setLastHurtMob(shared_ptr<Entity> target);
	virtual int getNoActionTime();
	float getYHeadRot();
	void setYHeadRot(float yHeadRot);
	float getSpeed();
	void setSpeed(float speed);
	virtual bool doHurtTarget(shared_ptr<Entity> target);
	shared_ptr<Mob> getTarget();
	virtual void setTarget(shared_ptr<Mob> target);
	virtual bool canAttackType(eINSTANCEOF targetType);
	virtual void ate();

	bool isWithinRestriction();
	bool isWithinRestriction(int x, int y, int z);
	void restrictTo(int x, int y, int z, int radius);
	Pos *getRestrictCenter();
	float getRestrictRadius();
	void clearRestriction();
	bool hasRestriction();

	virtual void setLastHurtByMob(shared_ptr<Mob> hurtBy);

protected:
	virtual void defineSynchedData();

public:
	bool canSee(shared_ptr<Entity> target);
	virtual int getTexture();		// 4J - changed from wstring to int
	virtual bool isPickable() ;
	virtual bool isPushable();
	virtual float getHeadHeight();
	virtual int getAmbientSoundInterval();
	void playAmbientSound();
	virtual void baseTick();

protected:
	virtual void tickDeath();
	virtual int decreaseAirSupply(int currentSupply);
	virtual int getExperienceReward(shared_ptr<Player> killedBy);
	virtual bool isAlwaysExperienceDropper();

public:
	void spawnAnim();
	virtual void rideTick();

protected:
	int lSteps;
	double lx, ly, lz, lyr, lxr;

public:
	virtual void lerpTo(double x, double y, double z, float yRot, float xRot, int steps);

private:
	float fallTime;

public:
	void superTick();
	virtual void tick();
	virtual void heal(int heal);
	virtual int getMaxHealth() = 0;
	virtual int getHealth();
	virtual void setHealth(int health);

protected:
	int lastHurt;

public:
	virtual bool hurt(DamageSource *source, int dmg);

protected:
	float getVoicePitch();

public:
	virtual void animateHurt();

	/**
	* Fetches the mob's armor value, from 0 (no armor) to 20 (full armor)
	* 
	* @return
	*/
	virtual int getArmorValue();

protected:
	virtual void hurtArmor(int damage);
	virtual int getDamageAfterArmorAbsorb(DamageSource *damageSource, int damage);
	virtual int getDamageAfterMagicAbsorb(DamageSource *damageSource, int damage);

	virtual void actuallyHurt(DamageSource *source, int dmg);
	virtual float getSoundVolume();
	virtual int getAmbientSound();
	virtual int getHurtSound();
	virtual int getDeathSound();

public:
	void knockback(shared_ptr<Entity> source, int dmg, double xd, double zd);
	virtual void die(DamageSource *source);

protected:
	virtual void dropRareDeathLoot(int rareLootLevel);
	virtual void dropDeathLoot(bool wasKilledByPlayer, int playerBonusLevel);
	virtual int getDeathLoot();
	virtual void causeFallDamage(float distance);

public:
	virtual void travel(float xa, float ya);
	virtual bool onLadder();
	virtual bool isShootable();
	virtual void addAdditonalSaveData(CompoundTag *entityTag);
	virtual void readAdditionalSaveData(CompoundTag *tag);
	virtual bool isAlive();
	virtual bool isWaterMob();
	virtual int getLightColor(float a);		// 4J - added

protected:
	int noActionTime;
	float xxa, yya, yRotA;
	bool jumping;
	float defaultLookAngle;
	float runSpeed;
protected:
	int noJumpDelay;

public:
	virtual void setYya(float yya);
	virtual void setJumping(bool jump);

	virtual void aiStep();

protected:
	virtual bool useNewAi();
	virtual bool isEffectiveAI();
	virtual bool isImmobile();

public:
	virtual bool isBlocking();

protected:
	virtual void jumpFromGround();
	virtual bool removeWhenFarAway();

private:
	shared_ptr<Entity> lookingAt;

protected:
	int lookTime;

	virtual void checkDespawn();
	virtual void newServerAiStep();
	virtual void serverAiMobStep();
	virtual void serverAiStep();

public:
	virtual int getMaxHeadXRot();

protected:
	void lookAt(shared_ptr<Entity> e, float yMax, float xMax);
	bool isLookingAtAnEntity();
	shared_ptr<Entity> getLookingAt();

private:
	float rotlerp(float a, float b, float max);

public:
	virtual bool canSpawn();

protected:
	virtual void outOfWorld();

public:
	float getAttackAnim(float a);
	virtual Vec3 *getPos(float a);
	virtual Vec3 *getLookAngle();
	Vec3 *getViewVector(float a);
	virtual float getSizeScale();
	virtual float getHeadSizeScale();
	HitResult *pick(double range, float a);
	virtual int getMaxSpawnClusterSize();
	virtual shared_ptr<ItemInstance> getCarriedItem();
	virtual shared_ptr<ItemInstance> getArmor(int pos);
	virtual void handleEntityEvent(byte id);
	virtual bool isSleeping();
	virtual Icon *getItemInHandIcon(shared_ptr<ItemInstance> item, int layer);
	virtual bool shouldRender(Vec3 *c);

protected:
	void tickEffects();

public:
	void removeAllEffects();
	vector<MobEffectInstance *> *getActiveEffects();
	bool hasEffect(int id);
	bool hasEffect(MobEffect *effect);
	MobEffectInstance *getEffect(MobEffect *effect);
	void addEffect(MobEffectInstance *newEffect);
	void addEffectNoUpdate(MobEffectInstance *newEffect); // 4J Added
	virtual bool canBeAffected(MobEffectInstance *newEffect);
	virtual bool isInvertedHealAndHarm();
	void removeEffectNoUpdate(int effectId);
	void removeEffect(int effectId);

protected:
	virtual void onEffectAdded(MobEffectInstance *effect);
	virtual void onEffectUpdated(MobEffectInstance *effect);
	virtual void onEffectRemoved(MobEffectInstance *effect);

public:
	virtual float getWalkingSpeedModifier();

	// 4J-Pb added (from 1.2.3)
	virtual void teleportTo(double x, double y, double z);
	virtual bool isBaby();
	virtual MobType getMobType();
	virtual void breakItem(shared_ptr<ItemInstance> itemInstance);

	virtual bool isInvulnerable();

	virtual void finalizeMobSpawn();
	virtual bool canBeControlledByRider();

	// 4J Added override to update ai elements when loading entity from schematics
	virtual void setLevel(Level *level);
};