the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 434 lines 13 kB view raw
1#pragma once 2using namespace std; 3#include "ListTag.h" 4#include "DoubleTag.h" 5#include "FloatTag.h" 6#include "Vec3.h" 7#include "Definitions.h" 8 9class LivingEntity; 10class LightningBolt; 11class ItemEntity; 12class EntityPos; 13class Material; 14class SynchedEntityData; 15class Player; 16class Random; 17class Level; 18class CompoundTag; 19class DamageSource; 20class Explosion; 21 22// 4J Stu Added this mainly to allow is to record telemetry for player deaths 23enum EEntityDamageType 24{ 25 eEntityDamageType_Entity, 26 eEntityDamageType_Fall, 27 eEntityDamageType_Fire, 28 eEntityDamageType_Lava, 29 eEntityDamageType_Water, 30 eEntityDamageType_Suffocate, 31 eEntityDamageType_OutOfWorld, 32 eEntityDamageType_Cactus, 33}; 34 35class Entity : public enable_shared_from_this<Entity> 36{ 37 friend class Gui; // 4J Stu - Added to be able to access the shared flag functions and constants, without making them publicly available to everything 38public: 39 // 4J-PB - added to replace (e instanceof Type), avoiding dynamic casts 40 virtual eINSTANCEOF GetType() = 0; 41 42 inline bool instanceof(eINSTANCEOF super) { return eTYPE_DERIVED_FROM(super, GetType()); } 43 inline static bool instanceof(eINSTANCEOF type, eINSTANCEOF super) { return eTYPE_DERIVED_FROM(super, type); } 44 45public: 46 static const wstring RIDING_TAG; 47 static const short TOTAL_AIR_SUPPLY = 20 * 15; 48 49private: 50 static int entityCounter; 51 52public: 53 int entityId; 54 55 double viewScale; 56 57 bool blocksBuilding; 58 weak_ptr<Entity> rider; // Changed to weak to avoid circular dependency between rider/riding entity 59 shared_ptr<Entity> riding; 60 bool forcedLoading; 61 62 Level *level; 63 double xo, yo, zo; 64 double x, y, z; 65 double xd, yd, zd; 66 float yRot, xRot; 67 float yRotO, xRotO; 68 /*const*/ AABB *bb; // 4J Was final 69 bool onGround; 70 bool horizontalCollision, verticalCollision; 71 bool collision; 72 bool hurtMarked; 73 74protected: 75 bool isStuckInWeb; 76 77public: 78 bool slide; 79 bool removed; 80 float heightOffset; 81 82 float bbWidth; 83 float bbHeight; 84 85 float walkDistO; 86 float walkDist; 87 float moveDist; 88 float fallDistance; 89 90private: 91 int nextStep; 92 93public: 94 double xOld, yOld, zOld; 95 float ySlideOffset; 96 float footSize; 97 bool noPhysics; 98 float pushthrough; 99 100protected: 101 Random *random; 102 103public: 104 int tickCount; 105 int flameTime; 106 107private: 108 int onFire; 109 110protected: 111 bool wasInWater; 112 113public: 114 int invulnerableTime; 115 116private: 117 bool firstTick; 118 119protected: 120 bool fireImmune; 121 122 // values that need to be sent to clients in SMP 123 shared_ptr<SynchedEntityData> entityData; 124 125private: 126 // shared flags that are sent to clients (max 8) 127 static const int DATA_SHARED_FLAGS_ID = 0; 128 static const int FLAG_ONFIRE = 0; 129 static const int FLAG_SNEAKING = 1; 130 //static const int FLAG_ = 2; 131 static const int FLAG_SPRINTING = 3; 132 static const int FLAG_USING_ITEM = 4; 133 static const int FLAG_INVISIBLE = 5; 134 static const int FLAG_IDLEANIM = 6; 135 static const int FLAG_EFFECT_WEAKENED = 7; //4J ADDED, needed for cure villager tooltip. 136 static const int DATA_AIR_SUPPLY_ID = 1; 137 138private: 139 double xRideRotA, yRideRotA; 140 141public: 142 bool inChunk; 143 int xChunk, yChunk, zChunk; 144 int xp, yp, zp, xRotp, yRotp; 145 bool noCulling; 146 bool hasImpulse; 147 int changingDimensionDelay; 148 149protected: 150 bool isInsidePortal; 151 int portalTime; 152 153public: 154 int dimension; 155 156protected: 157 int portalEntranceDir; 158 159private: 160 bool invulnerable; 161 wstring uuid; 162 163protected: 164 // 4J Added so that client side simulations on the host are not affected by zero-lag 165 bool m_ignoreVerticalCollisions; 166 167 bool m_ignorePortal; 168 169public: 170 Entity(Level *level, bool useSmallId = true); // 4J - added useSmallId parameter 171 virtual ~Entity(); 172 173protected: 174 // 4J - added for common ctor code 175 void _init(bool useSmallId, Level *level); 176 177protected: 178 virtual void defineSynchedData() = 0; 179 180public: 181 shared_ptr<SynchedEntityData> getEntityData(); 182 183 /* 184 public bool equals(Object obj) { 185 if (obj instanceof Entity) { 186 return ((Entity) obj).entityId == entityId; 187 } 188 return false; 189 } 190 191 public int hashCode() { 192 return entityId; 193 } 194 */ 195 196protected: 197 virtual void resetPos(); 198 199public: 200 virtual void remove(); 201 202protected: 203 virtual void setSize(float w, float h); 204 void setPos(EntityPos *pos); 205 void setRot(float yRot, float xRot); 206 207public: 208 void setPos(double x, double y, double z); 209 void turn(float xo, float yo); 210 void interpolateTurn(float xo, float yo); 211 virtual void tick(); 212 virtual void baseTick(); 213 virtual int getPortalWaitTime(); 214 215protected: 216 void lavaHurt(); 217 218public: 219 virtual void setOnFire(int numberOfSeconds); 220 virtual void clearFire(); 221 222protected: 223 virtual void outOfWorld(); 224 225public: 226 bool isFree(float xa, float ya, float za, float grow); 227 bool isFree(double xa, double ya, double za); 228 virtual void move(double xa, double ya, double za, bool noEntityCubes=false); // 4J - added noEntityCubes parameter 229 230protected: 231 virtual void checkInsideTiles(); 232 virtual void playStepSound(int xt, int yt, int zt, int t); 233 234public: 235 virtual void playSound(int iSound, float volume, float pitch); 236 237protected: 238 virtual bool makeStepSound(); 239 virtual void checkFallDamage(double ya, bool onGround); 240 241public: 242 virtual AABB *getCollideBox(); 243 244protected: 245 virtual void burn(int dmg); 246 247public: 248 bool isFireImmune(); 249 250protected: 251 virtual void causeFallDamage(float distance); 252 253public: 254 bool isInWaterOrRain(); 255 virtual bool isInWater(); 256 virtual bool updateInWaterState(); 257 bool isUnderLiquid(Material *material); 258 virtual float getHeadHeight(); 259 bool isInLava(); 260 void moveRelative(float xa, float za, float speed); 261 virtual int getLightColor(float a); // 4J - change brought forward from 1.8.2 262 virtual float getBrightness(float a); 263 virtual void setLevel(Level *level); 264 void absMoveTo(double x, double y, double z, float yRot, float xRot); 265 void moveTo(double x, double y, double z, float yRot, float xRot); 266 float distanceTo(shared_ptr<Entity> e); 267 double distanceToSqr(double x2, double y2, double z2); 268 double distanceTo(double x2, double y2, double z2); 269 double distanceToSqr(shared_ptr<Entity> e); 270 virtual void playerTouch(shared_ptr<Player> player); 271 virtual void push(shared_ptr<Entity> e); 272 virtual void push(double xa, double ya, double za); 273 274protected: 275 void markHurt(); 276 277public: 278 // 4J Added damageSource param to enable telemetry on player deaths 279 virtual bool hurt(DamageSource *source, float damage); 280 bool intersects(double x0, double y0, double z0, double x1, double y1, double z1); 281 virtual bool isPickable(); 282 virtual bool isPushable(); 283 virtual bool isShootable(); 284 virtual void awardKillScore(shared_ptr<Entity> victim, int score); 285 virtual bool shouldRender(Vec3 *c); 286 virtual bool shouldRenderAtSqrDistance(double distance); 287 virtual bool isCreativeModeAllowed(); 288 bool saveAsMount(CompoundTag *entityTag); 289 bool save(CompoundTag *entityTag); 290 void saveWithoutId(CompoundTag *entityTag); 291 virtual void load(CompoundTag *tag); 292 293protected: 294 virtual bool repositionEntityAfterLoad(); 295 const wstring getEncodeId(); 296 297public: 298 virtual void readAdditionalSaveData(CompoundTag *tag) = 0; 299 virtual void addAdditonalSaveData(CompoundTag *tag) = 0; 300 /** 301 * Called after load() has finished and the entity has been added to the 302 * world 303 */ 304 virtual void onLoadedFromSave(); 305 306protected: 307 template<typename ...Args> 308 ListTag<DoubleTag> *newDoubleList(unsigned int, double firstValue, Args... args); 309 ListTag<FloatTag> *newFloatList(unsigned int number, float firstValue, float secondValue); 310 311public: 312 virtual float getShadowHeightOffs(); 313 shared_ptr<ItemEntity> spawnAtLocation(int resource, int count); 314 shared_ptr<ItemEntity> spawnAtLocation(int resource, int count, float yOffs); 315 shared_ptr<ItemEntity> spawnAtLocation(shared_ptr<ItemInstance> itemInstance, float yOffs); 316 virtual bool isAlive(); 317 virtual bool isInWall(); 318 virtual bool interact(shared_ptr<Player> player); 319 virtual AABB *getCollideAgainstBox(shared_ptr<Entity> entity); 320 321 virtual void rideTick(); 322 virtual void positionRider(); 323 virtual double getRidingHeight(); 324 virtual double getRideHeight(); 325 virtual void ride(shared_ptr<Entity> e); 326 virtual void lerpTo(double x, double y, double z, float yRot, float xRot, int steps); 327 virtual float getPickRadius(); 328 virtual Vec3 *getLookAngle(); 329 virtual void handleInsidePortal(); 330 virtual int getDimensionChangingDelay(); 331 virtual void lerpMotion(double xd, double yd, double zd); 332 virtual void handleEntityEvent(byte eventId); 333 virtual void animateHurt(); 334 virtual ItemInstanceArray getEquipmentSlots(); // ItemInstance[] 335 virtual void setEquippedSlot(int slot, shared_ptr<ItemInstance> item); // 4J Stu - Brought forward change from 1.3 to fix #64688 - Customer Encountered: TU7: Content: Art: Aura of enchanted item is not displayed for other players in online game 336 virtual bool isOnFire(); 337 virtual bool isRiding(); 338 virtual bool isSneaking(); 339 virtual void setSneaking(bool value); 340 virtual bool isIdle(); 341 virtual void setIsIdle(bool value); 342 virtual bool isSprinting(); 343 virtual void setSprinting(bool value); 344 virtual bool isInvisible(); 345 virtual bool isInvisibleTo(shared_ptr<Player> plr); 346 virtual void setInvisible(bool value); 347 virtual bool isUsingItemFlag(); 348 virtual void setUsingItemFlag(bool value); 349 350 // 4J-ADDED, we need to see if this is weakened 351 // on the client for the cure villager tooltip. 352 bool isWeakened(); 353 void setWeakened(bool value); 354 355protected: 356 bool getSharedFlag(int flag); 357 void setSharedFlag(int flag, bool value); 358 359public: 360 // 4J Stu - Brought forward from 1.2.3 to fix 38654 - Gameplay: Player will take damage when air bubbles are present if resuming game from load/autosave underwater. 361 int getAirSupply(); 362 void setAirSupply(int supply); 363 364 virtual void thunderHit(const LightningBolt *lightningBolt); 365 virtual void killed(shared_ptr<LivingEntity> mob); 366 367protected: 368 bool checkInTile(double x, double y, double z); 369 370public: 371 virtual void makeStuckInWeb(); 372 373 virtual wstring getAName(); 374 375 // 4J - added to manage allocation of small ids 376private: 377 // Things also added here to be able to manage the concept of a number of extra "wandering" entities - normally path finding entities aren't allowed to 378 // randomly wander about once they are a certain distance away from any player, but we want to be able to (in a controlled fashion) allow some to be able 379 // to move so that we can determine whether they have been enclosed in some kind of farm, and so be able to better determine what shouldn't or shouldn't be despawned. 380 static const int EXTRA_WANDER_MAX = 3; // Number of entities that can simultaneously wander (in addition to the ones that would be wandering in java) 381 static const int EXTRA_WANDER_TICKS = 20 * 30; // Number of ticks each extra entity will be allowed to wander for. This should be enough for it to realistically be able to walk further than the biggest enclosure we want to consider 382 383 int getSmallId(); 384 void freeSmallId(int index); 385 static unsigned int entityIdUsedFlags[2048/32]; 386 static unsigned int entityIdWanderFlags[2048/32]; 387 static unsigned int entityIdRemovingFlags[2048/32]; 388 static int extraWanderIds[EXTRA_WANDER_MAX]; 389 static int extraWanderCount; 390 static int extraWanderTicks; 391 static DWORD tlsIdx; 392public: 393 static void tickExtraWandering(); 394 static void countFlagsForPIX(); 395 void resetSmallId(); 396 static void useSmallIds(); 397 void considerForExtraWandering(bool enable); 398 bool isExtraWanderingEnabled(); 399 int getWanderingQuadrant(); 400 401 virtual vector<shared_ptr<Entity> > *getSubEntities(); 402 virtual bool is(shared_ptr<Entity> other); 403 virtual float getYHeadRot(); 404 virtual void setYHeadRot(float yHeadRot); 405 virtual bool isAttackable(); 406 virtual bool skipAttackInteraction(shared_ptr<Entity> source); 407 virtual bool isInvulnerable(); 408 virtual void copyPosition(shared_ptr<Entity> target); 409 virtual void restoreFrom(shared_ptr<Entity> oldEntity, bool teleporting); 410 virtual void changeDimension(int i); 411 virtual float getTileExplosionResistance(Explosion *explosion, Level *level, int x, int y, int z, Tile *tile); 412 virtual bool shouldTileExplode(Explosion *explosion, Level *level, int x, int y, int z, int id, float power); 413 virtual int getMaxFallDistance(); 414 virtual int getPortalEntranceDir(); 415 virtual bool isIgnoringTileTriggers(); 416 virtual bool displayFireAnimation(); 417 virtual void setUUID(const wstring &UUID); 418 virtual wstring getUUID(); 419 virtual bool isPushedByWater(); 420 virtual wstring getDisplayName(); 421 virtual wstring getNetworkName(); // 4J: Added 422 423private: 424 unsigned int m_uiAnimOverrideBitmask; 425public: 426 void setAnimOverrideBitmask(unsigned int uiBitmask); 427 unsigned int getAnimOverrideBitmask(); 428 429 // 4J added 430 virtual bool isDespawnProtected() { return false; } 431 virtual void setDespawnProtected() {} 432 virtual bool couldWander() { return false; } 433 virtual bool canCreateParticles() { return true; } 434};