1
0

Implemented paintings, fixes #689

+ Implemented paintings
This commit is contained in:
Tiger Wang 2014-02-18 00:16:03 +00:00
parent 7aeae734e5
commit 320cc74f0a
15 changed files with 226 additions and 3 deletions

View File

@ -266,7 +266,7 @@ enum ENUM_ITEM_ID
E_ITEM_FLINT = 318,
E_ITEM_RAW_PORKCHOP = 319,
E_ITEM_COOKED_PORKCHOP = 320,
E_ITEM_PAINTINGS = 321,
E_ITEM_PAINTING = 321,
E_ITEM_GOLDEN_APPLE = 322,
E_ITEM_SIGN = 323,
E_ITEM_WOODEN_DOOR = 324,

View File

@ -2091,6 +2091,14 @@ void cClientHandle::SendPickupSpawn(const cPickup & a_Pickup)
void cClientHandle::SendPaintingSpawn(const cPainting & a_Painting)
{
m_Protocol->SendPaintingSpawn(a_Painting);
}
void cClientHandle::SendEntityAnimation(const cEntity & a_Entity, char a_Animation)
{

View File

@ -27,6 +27,7 @@ class cInventory;
class cMonster;
class cPawn;
class cExpOrb;
class cPainting;
class cPickup;
class cPlayer;
class cProtocol;
@ -111,6 +112,7 @@ public:
void SendGameMode (eGameMode a_GameMode);
void SendHealth (void);
void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item);
void SendPaintingSpawn (const cPainting & a_Painting);
void SendPickupSpawn (const cPickup & a_Pickup);
void SendEntityAnimation (const cEntity & a_Entity, char a_Animation);
void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount);

View File

@ -81,6 +81,7 @@ public:
etProjectile,
etExpOrb,
etFloater,
etPainting,
// Common variations
etMob = etMonster, // DEPRECATED, use etMonster instead!
@ -139,6 +140,7 @@ public:
bool IsProjectile (void) const { return (m_EntityType == etProjectile); }
bool IsExpOrb (void) const { return (m_EntityType == etExpOrb); }
bool IsFloater (void) const { return (m_EntityType == etFloater); }
bool IsPainting (void) const { return (m_EntityType == etPainting); }
/// Returns true if the entity is of the specified class or a subclass (cPawn's IsA("cEntity") returns true)
virtual bool IsA(const char * a_ClassName) const;

43
src/Entities/Painting.cpp Normal file
View File

@ -0,0 +1,43 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Painting.h"
#include "ClientHandle.h"
#include "Player.h"
cPainting::cPainting(const AString & a_Name, int a_Direction, double a_X, double a_Y, double a_Z)
: cEntity(etPainting, a_X, a_Y, a_Z, 1, 1),
m_Name(a_Name),
m_Direction(a_Direction)
{
}
void cPainting::SpawnOn(cClientHandle & a_Client)
{
a_Client.SendPaintingSpawn(*this);
}
void cPainting::GetDrops(cItems & a_Items, cEntity * a_Killer)
{
if ((a_Killer != NULL) && a_Killer->IsPlayer() && !((cPlayer *)a_Killer)->IsGameModeCreative())
{
a_Items.push_back(cItem(E_ITEM_PAINTING));
}
}

42
src/Entities/Painting.h Normal file
View File

@ -0,0 +1,42 @@
#pragma once
#include "Entity.h"
// tolua_begin
class cPainting :
public cEntity
{
// tolua_end
typedef cEntity super;
public:
CLASS_PROTODEF(cPainting);
cPainting(const AString & a_Name, int a_Direction, double a_X, double a_Y, double a_Z);
const AString & GetName(void) const { return m_Name; }
int GetDirection(void) const { return m_Direction; }
private:
virtual void SpawnOn(cClientHandle & a_Client) override;
virtual void Tick(float a_Dt, cChunk & a_Chunk) override {};
virtual void GetDrops(cItems & a_Items, cEntity * a_Killer) override;
virtual void KilledBy(cEntity * a_Killer) override
{
super::KilledBy(a_Killer);
Destroy();
}
AString m_Name;
int m_Direction;
}; // tolua_export

View File

@ -26,6 +26,7 @@
#include "ItemLighter.h"
#include "ItemMinecart.h"
#include "ItemNetherWart.h"
#include "ItemPainting.h"
#include "ItemPickaxe.h"
#include "ItemThrowable.h"
#include "ItemRedstoneDust.h"
@ -106,6 +107,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType)
case E_ITEM_FLINT_AND_STEEL: return new cItemLighterHandler(a_ItemType);
case E_ITEM_FLOWER_POT: return new cItemFlowerPotHandler(a_ItemType);
case E_ITEM_NETHER_WART: return new cItemNetherWartHandler(a_ItemType);
case E_ITEM_PAINTING: return new cItemPaintingHandler(a_ItemType);
case E_ITEM_REDSTONE_DUST: return new cItemRedstoneDustHandler(a_ItemType);
case E_ITEM_REDSTONE_REPEATER: return new cItemRedstoneRepeaterHandler(a_ItemType);
case E_ITEM_SHEARS: return new cItemShearsHandler(a_ItemType);
@ -305,7 +307,7 @@ char cItemHandler::GetMaxStackSize(void)
case E_ITEM_BOWL: return 64;
case E_ITEM_BREAD: return 64;
case E_ITEM_BREWING_STAND: return 64;
case E_ITEM_BUCKET: return 1; // TODO: change this to 16 when turning compatibility to 1.3
case E_ITEM_BUCKET: return 16;
case E_ITEM_CARROT: return 64;
case E_ITEM_CAULDRON: return 64;
case E_ITEM_CLAY: return 64;
@ -349,7 +351,7 @@ char cItemHandler::GetMaxStackSize(void)
case E_ITEM_MELON_SLICE: return 64;
case E_ITEM_NETHER_BRICK: return 64;
case E_ITEM_NETHER_WART: return 64;
case E_ITEM_PAINTINGS: return 64;
case E_ITEM_PAINTING: return 64;
case E_ITEM_PAPER: return 64;
case E_ITEM_POISONOUS_POTATO: return 64;
case E_ITEM_POTATO: return 64;

95
src/Items/ItemPainting.h Normal file
View File

@ -0,0 +1,95 @@
#pragma once
#include "ItemHandler.h"
#include "../World.h"
#include "../Entities/Player.h"
#include "../Entities/Painting.h"
class cItemPaintingHandler :
public cItemHandler
{
public:
cItemPaintingHandler(int a_ItemType)
: cItemHandler(a_ItemType)
{
}
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override
{
if (a_Dir == BLOCK_FACE_NONE)
{
return false;
}
AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_Dir);
BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_Dir, true);
if (Block == E_BLOCK_AIR)
{
int Dir = 0;
switch (a_Dir)
{
case BLOCK_FACE_SOUTH: break;
case BLOCK_FACE_NORTH: Dir = 2; break;
case BLOCK_FACE_WEST: Dir = 1; break;
case BLOCK_FACE_EAST: Dir = 3; break;
default: return false;
}
static const struct // Define all the possible painting titles
{
AString Title;
} gPaintingTitlesList[] =
{
{ "Kebab" },
{ "Aztec" },
{ "Alban" },
{ "Aztec2" },
{ "Bomb" },
{ "Plant" },
{ "Wasteland" },
{ "Wanderer" },
{ "Graham" },
{ "Pool" },
{ "Courbet" },
{ "Sunset" },
{ "Sea" },
{ "Creebet" },
{ "Match" },
{ "Bust" },
{ "Stage" },
{ "Void" },
{ "SkullAndRoses" },
{ "Wither" },
{ "Fighters" },
{ "Skeleton" },
{ "DonkeyKong" },
{ "Pointer" },
{ "Pigscene" },
{ "BurningSkull" }
};
cPainting * Painting = new cPainting(gPaintingTitlesList[a_World->GetTickRandomNumber(ARRAYCOUNT(gPaintingTitlesList) - 1)].Title, Dir, a_BlockX, a_BlockY, a_BlockZ);
Painting->Initialize(a_World);
if (!a_Player->IsGameModeCreative())
{
a_Player->GetInventory().RemoveOneEquippedItem();
}
return true;
}
return false;
}
};

View File

@ -24,6 +24,7 @@ class cWindow;
class cInventory;
class cPawn;
class cPickup;
class cPainting;
class cWorld;
class cMonster;
class cChunkDataSerializer;
@ -81,6 +82,7 @@ public:
virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) = 0;
virtual void SendKeepAlive (int a_PingID) = 0;
virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) = 0;
virtual void SendPaintingSpawn (const cPainting & a_Painting) = 0;
virtual void SendPickupSpawn (const cPickup & a_Pickup) = 0;
virtual void SendPlayerAbilities (void) = 0;
virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) = 0;

View File

@ -56,6 +56,7 @@ public:
virtual void SendKeepAlive (int a_PingID) override;
virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override;
virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount) override;
virtual void SendPaintingSpawn (const cPainting & a_Painting) override {};
virtual void SendPickupSpawn (const cPickup & a_Pickup) override;
virtual void SendPlayerAbilities (void) override {} // This protocol doesn't support such message
virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) override;

View File

@ -21,6 +21,7 @@ Implements the 1.7.x protocol classes:
#include "../Entities/ExpOrb.h"
#include "../Entities/Minecart.h"
#include "../Entities/FallingBlock.h"
#include "../Entities/Painting.h"
#include "../Entities/Pickup.h"
#include "../Entities/Player.h"
#include "../Mobs/IncludeAllMonsters.h"
@ -569,6 +570,20 @@ void cProtocol172::SendLogin(const cPlayer & a_Player, const cWorld & a_World)
void cProtocol172::SendPaintingSpawn(const cPainting & a_Painting)
{
cPacketizer Pkt(*this, 0x10); // Spawn Painting packet
Pkt.WriteVarInt(a_Painting.GetUniqueID());
Pkt.WriteString(a_Painting.GetName().c_str());
Pkt.WriteInt((int)a_Painting.GetPosX());
Pkt.WriteInt((int)a_Painting.GetPosY());
Pkt.WriteInt((int)a_Painting.GetPosZ());
Pkt.WriteInt(a_Painting.GetDirection());
}
void cProtocol172::SendPickupSpawn(const cPickup & a_Pickup)
{

View File

@ -87,6 +87,7 @@ public:
virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override;
virtual void SendKeepAlive (int a_PingID) override;
virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override;
virtual void SendPaintingSpawn (const cPainting & a_Painting) override;
virtual void SendPickupSpawn (const cPickup & a_Pickup) override;
virtual void SendPlayerAbilities (void) override;
virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) override;

View File

@ -405,6 +405,14 @@ void cProtocolRecognizer::SendParticleEffect(const AString & a_ParticleName, flo
void cProtocolRecognizer::SendPaintingSpawn(const cPainting & a_Painting)
{
m_Protocol->SendPaintingSpawn(a_Painting);
}
void cProtocolRecognizer::SendPickupSpawn(const cPickup & a_Pickup)
{

View File

@ -91,6 +91,7 @@ public:
virtual void SendKeepAlive (int a_PingID) override;
virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override;
virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount) override;
virtual void SendPaintingSpawn (const cPainting & a_Painting) override;
virtual void SendPickupSpawn (const cPickup & a_Pickup) override;
virtual void SendPlayerAbilities (void) override;
virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) override;

View File

@ -627,6 +627,7 @@ void cNBTChunkSerializer::Entity(cEntity * a_Entity)
case cEntity::etProjectile: AddProjectileEntity ((cProjectileEntity *)a_Entity); break;
case cEntity::etTNT: /* TODO */ break;
case cEntity::etExpOrb: /* TODO */ break;
case cEntity::etPainting: /* TODO */ break;
case cEntity::etPlayer: return; // Players aren't saved into the world
default:
{