summaryrefslogtreecommitdiffstats
path: root/src/BlockEntities
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2021-03-28 15:40:57 +0200
committerGitHub <noreply@github.com>2021-03-28 15:40:57 +0200
commit748b121703fa28b10933f4432c09391e66179118 (patch)
tree58a39b6a75c3e9127507bf3c185a99e546147276 /src/BlockEntities
parentFix Windows XP to 7 compatibility (#5167) (diff)
downloadcuberite-748b121703fa28b10933f4432c09391e66179118.tar
cuberite-748b121703fa28b10933f4432c09391e66179118.tar.gz
cuberite-748b121703fa28b10933f4432c09391e66179118.tar.bz2
cuberite-748b121703fa28b10933f4432c09391e66179118.tar.lz
cuberite-748b121703fa28b10933f4432c09391e66179118.tar.xz
cuberite-748b121703fa28b10933f4432c09391e66179118.tar.zst
cuberite-748b121703fa28b10933f4432c09391e66179118.zip
Diffstat (limited to '')
-rw-r--r--src/BlockEntities/BedEntity.cpp8
-rw-r--r--src/BlockEntities/ChestEntity.cpp21
-rw-r--r--src/BlockEntities/CommandBlockEntity.cpp11
-rw-r--r--src/BlockEntities/MobHeadEntity.cpp5
-rw-r--r--src/BlockEntities/MobSpawnerEntity.cpp3
5 files changed, 13 insertions, 35 deletions
diff --git a/src/BlockEntities/BedEntity.cpp b/src/BlockEntities/BedEntity.cpp
index 3d7005b12..7f5f90639 100644
--- a/src/BlockEntities/BedEntity.cpp
+++ b/src/BlockEntities/BedEntity.cpp
@@ -56,12 +56,4 @@ void cBedEntity::SendTo(cClientHandle & a_Client)
void cBedEntity::SetColor(short a_Color)
{
m_Color = a_Color;
- auto Pos = GetPos();
-
- // If the bed entity is send immediately, the client (maybe) still has not the bed.
- // Fix that by delaying the broadcast of the bed entity by a tick:
- m_World->ScheduleTask(1, [Pos](cWorld & a_World)
- {
- a_World.BroadcastBlockEntity(Pos);
- });
}
diff --git a/src/BlockEntities/ChestEntity.cpp b/src/BlockEntities/ChestEntity.cpp
index 039d62287..9ede18759 100644
--- a/src/BlockEntities/ChestEntity.cpp
+++ b/src/BlockEntities/ChestEntity.cpp
@@ -146,24 +146,25 @@ bool cChestEntity::UsedBy(cPlayer * a_Player)
void cChestEntity::ScanNeighbours()
{
- // Callback for finding neighbouring chest:
- auto FindNeighbour = [this](cChestEntity & a_Chest)
+ // Callback for finding neighbouring chest.
+ auto FindNeighbour = [this](cBlockEntity & a_BlockEntity)
{
- if (a_Chest.GetBlockType() != m_BlockType)
+ if (a_BlockEntity.GetBlockType() != m_BlockType)
{
// Neighboring block is not the same type of chest
- return true;
+ return false;
}
- m_Neighbour = &a_Chest;
- return false;
+
+ m_Neighbour = static_cast<cChestEntity *>(&a_BlockEntity);
+ return true;
};
// Scan horizontally adjacent blocks for any neighbouring chest of the same type:
if (
- m_World->DoWithChestAt(m_Pos.x - 1, m_Pos.y, m_Pos.z, FindNeighbour) ||
- m_World->DoWithChestAt(m_Pos.x + 1, m_Pos.y, m_Pos.z, FindNeighbour) ||
- m_World->DoWithChestAt(m_Pos.x, m_Pos.y, m_Pos.z - 1, FindNeighbour) ||
- m_World->DoWithChestAt(m_Pos.x, m_Pos.y, m_Pos.z + 1, FindNeighbour)
+ m_World->DoWithBlockEntityAt(m_Pos.addedX(-1), FindNeighbour) ||
+ m_World->DoWithBlockEntityAt(m_Pos.addedX(+1), FindNeighbour) ||
+ m_World->DoWithBlockEntityAt(m_Pos.addedZ(-1), FindNeighbour) ||
+ m_World->DoWithBlockEntityAt(m_Pos.addedX(+1), FindNeighbour)
)
{
m_Neighbour->m_Neighbour = this;
diff --git a/src/BlockEntities/CommandBlockEntity.cpp b/src/BlockEntities/CommandBlockEntity.cpp
index c1e2cd430..34b0fd5f5 100644
--- a/src/BlockEntities/CommandBlockEntity.cpp
+++ b/src/BlockEntities/CommandBlockEntity.cpp
@@ -43,15 +43,6 @@ bool cCommandBlockEntity::UsedBy(cPlayer * a_Player)
void cCommandBlockEntity::SetCommand(const AString & a_Cmd)
{
m_Command = a_Cmd;
-
- /*
- Vanilla requires that the server send a Block Entity Update after a command has been set
- Therefore, command blocks don't support on-the-fly (when window is open) updating of a command and therefore...
- ...the following code can't be put in UsedBy just before the window opens
-
- Just documenting my experience in getting this to work :P
- */
- m_World->BroadcastBlockEntity(GetPos());
}
@@ -60,7 +51,6 @@ void cCommandBlockEntity::SetCommand(const AString & a_Cmd)
void cCommandBlockEntity::SetLastOutput(const AString & a_LastOut)
{
- m_World->BroadcastBlockEntity(GetPos());
m_LastOutput = a_LastOut;
}
@@ -180,7 +170,6 @@ void cCommandBlockEntity::Execute()
{
// Overwrite field
m_CmdBlock->SetLastOutput(cClientHandle::FormatChatPrefix(m_CmdBlock->GetWorld()->ShouldUseChatPrefixes(), "SUCCESS", cChatColor::Green, cChatColor::White) + a_Text);
- m_CmdBlock->GetWorld()->BroadcastBlockEntity(m_CmdBlock->GetPos());
}
};
diff --git a/src/BlockEntities/MobHeadEntity.cpp b/src/BlockEntities/MobHeadEntity.cpp
index 14773a0f1..72d039e7e 100644
--- a/src/BlockEntities/MobHeadEntity.cpp
+++ b/src/BlockEntities/MobHeadEntity.cpp
@@ -33,7 +33,6 @@ void cMobHeadEntity::SetType(const eMobHeadType & a_Type)
m_OwnerUUID = cUUID{};
}
m_Type = a_Type;
- m_World->BroadcastBlockEntity(GetPos());
}
@@ -43,7 +42,6 @@ void cMobHeadEntity::SetType(const eMobHeadType & a_Type)
void cMobHeadEntity::SetRotation(eMobHeadRotation a_Rotation)
{
m_Rotation = a_Rotation;
- m_World->BroadcastBlockEntity(GetPos());
}
@@ -70,8 +68,6 @@ void cMobHeadEntity::SetOwner(const cPlayer & a_Owner)
break;
}
}
-
- m_World->BroadcastBlockEntity(GetPos());
}
@@ -89,7 +85,6 @@ void cMobHeadEntity::SetOwner(const cUUID & a_OwnerUUID, const AString & a_Owner
m_OwnerName = a_OwnerName;
m_OwnerTexture = a_OwnerTexture;
m_OwnerTextureSignature = a_OwnerTextureSignature;
- m_World->BroadcastBlockEntity(GetPos());
}
diff --git a/src/BlockEntities/MobSpawnerEntity.cpp b/src/BlockEntities/MobSpawnerEntity.cpp
index 78312edb1..8e5585b89 100644
--- a/src/BlockEntities/MobSpawnerEntity.cpp
+++ b/src/BlockEntities/MobSpawnerEntity.cpp
@@ -70,6 +70,7 @@ bool cMobSpawnerEntity::UsedBy(cPlayer * a_Player)
{
a_Player->GetInventory().RemoveOneEquippedItem();
}
+ m_World->BroadcastBlockEntity(GetPos());
FLOGD("Changed monster spawner at {0} to type {1}.", GetPos(), cMonster::MobTypeToString(MonsterType));
return true;
}
@@ -105,6 +106,7 @@ bool cMobSpawnerEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
if (m_SpawnDelay <= 0)
{
SpawnEntity();
+ m_World->BroadcastBlockEntity(GetPos());
return true;
}
else
@@ -121,7 +123,6 @@ bool cMobSpawnerEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
void cMobSpawnerEntity::ResetTimer(void)
{
m_SpawnDelay = GetRandomProvider().RandInt<short>(m_MinSpawnDelay, m_MaxSpawnDelay);
- m_World->BroadcastBlockEntity(GetPos());
}