12 #include "../BlockInfo.h"
13 #include "../ClientHandle.h"
16 #include "../BoundingBox.h"
17 #include "../UI/MinecartWithChestWindow.h"
21 #define MAX_SPEED_NEGATIVE -MAX_SPEED
22 #define DIR_NORTH_SOUTH 270
23 #define DIR_EAST_WEST 180
24 #define DIR_NORTH_WEST 315
25 #define DIR_NORTH_EAST 225
26 #define DIR_SOUTH_WEST 135
27 #define DIR_SOUTH_EAST 45
133 Super(etMinecart, a_Pos, 0.98f, 0.7f),
134 m_Payload(a_Payload),
136 m_DetectorRailPosition(0, 0, 0),
137 m_bIsOnDetectorRail(false)
178 if (chunk ==
nullptr)
197 chunk->GetBlockTypeMeta(relPos, InsideType, InsideMeta);
202 chunk->GetBlockTypeMeta(relPos.addedY(1), InsideType, InsideMeta);
211 chunk->GetBlockTypeMeta(relPos.addedY(-1), InsideType, InsideMeta);
243 default:
VERIFY(!
"Unhandled rail type despite checking if block was rail!");
break;
285 if (EntCol || BlckCol)
315 if (EntCol || BlckCol)
341 if (EntCol || BlckCol)
368 if (EntCol || BlckCol)
395 if (EntCol || BlckCol)
420 if (EntCol || BlckCol)
446 if (EntCol || BlckCol)
463 if (EntCol || BlckCol)
478 if (EntCol || BlckCol)
493 if (EntCol || BlckCol)
511 const bool IsRailPowered = ((a_RailMeta & 0x8) == 0x8);
512 const double Acceleration = IsRailPowered ? 1.0 : -2.0;
514 NIBBLETYPE PoweredRailMeta = a_RailMeta & 0x7;
515 switch (PoweredRailMeta)
525 if (EntCol || BlckCol)
542 else if (IsRailPowered)
547 if (IsBlockZM && !IsBlockZP)
551 else if (!IsBlockZM && IsBlockZP)
566 if (EntCol || BlckCol)
583 else if (IsRailPowered)
588 if (IsBlockXM && !IsBlockXP)
592 else if (!IsBlockXM && IsBlockXP)
667 default:
ASSERT(!
"Unhandled powered rail metadata!");
break;
854 static_cast<Vector3d>(BlockPosition),
872 #pragma clang diagnostic push
873 #pragma clang diagnostic ignored "-Wfloat-equal"
876 if ((SpeedX == 0) && (SpeedZ == 0))
882 #pragma clang diagnostic pop
885 auto StopTheCart =
true;
1016 StopOffset =
Vector3d(0.5, 0, 0.5);
1033 StopOffset =
Vector3d(0.5, 0, 0.5);
1055 #pragma clang diagnostic push
1056 #pragma clang diagnostic ignored "-Wfloat-equal"
1059 if (StopOffset.x != 0)
1063 if (StopOffset.z != 0)
1069 #pragma clang diagnostic pop
1162 if ((-
GetSpeedX() * 0.4 / sqrt(2.0)) < 0.01)
1175 else if ((
GetSpeedX() * 0.4 / sqrt(2.0)) < 0.01)
1307 Vector3d ToAddSpeed = LookVector * (a_Forward * 0.4) ;
1318 double CurSpeed =
GetSpeed().
Dot(a_ForwardDirection);
1319 double NewSpeed = CurSpeed + a_Acceleration;
1327 auto Acceleration = a_ForwardDirection * (NewSpeed - CurSpeed);
1340 Super(mpNone, a_Pos),
1341 m_Content(a_Content),
1342 m_ContentHeight(a_ContentHeight)
1394 Super(mpChest, a_Pos),
1396 m_Contents(ContentsWidth, ContentsHeight)
1418 if (Window !=
nullptr)
1420 Window->OwnerDestroyed();
1434 if (Window ==
nullptr)
1441 if (Window !=
nullptr)
1467 Super(mpFurnace, a_Pos),
1468 m_FueledTimeLeft(-1),
1607 Super(mpHopper, a_Pos)
bool IsBlockRail(BLOCKTYPE a_BlockType)
@ E_META_RAIL_CURVED_ZP_XP
@ E_META_RAIL_CURVED_ZP_XM
@ E_META_RAIL_CURVED_ZM_XM
@ E_META_RAIL_CURVED_ZM_XP
@ E_ITEM_MINECART_WITH_TNT
@ E_ITEM_MINECART_WITH_HOPPER
@ E_ITEM_FURNACE_MINECART
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
unsigned char BLOCKTYPE
The datatype used by blockdata.
#define MAX_SPEED_NEGATIVE
Vector3< double > Vector3d
unsigned char Distance(const BlockState Block)
static bool IsSolid(BLOCKTYPE Block)
Is this block solid (player cannot walk through)?
Represents two sets of coords, minimum and maximum for each direction.
bool DoesIntersect(const cBoundingBox &a_Other)
Returns true if the two bounding boxes intersect.
cChunk * GetRelNeighborChunkAdjustCoords(Vector3i &a_RelPos) const
Returns the chunk into which the relatively-specified block belongs.
static void BlockToChunk(int a_X, int a_Z, int &a_ChunkX, int &a_ChunkZ)
Converts absolute block coords to chunk coords:
static void AbsoluteToRelative(int &a_X, int &a_Y, int &a_Z, int &a_ChunkX, int &a_ChunkZ)
Converts absolute block coords into relative (chunk + block) coords:
void SendSpawnEntity(const cEntity &a_Entity)
void SendEntityMetadata(const cEntity &a_Entity)
const Vector3d & GetSpeed(void) const
Exported in ManualBindings.
void AddPosY(double a_AddPosY)
void AddSpeedX(double a_AddSpeedX)
bool IsPlayer(void) const
cBoundingBox GetBoundingBox() const
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk)
cEntity * m_Attachee
The entity which is attached to this entity (rider), nullptr if none.
void SetSpeedX(double a_SpeedX)
Sets the speed in the X axis, leaving the other speed components intact.
void Detach(void)
Detaches from the currently attached entity, if any.
void AddSpeed(double a_AddSpeedX, double a_AddSpeedY, double a_AddSpeedZ)
double GetSpeedZ(void) const
void SetYaw(double a_Yaw)
float GetMaxHealth(void) const
void SetHealth(float a_Health)
Sets the health of this entity; doesn't broadcast any hurt animation.
static const UInt32 INVALID_ID
Special ID that is considered an "invalid value", signifying no entity.
void SetSpeedY(double a_SpeedY)
Sets the speed in the Y axis, leaving the other speed components intact.
bool IsTicking(void) const
Returns true if the entity is valid and ticking.
void SetSpeedZ(double a_SpeedZ)
Sets the speed in the Z axis, leaving the other speed components intact.
void SetGravity(float a_Gravity)
void SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ)
Sets the speed of the entity, measured in m / sec.
double GetPosX(void) const
void SetPosY(double a_PosY)
float GetWidth(void) const
double GetPosZ(void) const
bool IsMinecart(void) const
UInt32 GetUniqueID(void) const
void Destroy()
Destroys the entity, schedules it for memory freeing and broadcasts the DestroyEntity packet.
void SetInvulnerableTicks(int a_InvulnerableTicks)
Set the invulnerable ticks from the entity.
double GetPosY(void) const
Vector3d m_Speed
Measured in meters / second (m / s)
virtual void HandlePhysics(std::chrono::milliseconds a_Dt, cChunk &a_Chunk)
Handles the physics of the entity - updates position based on speed, updates speed based on environme...
void AddPosition(double a_AddPosX, double a_AddPosY, double a_AddPosZ)
void AddSpeedZ(double a_AddSpeedZ)
void SetMass(double a_Mass)
float GetHeight(void) const
void SetAirDrag(float a_AirDrag)
virtual void KilledBy(TakeDamageInfo &a_TDI)
Called when the health drops below zero.
void SetPosZ(double a_PosZ)
virtual bool DoTakeDamage(TakeDamageInfo &a_TDI)
Makes this entity take damage specified in the a_TDI.
virtual void OnRemoveFromWorld(cWorld &a_World)
Called when the entity is removed from a world.
void SetPosX(double a_PosX)
void SetMaxHealth(float a_MaxHealth)
Sets the maximum value for the health.
virtual void OnRightClicked(cPlayer &a_Player)
Called when the specified player right-clicks this entity.
const Vector3d & GetPosition(void) const
Exported in ManualBindings.
Vector3d GetLookVector(void) const
void AttachTo(cEntity &a_AttachTo)
Attaches to the specified entity; detaches from any previous one first.
virtual void BroadcastMovementUpdate(const cClientHandle *a_Exclude=nullptr)
Updates clients of changes in the entity.
double GetSpeedX(void) const
bool operator()(cEntity &a_Entity)
cMinecartAttachCallback(cMinecart &a_Minecart, cEntity *a_Attachee)
UInt32 m_AttacheeUniqueID
bool operator()(cEntity &a_Entity)
Vector3d GetCollidedEntityPosition(void) const
cMinecartCollisionCallback(Vector3d a_Pos, double a_Height, double a_Width, UInt32 a_UniqueID, UInt32 a_AttacheeUniqueID)
bool FoundIntersection(void) const
Vector3d m_CollidedEntityPos
bool IsSolidBlockAtOffset(int a_XOffset, int a_YOffset, int a_ZOffset)
Tests if a solid block is at a specific offset of the minecart position.
void SnapToRail(NIBBLETYPE a_RailMeta)
Snaps a mincecart to a rail's axis, resetting its speed For curved rails, it changes the cart's direc...
virtual void HandleActivatorRailPhysics(NIBBLETYPE a_RailMeta, std::chrono::milliseconds a_Dt)
Handles activator rails.
cMinecart(ePayload a_Payload, Vector3d a_Pos)
bool TestBlockCollision(NIBBLETYPE a_RailMeta)
Tests if a solid block is in front of a cart, and stops the cart (and returns true) if so; returns fa...
void ApplyAcceleration(Vector3d a_ForwardDirection, double a_Acceleration)
Applies an acceleration to the minecart parallel to a_ForwardDirection but without allowing backward ...
Vector3i m_DetectorRailPosition
void HandleDetectorRailPhysics(NIBBLETYPE a_RailMeta, std::chrono::milliseconds a_Dt)
Handles detector rail activation Activates detector rails when a minecart is on them.
bool IsBlockCollisionAtOffset(Vector3i a_Offset)
virtual bool DoTakeDamage(TakeDamageInfo &TDI) override
Makes this entity take damage specified in the a_TDI.
ePayload
Minecart payload, values correspond to packet subtype.
bool TestEntityCollision(NIBBLETYPE a_RailMeta)
Tests if this mincecart's bounding box is intersecting another entity's bounding box (collision) and ...
bool IsSolidBlockAtPosition(Vector3i a_Offset)
Tests if there is a block at the specified position which is impassable to minecarts.
virtual void HandleSpeedFromAttachee(float a_Forward, float a_Sideways) override
virtual void SpawnOn(cClientHandle &a_ClientHandle) override
Descendants override this function to send a command to the specified client to spawn the entity on t...
virtual void KilledBy(TakeDamageInfo &a_TDI) override
Called when the health drops below zero.
void HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta)
Handles powered rail physics Each tick, speed up or slow down cart, depending on metadata of rail (po...
virtual void HandlePhysics(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
Handles the physics of the entity - updates position based on speed, updates speed based on environme...
void HandleRailPhysics(NIBBLETYPE a_RailMeta, std::chrono::milliseconds a_Dt)
Handles physics on normal rails For each tick, slow down on flat rails, speed up or slow down on asce...
virtual void OnRemoveFromWorld(cWorld &a_World) override
Called when the entity is removed from a world.
virtual void GetDrops(cItems &a_Drops, cEntity *a_Killer=nullptr) override
Returns the list of drops for this pawn when it is killed.
virtual void OnRightClicked(cPlayer &a_Player) override
Called when the specified player right-clicks this entity.
cRideableMinecart(Vector3d a_Pos, const cItem &a_Content, int a_ContentHeight)
virtual void GetDrops(cItems &a_Drops, cEntity *a_Killer=nullptr) override
Returns the list of drops for this pawn when it is killed.
virtual void OnRemoveFromWorld(cWorld &a_World) override
Called when the entity is removed from a world.
virtual void OnRightClicked(cPlayer &a_Player) override
Called when the specified player right-clicks this entity.
cMinecartWithChest(Vector3d a_Pos)
virtual void OnRightClicked(cPlayer &a_Player) override
Called when the specified player right-clicks this entity.
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
virtual void GetDrops(cItems &a_Drops, cEntity *a_Killer=nullptr) override
Returns the list of drops for this pawn when it is killed.
cMinecartWithFurnace(Vector3d a_Pos)
void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
void HandleActivatorRailPhysics(NIBBLETYPE a_RailMeta, std::chrono::milliseconds a_Dt) override
Handles activator rails.
cMinecartWithTNT(Vector3d a_Pos)
virtual void GetDrops(cItems &a_Drops, cEntity *a_Killer=nullptr) override
Returns the list of drops for this pawn when it is killed.
cMinecartWithHopper(Vector3d a_Pos)
virtual void GetDrops(cItems &a_Drops, cEntity *a_Killer=nullptr) override
Returns the list of drops for this pawn when it is killed.
const cItem & GetEquippedItem(void) const
void OpenWindow(cWindow &a_Window)
Opens the specified window; closes the current one first using CloseWindow()
bool IsGameModeCreative(void) const
Returns true if the player is in Creative mode, either explicitly, or by inheriting from current worl...
cInventory & GetInventory(void)
bool IsGameModeSpectator(void) const
Returns true if the player is in Spectator mode, either explicitly, or by inheriting from current wor...
cWindow * GetWindow(void)
bool RemoveOneEquippedItem(void)
Removes one item out of the currently equipped item stack, returns true if successful,...
This class bridges a vector of cItem for safe access via Lua.
void AddListener(cListener &a_Listener)
Adds a callback that gets called whenever a slot changes.
void CopyToItems(cItems &a_Items) const
Copies the contents into a cItems object; preserves the original a_Items contents.
cWindow * GetWindow(void) const
void OpenWindow(cWindow *a_Window)
Window owner that is associated with an entity (chest minecart etc.)
T Dot(const Vector3< T > &a_Rhs) const
Vector3< int > Floor(void) const
Returns a new Vector3i with coords set to std::floor() of this vector's coords.
void Clamp(T a_Min, T a_Max)
Clamps each coord into the specified range.
virtual void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, bool a_CanCauseFire, eExplosionSource a_Source, void *a_SourceData) override
Does an explosion with the specified strength at the specified coordinates.
virtual void BroadcastEntityMetadata(const cEntity &a_Entity, const cClientHandle *a_Exclude=nullptr) override
virtual void BroadcastEntityAnimation(const cEntity &a_Entity, EntityAnimation a_Animation, const cClientHandle *a_Exclude=nullptr) override
BLOCKTYPE GetBlock(Vector3i a_BlockPos) const
Returns the block type at the specified position.
virtual bool ForEachEntityInBox(const cBoundingBox &a_Box, cEntityCallback a_Callback) override
Calls the callback for each entity that has a nonempty intersection with the specified boundingbox.
NIBBLETYPE GetBlockMeta(Vector3i a_BlockPos) const
Returns the block meta at the specified position.
virtual void BroadcastSoundEffect(const AString &a_SoundName, Vector3d a_Position, float a_Volume, float a_Pitch, const cClientHandle *a_Exclude=nullptr) override
void SetBlockMeta(Vector3i a_BlockPos, NIBBLETYPE a_MetaData)
Sets the meta for the specified block, while keeping the blocktype.
bool ForEachEntityInChunk(int a_ChunkX, int a_ChunkZ, cEntityCallback a_Callback)
Calls the callback for each entity in the specified chunk; returns true if all entities processed,...
void SetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Sets the block at the specified coords to the specified value.