aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/Mob.h
blob: 113105098aaded254c3da0cbf4f176ea12c6837c (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
#pragma once
using namespace std;

#include "LivingEntity.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 MobGroupData;

class Mob : public LivingEntity
{
	friend class MobSpawner;
public:
	// 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 float MAX_WEARING_ARMOR_CHANCE;
	static const float MAX_PICKUP_LOOT_CHANCE;
	static const float MAX_ENCHANTED_ARMOR_CHANCE;
	static const float MAX_ENCHANTED_WEAPON_CHANCE;

private:
	static const int DATA_CUSTOM_NAME = 10;
	static const int DATA_CUSTOM_NAME_VISIBLE = 11;

public:
	int ambientSoundTime;

protected:
	int xpReward;

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

protected:
	GoalSelector goalSelector;
	GoalSelector targetSelector;

private:
	shared_ptr<LivingEntity> target;
	Sensing *sensing;

	ItemInstanceArray equipment;

protected:
	floatArray dropChances;

private:
	bool _canPickUpLoot;
	bool persistenceRequired;

protected:
	// 4J - added for common ctor code
	void _init();

public:
	Mob(Level* level);
	virtual ~Mob();

protected:
	void registerAttributes();

public:
	virtual LookControl *getLookControl();
	virtual MoveControl *getMoveControl();
	virtual JumpControl *getJumpControl();
	virtual PathNavigation *getNavigation();
	virtual Sensing *getSensing();
	shared_ptr<LivingEntity> getTarget();
	virtual void setTarget(shared_ptr<LivingEntity> target);
	virtual bool canAttackType(eINSTANCEOF targetType);
	virtual void ate();

protected:
	virtual void defineSynchedData();

public:
	virtual int getAmbientSoundInterval();
	void playAmbientSound();
	virtual void baseTick();

protected:
	virtual int getExperienceReward(shared_ptr<Player> killedBy);

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

protected:
	virtual float tickHeadTurn(float yBodyRotT, float walkSpeed);
	virtual int getAmbientSound();
	virtual int getDeathLoot();
	virtual void dropDeathLoot(bool wasKilledByPlayer, int playerBonusLevel);

public:
	virtual void addAdditonalSaveData(CompoundTag *entityTag);
	virtual void readAdditionalSaveData(CompoundTag *tag);

protected:
	float defaultLookAngle;

public:
	virtual void setYya(float yya);
	virtual void setSpeed(float speed);
	virtual void aiStep();

protected:
	virtual bool useNewAi();
	virtual bool removeWhenFarAway();

private:
	shared_ptr<Entity> lookingAt;

protected:
	int lookTime;

	virtual void checkDespawn();
	virtual void newServerAiStep();
	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();
	virtual float getSizeScale();
	virtual float getHeadSizeScale();
	virtual int getMaxSpawnClusterSize();
	virtual int getMaxFallDistance();
	virtual shared_ptr<ItemInstance> getCarriedItem();
	virtual shared_ptr<ItemInstance> getCarried(int slot);
	virtual shared_ptr<ItemInstance> getArmor(int pos);
	virtual void setEquippedSlot(int slot, shared_ptr<ItemInstance> item);
	virtual ItemInstanceArray getEquipmentSlots();

protected:
	virtual void dropEquipment(bool byPlayer, int playerBonusLevel);
	virtual void populateDefaultEquipmentSlots();

public:
	static int getEquipmentSlotForItem(shared_ptr<ItemInstance> item);
	static Item *getEquipmentForSlot(int slot, int type);

protected:
	virtual void populateDefaultEquipmentEnchantments();

public:
	/**
	* Added this method so mobs can handle their own spawn settings instead of
	* hacking MobSpawner.java
	* 
	* @param groupData
	*            TODO
	* @return TODO
	*/
	virtual MobGroupData *finalizeMobSpawn(MobGroupData *groupData, int extraData = 0); // 4J Added extraData param
	virtual void finalizeSpawnEggSpawn(int extraData); // 4J Added
	virtual bool canBeControlledByRider();
	virtual wstring getAName();
	virtual void setPersistenceRequired();
	virtual void setCustomName(const wstring &name);
	virtual wstring getCustomName();
	virtual bool hasCustomName();
	virtual void setCustomNameVisible(bool visible);
	virtual bool isCustomNameVisible();
	virtual bool shouldShowName();
	virtual void setDropChance(int slot, float pct);
	virtual bool canPickUpLoot();
	virtual void setCanPickUpLoot(bool canPickUpLoot);
	virtual bool isPersistenceRequired();
	virtual bool interact(shared_ptr<Player> player);

protected:
	virtual bool mobInteract(shared_ptr<Player> player);

	// roper / leash methods

private:
	bool _isLeashed;
	shared_ptr<Entity> leashHolder;
	CompoundTag *leashInfoTag;

protected:
	virtual void tickLeash();

public:
	virtual void dropLeash(bool synch, bool createItemDrop);
	virtual bool canBeLeashed();
	virtual bool isLeashed();
	virtual shared_ptr<Entity> getLeashHolder();
	virtual void setLeashedTo(shared_ptr<Entity> holder, bool synch);

private:
	virtual void restoreLeashFromSave();
	virtual bool shouldRender(Vec3 *c);


public:

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