1
0

allow use failures to propagate from the entity/block to the player

This commit is contained in:
Gargaj
2015-12-01 23:12:44 +01:00
parent e7fd308ffa
commit f9008a4860
55 changed files with 120 additions and 77 deletions

View File

@@ -282,7 +282,7 @@ bool cBeaconEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
void cBeaconEntity::UsedBy(cPlayer * a_Player)
bool cBeaconEntity::UsedBy(cPlayer * a_Player)
{
cWindow * Window = GetWindow();
if (Window == nullptr)
@@ -299,6 +299,7 @@ void cBeaconEntity::UsedBy(cPlayer * a_Player)
a_Player->OpenWindow(Window);
}
}
return true;
}

View File

@@ -31,7 +31,7 @@ public:
// cBlockEntity overrides:
virtual void SendTo(cClientHandle & a_Client) override;
virtual bool Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
virtual void UsedBy(cPlayer * a_Player) override;
virtual bool UsedBy(cPlayer * a_Player) override;
/** Modify the beacon level. (It is needed to load the beacon corectly) */
void SetBeaconLevel(char a_Level) { m_BeaconLevel = a_Level; }

View File

@@ -102,8 +102,9 @@ public:
// tolua_end
/** Called when a player uses this entity; should open the UI window */
virtual void UsedBy( cPlayer * a_Player) = 0;
/** Called when a player uses this entity; should open the UI window.
returns true if the use was successful, return false to use the block as a "normal" block */
virtual bool UsedBy( cPlayer * a_Player) = 0;
/** Sends the packet defining the block entity to the client specified.
To send to all eligible clients, use cWorld::BroadcastBlockEntity() */

View File

@@ -51,7 +51,7 @@ cBrewingstandEntity::~cBrewingstandEntity()
void cBrewingstandEntity::UsedBy(cPlayer * a_Player)
bool cBrewingstandEntity::UsedBy(cPlayer * a_Player)
{
cWindow * Window = GetWindow();
if (Window == nullptr)
@@ -76,6 +76,7 @@ void cBrewingstandEntity::UsedBy(cPlayer * a_Player)
{
BroadcastProgress(0, 0);
}
return true;
}

View File

@@ -44,7 +44,7 @@ public:
// cBlockEntity overrides:
virtual void SendTo(cClientHandle & a_Client) override;
virtual bool Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
virtual void UsedBy(cPlayer * a_Player) override;
virtual bool UsedBy(cPlayer * a_Player) override;
virtual void Destroy() override
{
m_IsDestroyed = true;

View File

@@ -45,7 +45,7 @@ void cChestEntity::SendTo(cClientHandle & a_Client)
void cChestEntity::UsedBy(cPlayer * a_Player)
bool cChestEntity::UsedBy(cPlayer * a_Player)
{
// If the window is not created, open it anew:
cWindow * Window = GetWindow();
@@ -71,6 +71,7 @@ void cChestEntity::UsedBy(cPlayer * a_Player)
int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(m_PosX, m_PosZ, ChunkX, ChunkZ);
m_World->MarkChunkDirty(ChunkX, ChunkZ, true);
return true;
}

View File

@@ -37,7 +37,7 @@ public:
// cBlockEntity overrides:
virtual void SendTo(cClientHandle & a_Client) override;
virtual void UsedBy(cPlayer * a_Player) override;
virtual bool UsedBy(cPlayer * a_Player) override;
/** Opens a new chest window for this chest.
Scans for neighbors to open a double chest window, if appropriate. */

View File

@@ -29,10 +29,11 @@ cCommandBlockEntity::cCommandBlockEntity(int a_X, int a_Y, int a_Z, cWorld * a_W
void cCommandBlockEntity::UsedBy(cPlayer * a_Player)
bool cCommandBlockEntity::UsedBy(cPlayer * a_Player)
{
// Nothing to do
UNUSED(a_Player);
return true;
}

View File

@@ -35,7 +35,7 @@ public:
virtual bool Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
virtual void SendTo(cClientHandle & a_Client) override;
virtual void UsedBy(cPlayer * a_Player) override;
virtual bool UsedBy(cPlayer * a_Player) override;
void SetLastOutput(const AString & a_LastOut);

View File

@@ -154,7 +154,7 @@ void cDropSpenserEntity::SendTo(cClientHandle & a_Client)
void cDropSpenserEntity::UsedBy(cPlayer * a_Player)
bool cDropSpenserEntity::UsedBy(cPlayer * a_Player)
{
cWindow * Window = GetWindow();
if (Window == nullptr)
@@ -170,6 +170,7 @@ void cDropSpenserEntity::UsedBy(cPlayer * a_Player)
a_Player->OpenWindow(Window);
}
}
return true;
}

View File

@@ -49,7 +49,7 @@ public:
// cBlockEntity overrides:
virtual bool Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
virtual void SendTo(cClientHandle & a_Client) override;
virtual void UsedBy(cPlayer * a_Player) override;
virtual bool UsedBy(cPlayer * a_Player) override;
// tolua_begin

View File

@@ -33,13 +33,13 @@ cEnderChestEntity::~cEnderChestEntity()
void cEnderChestEntity::UsedBy(cPlayer * a_Player)
bool cEnderChestEntity::UsedBy(cPlayer * a_Player)
{
// TODO: cats are an obstruction
if ((GetPosY() < cChunkDef::Height - 1) && !cBlockInfo::IsTransparent(GetWorld()->GetBlock(GetPosX(), GetPosY() + 1, GetPosZ())))
{
// Obstruction, don't open
return;
return false;
}
// If the window is not created, open it anew:
cWindow * Window = GetWindow();
@@ -57,6 +57,7 @@ void cEnderChestEntity::UsedBy(cPlayer * a_Player)
a_Player->OpenWindow(Window);
}
}
return true;
}

View File

@@ -24,7 +24,7 @@ public:
virtual ~cEnderChestEntity();
// cBlockEntity overrides:
virtual void UsedBy(cPlayer * a_Player) override;
virtual bool UsedBy(cPlayer * a_Player) override;
virtual void SendTo(cClientHandle & a_Client) override { UNUSED(a_Client); }
static void LoadFromJson(const Json::Value & a_Value, cItemGrid & a_Grid);

View File

@@ -22,11 +22,11 @@ cFlowerPotEntity::cFlowerPotEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWo
// It don't do anything when 'used'
void cFlowerPotEntity::UsedBy(cPlayer * a_Player)
bool cFlowerPotEntity::UsedBy(cPlayer * a_Player)
{
if (IsItemInPot())
{
return;
return false;
}
cItem SelectedItem = a_Player->GetInventory().GetEquippedItem();
@@ -39,6 +39,7 @@ void cFlowerPotEntity::UsedBy(cPlayer * a_Player)
}
m_World->BroadcastBlockEntity(m_PosX, m_PosY, m_PosZ, a_Player->GetClientHandle());
}
return true;
}

View File

@@ -46,7 +46,8 @@ public:
// tolua_end
virtual void UsedBy(cPlayer * a_Player) override;
/** Called when the player is using the entity; returns true if it was a successful use, return false if it should be treated as a normal block */
virtual bool UsedBy(cPlayer * a_Player) override;
virtual void SendTo(cClientHandle & a_Client) override;
static bool IsFlower(short m_ItemType, short m_ItemData);

View File

@@ -56,7 +56,7 @@ cFurnaceEntity::~cFurnaceEntity()
void cFurnaceEntity::UsedBy(cPlayer * a_Player)
bool cFurnaceEntity::UsedBy(cPlayer * a_Player)
{
cWindow * Window = GetWindow();
if (Window == nullptr)
@@ -74,6 +74,7 @@ void cFurnaceEntity::UsedBy(cPlayer * a_Player)
}
UpdateProgressBars(true);
return true;
}

View File

@@ -43,7 +43,7 @@ public:
// cBlockEntity overrides:
virtual void SendTo(cClientHandle & a_Client) override;
virtual bool Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
virtual void UsedBy(cPlayer * a_Player) override;
virtual bool UsedBy(cPlayer * a_Player) override;
virtual void Destroy() override
{
m_IsDestroyed = true;

View File

@@ -80,7 +80,7 @@ void cHopperEntity::SendTo(cClientHandle & a_Client)
void cHopperEntity::UsedBy(cPlayer * a_Player)
bool cHopperEntity::UsedBy(cPlayer * a_Player)
{
// If the window is not created, open it anew:
cWindow * Window = GetWindow();
@@ -106,6 +106,7 @@ void cHopperEntity::UsedBy(cPlayer * a_Player)
int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(m_PosX, m_PosZ, ChunkX, ChunkZ);
m_World->MarkChunkDirty(ChunkX, ChunkZ);
return true;
}

View File

@@ -49,7 +49,7 @@ protected:
// cBlockEntity overrides:
virtual bool Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
virtual void SendTo(cClientHandle & a_Client) override;
virtual void UsedBy(cPlayer * a_Player) override;
virtual bool UsedBy(cPlayer * a_Player) override;
/** Opens a new chest window for this chest. Scans for neighbors to open a double chest window, if appropriate. */
void OpenNewWindow(void);

View File

@@ -28,11 +28,12 @@ cJukeboxEntity::~cJukeboxEntity()
void cJukeboxEntity::UsedBy(cPlayer * a_Player)
bool cJukeboxEntity::UsedBy(cPlayer * a_Player)
{
if (IsPlayingRecord())
{
EjectRecord();
return true;
}
else
{
@@ -40,8 +41,10 @@ void cJukeboxEntity::UsedBy(cPlayer * a_Player)
if (PlayRecord(HeldItem.m_ItemType))
{
a_Player->GetInventory().RemoveOneEquippedItem();
return true;
}
}
return false;
}

View File

@@ -44,7 +44,7 @@ public:
// tolua_end
virtual void UsedBy(cPlayer * a_Player) override;
virtual bool UsedBy(cPlayer * a_Player) override;
virtual void SendTo(cClientHandle &) override {}
private:

View File

@@ -23,9 +23,10 @@ cMobHeadEntity::cMobHeadEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld
void cMobHeadEntity::UsedBy(cPlayer * a_Player)
bool cMobHeadEntity::UsedBy(cPlayer * a_Player)
{
UNUSED(a_Player);
return true;
}

View File

@@ -53,7 +53,7 @@ public:
// tolua_end
virtual void UsedBy(cPlayer * a_Player) override;
virtual bool UsedBy(cPlayer * a_Player) override;
virtual void SendTo(cClientHandle & a_Client) override;
private:

View File

@@ -33,14 +33,14 @@ void cMobSpawnerEntity::SendTo(cClientHandle & a_Client)
void cMobSpawnerEntity::UsedBy(cPlayer * a_Player)
bool cMobSpawnerEntity::UsedBy(cPlayer * a_Player)
{
if (a_Player->GetEquippedItem().m_ItemType == E_ITEM_SPAWN_EGG)
{
eMonsterType MonsterType = cItemSpawnEggHandler::ItemDamageToMonsterType(a_Player->GetEquippedItem().m_ItemDamage);
if (MonsterType == eMonsterType::mtInvalidType)
{
return;
return false;
}
m_Entity = MonsterType;
@@ -50,7 +50,9 @@ void cMobSpawnerEntity::UsedBy(cPlayer * a_Player)
a_Player->GetInventory().RemoveOneEquippedItem();
}
LOGD("Changed monster spawner at {%d, %d, %d} to type %s.", GetPosX(), GetPosY(), GetPosZ(), cMonster::MobTypeToString(MonsterType).c_str());
return true;
}
return false;
}

View File

@@ -28,7 +28,7 @@ public:
cMobSpawnerEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World);
virtual void SendTo(cClientHandle & a_Client) override;
virtual void UsedBy(cPlayer * a_Player) override;
virtual bool UsedBy(cPlayer * a_Player) override;
virtual bool Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
// tolua_begin

View File

@@ -19,11 +19,12 @@ cNoteEntity::cNoteEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_Wo
void cNoteEntity::UsedBy(cPlayer * a_Player)
bool cNoteEntity::UsedBy(cPlayer * a_Player)
{
UNUSED(a_Player);
IncrementPitch();
MakeSound();
return true;
}

View File

@@ -49,7 +49,7 @@ public:
// tolua_end
virtual void UsedBy(cPlayer * a_Player) override;
virtual bool UsedBy(cPlayer * a_Player) override;
virtual void SendTo(cClientHandle &) override {}
virtual void SetRedstonePower(bool a_Value) override

View File

@@ -22,9 +22,10 @@ cSignEntity::cSignEntity(BLOCKTYPE a_BlockType, int a_X, int a_Y, int a_Z, cWorl
void cSignEntity::UsedBy(cPlayer * a_Player)
bool cSignEntity::UsedBy(cPlayer * a_Player)
{
UNUSED(a_Player);
return true;
}

View File

@@ -43,7 +43,7 @@ public:
// tolua_end
virtual void UsedBy(cPlayer * a_Player) override;
virtual bool UsedBy(cPlayer * a_Player) override;
virtual void SendTo(cClientHandle & a_Client) override;
private: