Merge branch 'boats' of git://github.com/tigerw/MCServer.
This commit is contained in:
commit
5945166a98
@ -1115,6 +1115,14 @@
|
|||||||
<Filter
|
<Filter
|
||||||
Name="Entities"
|
Name="Entities"
|
||||||
>
|
>
|
||||||
|
<File
|
||||||
|
RelativePath="..\source\Entities\Boat.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\source\Entities\Boat.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\source\Entities\Entity.cpp"
|
RelativePath="..\source\Entities\Entity.cpp"
|
||||||
>
|
>
|
||||||
@ -2243,6 +2251,10 @@
|
|||||||
RelativePath="..\source\items\ItemBed.h"
|
RelativePath="..\source\items\ItemBed.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\source\Items\ItemBoat.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\source\Items\ItemBow.h"
|
RelativePath="..\source\Items\ItemBow.h"
|
||||||
>
|
>
|
||||||
|
@ -125,7 +125,7 @@ public:
|
|||||||
void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock);
|
void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock);
|
||||||
void SendSpawnMob (const cMonster & a_Mob);
|
void SendSpawnMob (const cMonster & a_Mob);
|
||||||
void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch);
|
void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch);
|
||||||
void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType);
|
void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType = 0);
|
||||||
void SendTabCompletionResults(const AStringVector & a_Results);
|
void SendTabCompletionResults(const AStringVector & a_Results);
|
||||||
void SendTeleportEntity (const cEntity & a_Entity);
|
void SendTeleportEntity (const cEntity & a_Entity);
|
||||||
void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ);
|
void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ);
|
||||||
|
87
source/Entities/Boat.cpp
Normal file
87
source/Entities/Boat.cpp
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
|
||||||
|
// Boat.cpp
|
||||||
|
|
||||||
|
// Implements the cBoat class representing a boat in the world
|
||||||
|
|
||||||
|
#include "Globals.h"
|
||||||
|
#include "Boat.h"
|
||||||
|
#include "../World.h"
|
||||||
|
#include "../ClientHandle.h"
|
||||||
|
#include "Player.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
cBoat::cBoat(double a_X, double a_Y, double a_Z) :
|
||||||
|
super(etBoat, a_X, a_Y, a_Z, 0.98, 0.7)
|
||||||
|
{
|
||||||
|
SetMass(20.f);
|
||||||
|
SetMaxHealth(6);
|
||||||
|
SetHealth(6);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cBoat::SpawnOn(cClientHandle & a_ClientHandle)
|
||||||
|
{
|
||||||
|
a_ClientHandle.SendSpawnVehicle(*this, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cBoat::DoTakeDamage(TakeDamageInfo & TDI)
|
||||||
|
{
|
||||||
|
super::DoTakeDamage(TDI);
|
||||||
|
|
||||||
|
if (GetHealth() == 0)
|
||||||
|
{
|
||||||
|
Destroy(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cBoat::OnRightClicked(cPlayer & a_Player)
|
||||||
|
{
|
||||||
|
if (m_Attachee != NULL)
|
||||||
|
{
|
||||||
|
if (m_Attachee->GetUniqueID() == a_Player.GetUniqueID())
|
||||||
|
{
|
||||||
|
// This player is already sitting in, they want out.
|
||||||
|
a_Player.Detach();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_Attachee->IsPlayer())
|
||||||
|
{
|
||||||
|
// Another player is already sitting in here, cannot attach
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detach whatever is sitting in this boat now:
|
||||||
|
m_Attachee->Detach();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attach the player to this boat
|
||||||
|
a_Player.AttachTo(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cBoat::HandlePhysics(float a_Dt, cChunk & a_Chunk)
|
||||||
|
{
|
||||||
|
super::HandlePhysics(a_Dt, a_Chunk);
|
||||||
|
BroadcastMovementUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
38
source/Entities/Boat.h
Normal file
38
source/Entities/Boat.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
|
||||||
|
// Boat.h
|
||||||
|
|
||||||
|
// Declares the cBoat class representing a boat in the world
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Entity.h"
|
||||||
|
#include "../Item.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class cBoat :
|
||||||
|
public cEntity
|
||||||
|
{
|
||||||
|
typedef cEntity super;
|
||||||
|
|
||||||
|
public:
|
||||||
|
CLASS_PROTODEF(cBoat);
|
||||||
|
|
||||||
|
// cEntity overrides:
|
||||||
|
virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
|
||||||
|
virtual void OnRightClicked(cPlayer & a_Player) override;
|
||||||
|
virtual void DoTakeDamage(TakeDamageInfo & TDI) override;
|
||||||
|
virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override;
|
||||||
|
|
||||||
|
cBoat(double a_X, double a_Y, double a_Z);
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -92,6 +92,7 @@ public:
|
|||||||
etMonster,
|
etMonster,
|
||||||
etFallingBlock,
|
etFallingBlock,
|
||||||
etMinecart,
|
etMinecart,
|
||||||
|
etBoat,
|
||||||
etTNT,
|
etTNT,
|
||||||
etProjectile,
|
etProjectile,
|
||||||
|
|
||||||
@ -119,6 +120,7 @@ public:
|
|||||||
bool IsPickup (void) const { return (m_EntityType == etPickup); }
|
bool IsPickup (void) const { return (m_EntityType == etPickup); }
|
||||||
bool IsMob (void) const { return (m_EntityType == etMob); }
|
bool IsMob (void) const { return (m_EntityType == etMob); }
|
||||||
bool IsMinecart(void) const { return (m_EntityType == etMinecart); }
|
bool IsMinecart(void) const { return (m_EntityType == etMinecart); }
|
||||||
|
bool IsBoat (void) const { return (m_EntityType == etBoat); }
|
||||||
bool IsTNT (void) const { return (m_EntityType == etTNT); }
|
bool IsTNT (void) const { return (m_EntityType == etTNT); }
|
||||||
|
|
||||||
/// Returns true if the entity is of the specified class or a subclass (cPawn's IsA("cEntity") returns true)
|
/// Returns true if the entity is of the specified class or a subclass (cPawn's IsA("cEntity") returns true)
|
||||||
|
54
source/Items/ItemBoat.h
Normal file
54
source/Items/ItemBoat.h
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
|
||||||
|
// ItemBoat.h
|
||||||
|
|
||||||
|
// Declares the various boat ItemHandlers
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../Entities/Boat.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class cItemBoatHandler :
|
||||||
|
public cItemHandler
|
||||||
|
{
|
||||||
|
typedef cItemHandler super;
|
||||||
|
|
||||||
|
public:
|
||||||
|
cItemBoatHandler(int a_ItemType) :
|
||||||
|
super(a_ItemType)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override
|
||||||
|
{
|
||||||
|
if (a_Dir < 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
double x = (double)a_BlockX + 0.5;
|
||||||
|
double y = (double)a_BlockY + 0.5;
|
||||||
|
double z = (double)a_BlockZ + 0.5;
|
||||||
|
|
||||||
|
cBoat * Boat = NULL;
|
||||||
|
|
||||||
|
Boat = new cBoat (x, y, z);
|
||||||
|
Boat->Initialize(a_World);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
// Handlers:
|
// Handlers:
|
||||||
#include "ItemBed.h"
|
#include "ItemBed.h"
|
||||||
|
#include "ItemBoat.h"
|
||||||
#include "ItemBow.h"
|
#include "ItemBow.h"
|
||||||
#include "ItemBrewingStand.h"
|
#include "ItemBrewingStand.h"
|
||||||
#include "ItemBucket.h"
|
#include "ItemBucket.h"
|
||||||
@ -180,6 +181,11 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType)
|
|||||||
return new cItemMinecartHandler(a_ItemType);
|
return new cItemMinecartHandler(a_ItemType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case E_ITEM_BOAT:
|
||||||
|
{
|
||||||
|
return new cItemBoatHandler(a_ItemType);
|
||||||
|
}
|
||||||
|
|
||||||
// Food:
|
// Food:
|
||||||
case E_ITEM_BREAD:
|
case E_ITEM_BREAD:
|
||||||
case E_ITEM_COOKIE:
|
case E_ITEM_COOKIE:
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "../OSSupport/MakeDir.h"
|
#include "../OSSupport/MakeDir.h"
|
||||||
#include "FastNBT.h"
|
#include "FastNBT.h"
|
||||||
#include "../Entities/FallingBlock.h"
|
#include "../Entities/FallingBlock.h"
|
||||||
|
#include "../Entities/Boat.h"
|
||||||
#include "../Entities/Minecart.h"
|
#include "../Entities/Minecart.h"
|
||||||
#include "../Mobs/Monster.h"
|
#include "../Mobs/Monster.h"
|
||||||
#include "../Entities/Pickup.h"
|
#include "../Entities/Pickup.h"
|
||||||
@ -252,6 +253,17 @@ void cNBTChunkSerializer::AddBasicEntity(cEntity * a_Entity, const AString & a_C
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cNBTChunkSerializer::AddBoatEntity(cBoat * a_Boat)
|
||||||
|
{
|
||||||
|
m_Writer.BeginCompound("");
|
||||||
|
AddBasicEntity(a_Boat, "Boat");
|
||||||
|
m_Writer.EndCompound();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cNBTChunkSerializer::AddFallingBlockEntity(cFallingBlock * a_FallingBlock)
|
void cNBTChunkSerializer::AddFallingBlockEntity(cFallingBlock * a_FallingBlock)
|
||||||
{
|
{
|
||||||
m_Writer.BeginCompound("");
|
m_Writer.BeginCompound("");
|
||||||
@ -462,6 +474,7 @@ void cNBTChunkSerializer::Entity(cEntity * a_Entity)
|
|||||||
|
|
||||||
switch (a_Entity->GetEntityType())
|
switch (a_Entity->GetEntityType())
|
||||||
{
|
{
|
||||||
|
case cEntity::etBoat: AddBoatEntity ((cBoat *) a_Entity); break;
|
||||||
case cEntity::etFallingBlock: AddFallingBlockEntity((cFallingBlock *) a_Entity); break;
|
case cEntity::etFallingBlock: AddFallingBlockEntity((cFallingBlock *) a_Entity); break;
|
||||||
case cEntity::etMinecart: AddMinecartEntity ((cMinecart *) a_Entity); break;
|
case cEntity::etMinecart: AddMinecartEntity ((cMinecart *) a_Entity); break;
|
||||||
case cEntity::etMonster: AddMonsterEntity ((cMonster *) a_Entity); break;
|
case cEntity::etMonster: AddMonsterEntity ((cMonster *) a_Entity); break;
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
class cFastNBTWriter;
|
class cFastNBTWriter;
|
||||||
class cEntity;
|
class cEntity;
|
||||||
class cBlockEntity;
|
class cBlockEntity;
|
||||||
|
class cBoat;
|
||||||
class cChestEntity;
|
class cChestEntity;
|
||||||
class cDispenserEntity;
|
class cDispenserEntity;
|
||||||
class cDropperEntity;
|
class cDropperEntity;
|
||||||
@ -94,6 +95,7 @@ protected:
|
|||||||
|
|
||||||
// Entities:
|
// Entities:
|
||||||
void AddBasicEntity (cEntity * a_Entity, const AString & a_ClassName);
|
void AddBasicEntity (cEntity * a_Entity, const AString & a_ClassName);
|
||||||
|
void AddBoatEntity (cBoat * a_Boat);
|
||||||
void AddFallingBlockEntity(cFallingBlock * a_FallingBlock);
|
void AddFallingBlockEntity(cFallingBlock * a_FallingBlock);
|
||||||
void AddMinecartEntity (cMinecart * a_Minecart);
|
void AddMinecartEntity (cMinecart * a_Minecart);
|
||||||
void AddMonsterEntity (cMonster * a_Monster);
|
void AddMonsterEntity (cMonster * a_Monster);
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "../OSSupport/MakeDir.h"
|
#include "../OSSupport/MakeDir.h"
|
||||||
#include "FastNBT.h"
|
#include "FastNBT.h"
|
||||||
#include "../Mobs/Monster.h"
|
#include "../Mobs/Monster.h"
|
||||||
|
#include "../Entities/Boat.h"
|
||||||
#include "../Entities/FallingBlock.h"
|
#include "../Entities/FallingBlock.h"
|
||||||
#include "../Entities/Minecart.h"
|
#include "../Entities/Minecart.h"
|
||||||
#include "../Entities/Pickup.h"
|
#include "../Entities/Pickup.h"
|
||||||
@ -911,7 +912,11 @@ void cWSSAnvil::LoadSignFromNBT(cBlockEntityList & a_BlockEntities, const cParse
|
|||||||
|
|
||||||
void cWSSAnvil::LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_EntityTagIdx, const char * a_IDTag, int a_IDTagLength)
|
void cWSSAnvil::LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_EntityTagIdx, const char * a_IDTag, int a_IDTagLength)
|
||||||
{
|
{
|
||||||
if (strncmp(a_IDTag, "FallingBlock", a_IDTagLength) == 0)
|
if (strncmp(a_IDTag, "Boat", a_IDTagLength) == 0)
|
||||||
|
{
|
||||||
|
LoadBoatFromNBT(a_Entities, a_NBT, a_EntityTagIdx);
|
||||||
|
}
|
||||||
|
else if (strncmp(a_IDTag, "FallingBlock", a_IDTagLength) == 0)
|
||||||
{
|
{
|
||||||
LoadFallingBlockFromNBT(a_Entities, a_NBT, a_EntityTagIdx);
|
LoadFallingBlockFromNBT(a_Entities, a_NBT, a_EntityTagIdx);
|
||||||
}
|
}
|
||||||
@ -987,6 +992,20 @@ void cWSSAnvil::LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cWSSAnvil::LoadBoatFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx)
|
||||||
|
{
|
||||||
|
std::auto_ptr<cBoat> Boat(new cBoat(0, 0, 0));
|
||||||
|
if (!LoadEntityBaseFromNBT(*Boat.get(), a_NBT, a_TagIdx))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
a_Entities.push_back(Boat.release());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cWSSAnvil::LoadFallingBlockFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx)
|
void cWSSAnvil::LoadFallingBlockFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx)
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
|
@ -140,6 +140,7 @@ protected:
|
|||||||
|
|
||||||
void LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_EntityTagIdx, const char * a_IDTag, int a_IDTagLength);
|
void LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_EntityTagIdx, const char * a_IDTag, int a_IDTagLength);
|
||||||
|
|
||||||
|
void LoadBoatFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
|
||||||
void LoadFallingBlockFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
|
void LoadFallingBlockFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
|
||||||
void LoadMinecartRFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
|
void LoadMinecartRFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
|
||||||
void LoadMinecartCFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
|
void LoadMinecartCFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
|
||||||
|
Loading…
Reference in New Issue
Block a user