the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#pragma once
2using namespace std;
3
4#include "LivingEntity.h"
5#include "Definitions.h"
6#include "Abilities.h"
7#include "FoodData.h"
8#include "PlayerEnderChestContainer.h"
9#include "CommandSender.h"
10#include "ScoreHolder.h"
11
12class AbstractContainerMenu;
13class Stats;
14class FishingHook;
15class EntityHorse;
16class ItemEntity;
17class Slot;
18class Pos;
19class TileEntity;
20class BeaconTileEntity;
21class FurnaceTileEntity;
22class DispenserTileEntity;
23class SignTileEntity;
24class BrewingStandTileEntity;
25class HopperTileEntity;
26class MinecartHopper;
27class Inventory;
28class Container;
29class FoodData;
30class DamageSource;
31class Merchant;
32class PlayerEnderChestContainer;
33class GameType;
34class Scoreboard;
35
36class Player : public LivingEntity, public CommandSender, public ScoreHolder
37{
38public:
39 static const int MAX_NAME_LENGTH = 16 + 4;
40 static const int MAX_HEALTH = 20;
41 static const int SLEEP_DURATION = 100;
42 static const int WAKE_UP_DURATION = 10;
43
44 static const int CHAT_VISIBILITY_FULL = 0;
45 static const int CHAT_VISIBILITY_SYSTEM = 1;
46 static const int CHAT_VISIBILITY_HIDDEN = 2;
47
48 // 4J-PB - added for a red death fade in the gui
49 static const int DEATHFADE_DURATION = 21;
50private:
51 static const int FLY_ACHIEVEMENT_SPEED = 25;
52
53 static const int DATA_PLAYER_FLAGS_ID = 16;
54 static const int DATA_PLAYER_ABSORPTION_ID = 17;
55 static const int DATA_SCORE_ID = 18;
56
57protected:
58 static const int FLAG_HIDE_CAPE = 1;
59
60public:
61 shared_ptr<Inventory> inventory;
62
63private:
64 shared_ptr<PlayerEnderChestContainer> enderChestInventory;
65
66public:
67 AbstractContainerMenu *inventoryMenu;
68 AbstractContainerMenu *containerMenu;
69
70protected:
71 FoodData foodData;
72 int jumpTriggerTime;
73
74public:
75 BYTE userType;
76 float oBob, bob;
77
78 wstring name;
79 int takeXpDelay;
80
81 // 4J-PB - track custom skin
82 wstring customTextureUrl;
83 wstring customTextureUrl2;
84 unsigned int m_uiPlayerCurrentSkin;
85 void ChangePlayerSkin();
86
87 // 4J-PB - not needed, since cutomtextureurl2 is the same thing wstring cloakTexture;
88
89 double xCloakO, yCloakO, zCloakO;
90 double xCloak, yCloak, zCloak;
91
92 // 4J-HG: store display name, added for Xbox One "game display name"
93 wstring m_displayName;
94
95protected:
96 // player sleeping in bed?
97 bool m_isSleeping;
98
99public:
100 Pos *bedPosition;
101
102private:
103 int sleepCounter; // animation timer
104 int deathFadeCounter; // animation timer
105
106public:
107 float bedOffsetX, bedOffsetY, bedOffsetZ;
108 Stats *stats;
109
110private:
111 Pos *respawnPosition;
112 bool respawnForced;
113 Pos *minecartAchievementPos;
114
115 //4J Gordon: These are in cms, every time they go > 1m they are entered into the stats
116 int distanceWalk, distanceSwim, distanceFall, distanceClimb, distanceMinecart, distanceBoat, distancePig;
117
118public:
119 Abilities abilities;
120
121 int experienceLevel, totalExperience;
122 float experienceProgress;
123
124 // 4J Stu - Made protected so that we can access it from MultiPlayerLocalPlayer
125protected:
126 shared_ptr<ItemInstance> useItem;
127 int useItemDuration;
128
129protected:
130 float defaultWalkSpeed;
131 float defaultFlySpeed;
132
133private:
134 int lastLevelUpTime;
135
136public:
137
138 eINSTANCEOF GetType() { return eTYPE_PLAYER; }
139
140 // 4J Added to default init
141 void _init();
142
143 Player(Level *level, const wstring &name);
144 virtual ~Player();
145
146protected:
147 virtual void registerAttributes();
148 virtual void defineSynchedData();
149
150public:
151 shared_ptr<ItemInstance> getUseItem();
152 int getUseItemDuration();
153 bool isUsingItem(); int getTicksUsingItem();
154 void releaseUsingItem();
155 void stopUsingItem();
156 virtual bool isBlocking();
157
158 // 4J Stu - Added for things that should only be ticked once per simulation frame
159 virtual void updateFrameTick();
160
161 virtual void tick();
162 virtual int getPortalWaitTime();
163 virtual int getDimensionChangingDelay();
164 virtual void playSound(int iSound, float volume, float pitch);
165
166protected:
167 void spawnEatParticles(shared_ptr<ItemInstance> useItem, int count);
168 virtual void completeUsingItem();
169
170public:
171 virtual void handleEntityEvent(byte id);
172
173protected:
174 bool isImmobile();
175 virtual void closeContainer();
176
177public:
178 virtual void ride(shared_ptr<Entity> e);
179 void prepareCustomTextures();
180 virtual void rideTick();
181 virtual void resetPos();
182
183protected:
184 virtual void serverAiStep();
185
186public:
187 virtual void aiStep();
188
189private:
190 virtual void touch(shared_ptr<Entity> entity);
191
192public:
193 virtual int getScore();
194 virtual void setScore(int value);
195 virtual void increaseScore(int amount);
196 virtual void die(DamageSource *source);
197 virtual void awardKillScore(shared_ptr<Entity> victim, int awardPoints);
198 virtual bool isShootable();
199 bool isCreativeModeAllowed();
200 virtual shared_ptr<ItemEntity> drop(bool all);
201 shared_ptr<ItemEntity> drop(shared_ptr<ItemInstance> item);
202 shared_ptr<ItemEntity> drop(shared_ptr<ItemInstance> item, bool randomly);
203
204protected:
205 virtual void reallyDrop(shared_ptr<ItemEntity> thrownItem);
206
207public:
208 float getDestroySpeed(Tile *tile, bool hasProperTool);
209 bool canDestroy(Tile *tile);
210 virtual void readAdditionalSaveData(CompoundTag *entityTag);
211 virtual void addAdditonalSaveData(CompoundTag *entityTag);
212 virtual bool openContainer(shared_ptr<Container> container); // 4J - added bool return
213 virtual bool openHopper(shared_ptr<HopperTileEntity> container);
214 virtual bool openHopper(shared_ptr<MinecartHopper> container);
215 virtual bool openHorseInventory(shared_ptr<EntityHorse> horse, shared_ptr<Container> container);
216 virtual bool startEnchanting(int x, int y, int z, const wstring &name); // 4J - added bool return
217 virtual bool startRepairing(int x, int y, int z); // 4J - added bool return
218 virtual bool startCrafting(int x, int y, int z); // 4J - added bool return
219 virtual bool openFireworks(int x, int y, int z); // 4J - added
220 virtual float getHeadHeight();
221
222 // 4J-PB - added to keep the code happy with the change to make the third person view per player
223 virtual int ThirdPersonView() {return 0;}
224 virtual void SetThirdPersonView(int val) {}
225
226protected:
227 virtual void setDefaultHeadHeight();
228
229public:
230 shared_ptr<FishingHook> fishing;
231
232 virtual bool hurt(DamageSource *source, float dmg);
233 virtual bool canHarmPlayer(shared_ptr<Player> target);
234 virtual bool canHarmPlayer(wstring targetName); // 4J: Added for ServerPlayer when only player name is provided
235
236protected:
237 virtual void hurtArmor(float damage);
238
239public:
240 virtual int getArmorValue();
241 virtual float getArmorCoverPercentage();
242
243protected:
244 virtual void actuallyHurt(DamageSource *source, float dmg);
245
246public:
247 using Entity::interact;
248
249 virtual bool openFurnace(shared_ptr<FurnaceTileEntity> container); // 4J - added bool return
250 virtual bool openTrap(shared_ptr<DispenserTileEntity> container); // 4J - added bool return
251 virtual void openTextEdit(shared_ptr<TileEntity> sign);
252 virtual bool openBrewingStand(shared_ptr<BrewingStandTileEntity> brewingStand); // 4J - added bool return
253 virtual bool openBeacon(shared_ptr<BeaconTileEntity> beacon);
254 virtual bool openTrading(shared_ptr<Merchant> traderTarget, const wstring &name); // 4J - added bool return
255 virtual void openItemInstanceGui(shared_ptr<ItemInstance> itemInstance);
256 virtual bool interact(shared_ptr<Entity> entity);
257 virtual shared_ptr<ItemInstance> getSelectedItem();
258 void removeSelectedItem();
259 virtual double getRidingHeight();
260 virtual void attack(shared_ptr<Entity> entity);
261 virtual void crit(shared_ptr<Entity> entity);
262 virtual void magicCrit(shared_ptr<Entity> entity);
263 virtual void respawn();
264
265protected:
266 static void animateRespawn(shared_ptr<Player> player, Level *level);
267
268public:
269 Slot *getInventorySlot(int slotId);
270 virtual void remove();
271 virtual bool isInWall();
272 virtual bool isLocalPlayer();
273
274 enum BedSleepingResult
275 {
276 OK, NOT_POSSIBLE_HERE, NOT_POSSIBLE_NOW, TOO_FAR_AWAY, OTHER_PROBLEM, NOT_SAFE
277 };
278
279 virtual BedSleepingResult startSleepInBed(int x, int y, int z, bool bTestUse = false);
280
281private:
282 void setBedOffset(int bedDirection);
283
284public:
285 /**
286 *
287 * @param forcefulWakeUp
288 * If the player has been forced to wake up. When this happens,
289 * the client will skip the wake-up animation. For example, when
290 * the player is hurt or the bed is destroyed.
291 * @param updateLevelList
292 * If the level's sleeping player list needs to be updated. This
293 * is usually the case.
294 * @param saveRespawnPoint
295 * TODO
296 */
297 virtual void stopSleepInBed(bool forcefulWakeUp, bool updateLevelList, bool saveRespawnPoint);
298
299private:
300 bool checkBed();
301
302public:
303 static Pos *checkBedValidRespawnPosition(Level *level, Pos *pos, bool forced);
304 float getSleepRotation();
305 bool isSleeping();
306 bool isSleepingLongEnough();
307 int getSleepTimer();
308 int getDeathFadeTimer();
309
310protected:
311 bool getPlayerFlag(int flag);
312 void setPlayerFlag(int flag, bool value);
313
314public:
315 /**
316 * This method is currently only relevant to client-side players. It will
317 * try to load the messageId from the language file and display it to the
318 * client.
319 */
320 virtual void displayClientMessage(int messageId);
321 virtual Pos *getRespawnPosition();
322 virtual bool isRespawnForced();
323 virtual void setRespawnPosition(Pos *respawnPosition, bool forced);
324 virtual void awardStat(Stat *stat, byteArray param);
325
326protected:
327 void jumpFromGround();
328
329public:
330 virtual void travel(float xa, float ya);
331 virtual float getSpeed();
332 virtual void checkMovementStatistiscs(double dx, double dy, double dz);
333
334private:
335 void checkRidingStatistiscs(double dx, double dy, double dz);
336
337 bool m_bAwardedOnARail;
338
339protected:
340 virtual void causeFallDamage(float distance);
341
342public:
343 virtual void killed(shared_ptr<LivingEntity> mob);
344 virtual void makeStuckInWeb();
345 virtual Icon *getItemInHandIcon(shared_ptr<ItemInstance> item, int layer);
346 virtual shared_ptr<ItemInstance> getArmor(int pos);
347 virtual void increaseXp(int i);
348 virtual void giveExperienceLevels(int amount);
349 int getXpNeededForNextLevel();
350 void causeFoodExhaustion(float amount);
351 FoodData *getFoodData();
352 bool canEat(bool magicalItem);
353 bool isHurt();
354 virtual void startUsingItem(shared_ptr<ItemInstance> instance, int duration);
355 virtual bool mayDestroyBlockAt(int x, int y, int z);
356 virtual bool mayUseItemAt(int x, int y, int z, int face, shared_ptr<ItemInstance> item);
357
358protected:
359 virtual int getExperienceReward(shared_ptr<Player> killedBy);
360 virtual bool isAlwaysExperienceDropper();
361
362public:
363 virtual wstring getAName();
364 virtual bool shouldShowName();
365 virtual void restoreFrom(shared_ptr<Player> oldPlayer, bool restoreAll);
366
367protected:
368 bool makeStepSound();
369
370public:
371 void onUpdateAbilities();
372 void setGameMode(GameType *mode);
373 wstring getName();
374 virtual wstring getDisplayName();
375 virtual wstring getNetworkName(); // 4J: Added
376
377 virtual Level *getCommandSenderWorld();
378
379 shared_ptr<PlayerEnderChestContainer> getEnderChestInventory();
380
381 virtual shared_ptr<ItemInstance> getCarried(int slot);
382 virtual shared_ptr<ItemInstance> getCarriedItem();
383 virtual void setEquippedSlot(int slot, shared_ptr<ItemInstance> item);
384 virtual bool isInvisibleTo(shared_ptr<Player> player);
385 virtual ItemInstanceArray getEquipmentSlots();
386 virtual bool isCapeHidden();
387 virtual bool isPushedByWater();
388 virtual Scoreboard *getScoreboard();
389 virtual Team *getTeam();
390 virtual void setAbsorptionAmount(float absorptionAmount);
391 virtual float getAbsorptionAmount();
392
393 //////// 4J /////////////////
394
395 static int hash_fnct(const shared_ptr<Player> k);
396 static bool eq_test(const shared_ptr<Player> x, const shared_ptr<Player> y);
397
398 // 4J Stu - Added to allow callback to tutorial to stay within Minecraft.Client
399 // Overidden in LocalPlayer
400 virtual void onCrafted(shared_ptr<ItemInstance> item) {}
401
402 // 4J Overriding this so that we can have some different default skins
403 virtual int getTexture(); // 4J changed from wstring to int
404 void setPlayerDefaultSkin(EDefaultSkins skin);
405 EDefaultSkins getPlayerDefaultSkin() { return m_skinIndex; }
406 virtual void setCustomSkin(DWORD skinId);
407 DWORD getCustomSkin() {return m_dwSkinId; }
408 virtual void setCustomCape(DWORD capeId);
409 DWORD getCustomCape() {return m_dwCapeId; }
410
411 static DWORD getCapeIdFromPath(const wstring &cape);
412 static wstring getCapePathFromId(DWORD capeId);
413 static unsigned int getSkinAnimOverrideBitmask(DWORD skinId);
414
415 // 4J Added
416 void setXuid(PlayerUID xuid);
417 PlayerUID getXuid() { return m_xuid; }
418 void setOnlineXuid(PlayerUID xuid) { m_OnlineXuid = xuid; }
419 PlayerUID getOnlineXuid() { return m_OnlineXuid; }
420
421 void setPlayerIndex(DWORD dwIndex) { m_playerIndex = dwIndex; }
422 DWORD getPlayerIndex() { return m_playerIndex; }
423
424 void setIsGuest(bool bVal) { m_bIsGuest = bVal; }
425 bool isGuest() { return m_bIsGuest; }
426
427 void setShowOnMaps(bool bVal) { m_bShownOnMaps = bVal; }
428 bool canShowOnMaps() { return m_bShownOnMaps && !getPlayerGamePrivilege(ePlayerGamePrivilege_Invisible); }
429
430 virtual void sendMessage(const wstring& message, ChatPacket::EChatPacketMessage type = ChatPacket::e_ChatCustom, int customData = -1, const wstring& additionalMessage = L"") { }
431private:
432 PlayerUID m_xuid;
433 PlayerUID m_OnlineXuid;
434
435protected:
436 bool m_bShownOnMaps;
437
438 bool m_bIsGuest;
439
440private:
441 EDefaultSkins m_skinIndex;
442 DWORD m_dwSkinId,m_dwCapeId;
443
444 // 4J Added - Used to show which colour the player is on the map/behind their name
445 DWORD m_playerIndex;
446
447 // 4J-PB - to track debug options from the server player
448 unsigned int m_uiDebugOptions;
449
450public:
451 void SetDebugOptions(unsigned int uiVal) { m_uiDebugOptions=uiVal;}
452 unsigned int GetDebugOptions(void) { return m_uiDebugOptions;}
453
454 void StopSleeping() {}
455
456public:
457 // If you add things here, you should also add a message to ClientConnection::displayPrivilegeChanges to alert players to changes
458 enum EPlayerGamePrivileges
459 {
460 ePlayerGamePrivilege_CannotMine = 0, // Only checked if trust system is on
461 ePlayerGamePrivilege_CannotBuild, // Only checked if trust system is on
462 ePlayerGamePrivilege_CannotAttackMobs, // Only checked if trust system is on
463 ePlayerGamePrivilege_CannotAttackPlayers, //Only checked if trust system is on
464 ePlayerGamePrivilege_Op,
465 ePlayerGamePrivilege_CanFly,
466 ePlayerGamePrivilege_ClassicHunger,
467 ePlayerGamePrivilege_Invisible,
468 ePlayerGamePrivilege_Invulnerable,
469
470 ePlayerGamePrivilege_CreativeMode, // Used only to transfer across network, should never be used to determine if a player is in creative mode
471
472 ePlayerGamePrivilege_CannotAttackAnimals, // Only checked if trust system is on
473 ePlayerGamePrivilege_CanUseDoorsAndSwitches, // Only checked if trust system is on
474 ePlayerGamePrivilege_CanUseContainers, // Only checked if trust system is on
475
476 ePlayerGamePrivilege_CanToggleInvisible,
477 ePlayerGamePrivilege_CanToggleFly,
478 ePlayerGamePrivilege_CanToggleClassicHunger,
479 ePlayerGamePrivilege_CanTeleport,
480
481 // Currently enum is used to bitshift into an unsigned int
482 ePlayerGamePrivilege_MAX = 32,
483 ePlayerGamePrivilege_All = 33,
484 ePlayerGamePrivilege_HOST,
485 };
486private:
487 // 4J Added - Used to track what actions players have been allowed to perform by the host
488 unsigned int m_uiGamePrivileges;
489
490 unsigned int getPlayerGamePrivilege(EPlayerGamePrivileges privilege);
491public:
492 unsigned int getAllPlayerGamePrivileges() { return getPlayerGamePrivilege(ePlayerGamePrivilege_All); }
493
494 static unsigned int getPlayerGamePrivilege(unsigned int uiGamePrivileges, EPlayerGamePrivileges privilege);
495 void setPlayerGamePrivilege(EPlayerGamePrivileges privilege, unsigned int value);
496 static void setPlayerGamePrivilege(unsigned int &uiGamePrivileges, EPlayerGamePrivileges privilege, unsigned int value);
497
498 bool isAllowedToUse(Tile *tile);
499 bool isAllowedToUse(shared_ptr<ItemInstance> item);
500 bool isAllowedToInteract(shared_ptr<Entity> target);
501 bool isAllowedToMine();
502 bool isAllowedToAttackPlayers();
503 bool isAllowedToAttackAnimals();
504 bool isAllowedToHurtEntity(shared_ptr<Entity> target);
505 bool isAllowedToFly();
506 bool isAllowedToIgnoreExhaustion();
507 bool isAllowedToTeleport();
508 bool hasInvisiblePrivilege();
509 bool hasInvulnerablePrivilege();
510 bool isModerator();
511
512 static void enableAllPlayerPrivileges(unsigned int &uigamePrivileges, bool enable);
513 void enableAllPlayerPrivileges(bool enable);
514
515 virtual bool canCreateParticles();
516
517public:
518 // 4J Stu - Added hooks for the game rules
519 virtual void handleCollectItem(shared_ptr<ItemInstance> item) {}
520
521 vector<ModelPart *> *GetAdditionalModelParts();
522 void SetAdditionalModelParts(vector<ModelPart *> *ppAdditionalModelParts);
523
524#if defined(__PS3__) || defined(__ORBIS__)
525 enum ePlayerNameValidState
526 {
527 ePlayerNameValid_NotSet=0,
528 ePlayerNameValid_True,
529 ePlayerNameValid_False
530 };
531
532 ePlayerNameValidState GetPlayerNameValidState();
533 void SetPlayerNameValidState(bool bState);
534#endif
535private:
536 vector<ModelPart *> *m_ppAdditionalModelParts;
537 bool m_bCheckedForModelParts;
538 bool m_bCheckedDLCForModelParts;
539
540#if defined(__PS3__) || defined(__ORBIS__)
541 ePlayerNameValidState m_ePlayerNameValidState; // 4J-PB - to ensure we have the characters for this name in our font, or display a player number instead
542#endif
543};
544
545struct PlayerKeyHash
546{
547 inline int operator() (const shared_ptr<Player> k) const
548 { return Player::hash_fnct (k); }
549};
550
551struct PlayerKeyEq
552{
553 inline bool operator() (const shared_ptr<Player> x, const shared_ptr<Player> y) const
554 { return Player::eq_test (x, y); }
555};
556