2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
// Minecart.h
|
|
|
|
|
|
|
|
// Declares the cMinecart class representing a minecart in the world
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Entity.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cMinecart :
|
|
|
|
public cEntity
|
|
|
|
{
|
|
|
|
typedef cEntity super;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CLASS_PROTODEF(cMinecart);
|
|
|
|
|
|
|
|
enum ePayload
|
|
|
|
{
|
|
|
|
mpNone, // Empty minecart, ridable by player or mobs
|
|
|
|
mpChest, // Minecart-with-chest, can store a grid of 3*8 items
|
|
|
|
mpFurnace, // Minecart-with-furnace, can be powered
|
2013-08-16 06:23:24 -04:00
|
|
|
mpTNT, // Minecart-with-TNT, can be blown up with activator rail
|
|
|
|
mpHopper, // Minecart-with-hopper, can be hopper
|
|
|
|
// TODO: Spawner minecarts, (and possibly any block in a minecart with NBT editing)
|
2013-07-29 07:13:03 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
// cEntity overrides:
|
|
|
|
virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
|
2013-09-02 07:01:49 -04:00
|
|
|
virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override;
|
|
|
|
virtual void DoTakeDamage(TakeDamageInfo & TDI) override;
|
2014-01-13 17:37:09 -05:00
|
|
|
virtual void Destroyed() override;
|
2013-07-29 07:13:03 -04:00
|
|
|
|
2013-10-09 16:02:59 -04:00
|
|
|
int LastDamage(void) const { return m_LastDamage; }
|
2013-07-29 07:13:03 -04:00
|
|
|
ePayload GetPayload(void) const { return m_Payload; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
ePayload m_Payload;
|
2014-01-12 08:28:37 -05:00
|
|
|
int m_LastDamage;
|
2014-01-13 17:37:09 -05:00
|
|
|
Vector3i m_DetectorRailPosition;
|
|
|
|
bool m_bIsOnDetectorRail;
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
cMinecart(ePayload a_Payload, double a_X, double a_Y, double a_Z);
|
2014-01-13 17:37:09 -05:00
|
|
|
|
|
|
|
/** Handles physics on normal rails
|
|
|
|
For each tick, slow down on flat rails, speed up or slow down on ascending/descending rails (depending on direction), and turn on curved rails
|
|
|
|
*/
|
|
|
|
void HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt);
|
|
|
|
|
|
|
|
/** Handles powered rail physics
|
|
|
|
Each tick, speed up or slow down cart, depending on metadata of rail (powered or not)
|
|
|
|
*/
|
2014-01-12 08:28:37 -05:00
|
|
|
void HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta);
|
2014-01-13 17:37:09 -05:00
|
|
|
|
|
|
|
/** Handles detector rail activation
|
|
|
|
Activates detector rails when a minecart is on them. Calls HandleRailPhysics() for physics simulations
|
|
|
|
*/
|
|
|
|
void HandleDetectorRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt);
|
|
|
|
|
2014-01-19 14:31:17 -05:00
|
|
|
/** Handles activator rails - placeholder for future implementation */
|
|
|
|
void HandleActivatorRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt);
|
|
|
|
|
2014-01-18 15:58:26 -05:00
|
|
|
/** Snaps a mincecart to a rail's axis, resetting its speed
|
|
|
|
For curved rails, it changes the cart's direction as well as snapping it to axis */
|
2014-01-12 08:28:37 -05:00
|
|
|
void SnapToRail(NIBBLETYPE a_RailMeta);
|
2014-01-18 15:58:26 -05:00
|
|
|
/** Tests if a solid block is in front of a cart, and stops the cart (and returns true) if so; returns false if no obstruction */
|
2014-01-13 17:37:09 -05:00
|
|
|
bool TestBlockCollision(NIBBLETYPE a_RailMeta);
|
2014-01-18 15:58:26 -05:00
|
|
|
/** Tests if this mincecart's bounding box is intersecting another entity's bounding box (collision) and pushes mincecart away */
|
|
|
|
bool TestEntityCollision(NIBBLETYPE a_RailMeta);
|
2013-10-08 14:20:49 -04:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-01-12 12:04:41 -05:00
|
|
|
class cRideableMinecart :
|
2013-07-29 07:13:03 -04:00
|
|
|
public cMinecart
|
|
|
|
{
|
|
|
|
typedef cMinecart super;
|
|
|
|
|
|
|
|
public:
|
2014-01-12 12:04:41 -05:00
|
|
|
CLASS_PROTODEF(cRideableMinecart);
|
2013-07-29 07:13:03 -04:00
|
|
|
|
2014-01-12 12:04:41 -05:00
|
|
|
cRideableMinecart(double a_X, double a_Y, double a_Z, const cItem & a_Content, int a_Height);
|
2013-07-29 07:13:03 -04:00
|
|
|
|
2014-01-16 10:54:22 -05:00
|
|
|
const cItem & GetContent(void) const {return m_Content;}
|
2014-01-12 09:27:50 -05:00
|
|
|
int GetBlockHeight(void) const {return m_Height;}
|
2013-07-29 07:13:03 -04:00
|
|
|
// cEntity overrides:
|
|
|
|
virtual void OnRightClicked(cPlayer & a_Player) override;
|
2014-01-12 09:27:50 -05:00
|
|
|
protected:
|
|
|
|
|
2014-01-12 12:15:54 -05:00
|
|
|
cItem m_Content;
|
2014-01-12 09:27:50 -05:00
|
|
|
int m_Height;
|
2013-07-29 07:13:03 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cMinecartWithChest :
|
|
|
|
public cMinecart
|
|
|
|
{
|
|
|
|
typedef cMinecart super;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CLASS_PROTODEF(cMinecartWithChest);
|
|
|
|
|
|
|
|
/// Number of item slots in the chest
|
|
|
|
static const int NumSlots = 9 * 3;
|
|
|
|
|
|
|
|
cMinecartWithChest(double a_X, double a_Y, double a_Z);
|
|
|
|
|
|
|
|
const cItem & GetSlot(int a_Idx) const { return m_Items[a_Idx]; }
|
|
|
|
cItem & GetSlot(int a_Idx) { return m_Items[a_Idx]; }
|
|
|
|
|
2014-03-08 11:33:38 -05:00
|
|
|
void SetSlot(size_t a_Idx, const cItem & a_Item);
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
/// The chest contents:
|
|
|
|
cItem m_Items[NumSlots];
|
|
|
|
|
|
|
|
// cEntity overrides:
|
|
|
|
virtual void OnRightClicked(cPlayer & a_Player) override;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cMinecartWithFurnace :
|
|
|
|
public cMinecart
|
|
|
|
{
|
|
|
|
typedef cMinecart super;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CLASS_PROTODEF(cMinecartWithFurnace);
|
|
|
|
|
|
|
|
cMinecartWithFurnace(double a_X, double a_Y, double a_Z);
|
|
|
|
|
|
|
|
// cEntity overrides:
|
|
|
|
virtual void OnRightClicked(cPlayer & a_Player) override;
|
2014-01-15 08:03:09 -05:00
|
|
|
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
|
2014-01-15 08:38:54 -05:00
|
|
|
|
|
|
|
// Set functions.
|
|
|
|
void SetIsFueled(bool a_IsFueled, int a_FueledTimeLeft = -1) {m_IsFueled = a_IsFueled; m_FueledTimeLeft = a_FueledTimeLeft;}
|
|
|
|
|
|
|
|
// Get functions.
|
|
|
|
int GetFueledTimeLeft(void) const {return m_FueledTimeLeft; }
|
|
|
|
bool IsFueled (void) const {return m_IsFueled;}
|
2013-10-08 14:20:49 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2014-01-15 08:38:54 -05:00
|
|
|
int m_FueledTimeLeft;
|
2013-10-08 14:20:49 -04:00
|
|
|
bool m_IsFueled;
|
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-16 06:23:24 -04:00
|
|
|
|
|
|
|
class cMinecartWithTNT :
|
|
|
|
public cMinecart
|
|
|
|
{
|
|
|
|
typedef cMinecart super;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CLASS_PROTODEF(cMinecartWithTNT);
|
|
|
|
|
|
|
|
cMinecartWithTNT(double a_X, double a_Y, double a_Z);
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cMinecartWithHopper :
|
|
|
|
public cMinecart
|
|
|
|
{
|
|
|
|
typedef cMinecart super;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CLASS_PROTODEF(cMinecartWithHopper);
|
|
|
|
|
|
|
|
cMinecartWithHopper(double a_X, double a_Y, double a_Z);
|
2014-03-08 11:33:38 -05:00
|
|
|
} ;
|