1
0
Fork 0

Minecarts can now be placed.

No interaction, no physics, though.

git-svn-id: http://mc-server.googlecode.com/svn/trunk@1219 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2013-02-18 16:48:50 +00:00
parent 32ee4aaf1e
commit d47ff55203
15 changed files with 292 additions and 18 deletions

View File

@ -974,6 +974,14 @@
RelativePath="..\source\Ladder.h"
>
</File>
<File
RelativePath="..\source\Minecart.cpp"
>
</File>
<File
RelativePath="..\source\Minecart.h"
>
</File>
<File
RelativePath="..\source\NoteEntity.cpp"
>
@ -2050,6 +2058,10 @@
RelativePath="..\source\items\ItemLighter.h"
>
</File>
<File
RelativePath="..\source\Items\ItemMinecart.h"
>
</File>
<File
RelativePath="..\source\items\ItemPickaxe.h"
>

View File

@ -1703,6 +1703,15 @@ void cClientHandle::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType,
void cClientHandle::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType)
{
m_Protocol->SendSpawnVehicle(a_Vehicle, a_VehicleType);
}
void cClientHandle::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer)
{
// Check chunks being sent, erase them from m_ChunksToSend:

View File

@ -114,6 +114,7 @@ public:
void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock);
void SendSpawnMob (const cMonster & a_Mob);
void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, short a_SpeedX, short a_SpeedY, short a_SpeedZ, Byte a_Yaw, Byte a_Pitch);
void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType);
void SendTeleportEntity (const cEntity & a_Entity);
void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ);
void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay);

View File

@ -64,6 +64,7 @@ public:
etPickup,
etMob,
etFallingBlock,
etMinecart,
// Older constants, left over for compatibility reasons (plugins)
eEntityType_Entity = etEntity,

View File

@ -5,32 +5,33 @@
#include "../World.h"
#include "../Player.h"
//Handler
#include "ItemCloth.h"
#include "ItemHoe.h"
#include "ItemSlab.h"
#include "ItemWood.h"
#include "ItemShears.h"
#include "ItemLeaves.h"
#include "ItemSapling.h"
// Handlers:
#include "ItemBed.h"
#include "ItemBrewingStand.h"
#include "ItemBucket.h"
#include "ItemCauldron.h"
#include "ItemCloth.h"
#include "ItemDoor.h"
#include "ItemDye.h"
#include "ItemFlowerPot.h"
#include "ItemFood.h"
#include "ItemHoe.h"
#include "ItemLeaves.h"
#include "ItemLighter.h"
#include "ItemMinecart.h"
#include "ItemPickaxe.h"
#include "ItemRedstoneDust.h"
#include "ItemRedstoneRepeater.h"
#include "ItemSapling.h"
#include "ItemSeeds.h"
#include "ItemDye.h"
#include "ItemSugarcane.h"
#include "ItemPickaxe.h"
#include "ItemShears.h"
#include "ItemShovel.h"
#include "ItemSword.h"
#include "ItemDoor.h"
#include "ItemFood.h"
#include "ItemSign.h"
#include "ItemBed.h"
#include "ItemSlab.h"
#include "ItemSpawnEgg.h"
#include "ItemFlowerPot.h"
#include "ItemBrewingStand.h"
#include "ItemCauldron.h"
#include "ItemSugarcane.h"
#include "ItemSword.h"
#include "ItemWood.h"
#include "../Blocks/BlockHandler.h"
@ -155,6 +156,13 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType)
return new cItemDoorHandler(a_ItemType);
}
case E_ITEM_MINECART:
case E_ITEM_CHEST_MINECART:
case E_ITEM_FURNACE_MINECART:
{
return new cItemMinecartHandler(a_ItemType);
}
// Food:
case E_ITEM_BREAD:
case E_ITEM_COOKIE:

View File

@ -0,0 +1,79 @@
// ItemMinecart.h
// Declares the various minecart ItemHandlers
#pragma once
// Not needed, we're being included only from ItemHandler.cpp which already has this file: #include "ItemHandler.h"
#include "../Minecart.h"
class cItemMinecartHandler :
public cItemHandler
{
typedef cItemHandler super;
public:
cItemMinecartHandler(int a_ItemType) :
super(a_ItemType)
{
}
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, cItem * a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override
{
if (a_Dir < 0)
{
return false;
}
// Check that there's rail in there:
BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
switch (Block)
{
case E_BLOCK_MINECART_TRACKS:
case E_BLOCK_POWERED_RAIL:
case E_BLOCK_DETECTOR_RAIL:
{
// These are allowed
break;
}
default:
{
LOGD("Used minecart on an unsuitable block %d (%s)", Block, ItemTypeToString(Block).c_str());
return false;
}
}
cMinecart::ePayload Payload = cMinecart::mpNone;
switch (m_ItemType)
{
case E_ITEM_MINECART: Payload = cMinecart::mpNone; break;
case E_ITEM_CHEST_MINECART: Payload = cMinecart::mpChest; break;
case E_ITEM_FURNACE_MINECART: Payload = cMinecart::mpFurnace; break;
default:
{
ASSERT(!"Unhandled minecart item");
return false;
}
} // switch (m_ItemType)
cMinecart * Minecart = new cMinecart(Payload, (double)a_BlockX + 0.5, a_BlockY, (double)a_BlockZ + 0.5);
a_World->AddEntity(Minecart);
Minecart->Initialize(a_World);
return true;
}
} ;

62
source/Minecart.cpp Normal file
View File

@ -0,0 +1,62 @@
// Minecart.cpp
// Implements the cMinecart class representing a minecart in the world
#include "Globals.h"
#include "Minecart.h"
#include "World.h"
#include "ClientHandle.h"
cMinecart::cMinecart(ePayload a_Payload, double a_X, double a_Y, double a_Z) :
super(etMinecart, a_X, a_Y, a_Z),
m_Payload(a_Payload)
{
}
void cMinecart::Initialize(cWorld * a_World)
{
super::Initialize(a_World);
a_World->BroadcastSpawn(*this);
}
void cMinecart::SpawnOn(cClientHandle & a_ClientHandle)
{
char Type = 0;
switch (m_Payload)
{
case mpNone: Type = 10; break;
case mpChest: Type = 11; break;
case mpFurnace: Type = 12; break;
default:
{
ASSERT(!"Unknown payload, cannot spawn on client");
return;
}
}
a_ClientHandle.SendSpawnVehicle(*this, Type);
}
void cMinecart::Tick(float a_Dt, MTRand & a_TickRandom)
{
// TODO: the physics
}

46
source/Minecart.h Normal file
View File

@ -0,0 +1,46 @@
// 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:
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
// TODO: Other 1.5 features: hopper, tnt, dispenser, spawner
} ;
cMinecart(ePayload a_Payload, double a_X, double a_Y, double a_Z);
// cEntity overrides:
virtual void Initialize(cWorld * a_World) override;
virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
virtual void Tick(float a_Dt, MTRand & a_TickRandom) override;
ePayload GetPayload(void) const { return m_Payload; }
protected:
ePayload m_Payload;
} ;

View File

@ -84,6 +84,7 @@ public:
virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) = 0;
virtual void SendSpawnMob (const cMonster & a_Mob) = 0;
virtual void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, short a_SpeedX, short a_SpeedY, short a_SpeedZ, Byte a_Yaw, Byte a_Pitch) = 0;
virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType) = 0;
virtual void SendTeleportEntity (const cEntity & a_Entity) = 0;
virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) = 0;
virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay) = 0;

View File

@ -670,6 +670,26 @@ void cProtocol125::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType,
void cProtocol125::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType)
{
cCSLock Lock(m_CSPacket);
WriteByte (PACKET_SPAWN_OBJECT);
WriteInt (a_Vehicle.GetUniqueID());
WriteByte (a_VehicleType);
WriteInt ((int)(a_Vehicle.GetPosX() * 32));
WriteInt ((int)(a_Vehicle.GetPosY() * 32));
WriteInt ((int)(a_Vehicle.GetPosZ() * 32));
WriteInt (1);
WriteShort(0); // TODO: SpeedX
WriteShort(0); // TODO: SpeedY
WriteShort(0); // TODO: SpeedZ
Flush();
}
void cProtocol125::SendTeleportEntity(const cEntity & a_Entity)
{
cCSLock Lock(m_CSPacket);

View File

@ -61,6 +61,7 @@ public:
virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override;
virtual void SendSpawnMob (const cMonster & a_Mob) override;
virtual void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, short a_SpeedX, short a_SpeedY, short a_SpeedZ, Byte a_Yaw, Byte a_Pitch) override;
virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType) override;
virtual void SendTeleportEntity (const cEntity & a_Entity) override;
virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) override;
virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay) override;

View File

@ -235,3 +235,25 @@ void cProtocol146::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType,
void cProtocol146::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType)
{
cCSLock Lock(m_CSPacket);
WriteByte(PACKET_SPAWN_OBJECT);
WriteInt (a_Vehicle.GetUniqueID());
WriteByte(a_VehicleType);
WriteInt ((int)(a_Vehicle.GetPosX() * 32));
WriteInt ((int)(a_Vehicle.GetPosY() * 32));
WriteInt ((int)(a_Vehicle.GetPosZ() * 32));
WriteInt (1);
WriteShort(0); // TODO: SpeedX
WriteShort(0); // TODO: SpeedY
WriteShort(0); // TODO: SpeedZ
WriteByte (0); // TODO: Yaw
WriteByte (0); // TODO: Pitch
Flush();
}

View File

@ -55,6 +55,7 @@ public:
virtual void SendPickupSpawn (const cPickup & a_Pickup) override;
virtual void SendSpawnFallingBlock(const cFallingBlock & a_FallingBlock) override;
virtual void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, short a_SpeedX, short a_SpeedY, short a_SpeedZ, Byte a_Yaw, Byte a_Pitch) override;
virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType) override;
} ;

View File

@ -436,6 +436,16 @@ void cProtocolRecognizer::SendSpawnObject(const cEntity & a_Entity, char a_Objec
void cProtocolRecognizer::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType)
{
ASSERT(m_Protocol != NULL);
m_Protocol->SendSpawnVehicle(a_Vehicle, a_VehicleType);
}
void cProtocolRecognizer::SendTeleportEntity(const cEntity & a_Entity)
{
ASSERT(m_Protocol != NULL);

View File

@ -86,6 +86,7 @@ public:
virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override;
virtual void SendSpawnMob (const cMonster & a_Mob) override;
virtual void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, short a_SpeedX, short a_SpeedY, short a_SpeedZ, Byte a_Yaw, Byte a_Pitch) override;
virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType) override;
virtual void SendTeleportEntity (const cEntity & a_Entity) override;
virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) override;
virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay) override;