WriteBlockEntity: don't write position multiple times (#5373)

This commit is contained in:
Tiger Wang 2022-01-02 09:48:02 +00:00 committed by GitHub
parent 9914393c63
commit 1616108af3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 36 deletions

View File

@ -609,10 +609,6 @@ void cProtocol_1_11_0::HandlePacketBlockPlace(cByteBuffer & a_ByteBuffer)
void cProtocol_1_11_0::WriteBlockEntity(cFastNBTWriter & a_Writer, const cBlockEntity & a_BlockEntity) const
{
a_Writer.AddInt("x", a_BlockEntity.GetPosX());
a_Writer.AddInt("y", a_BlockEntity.GetPosY());
a_Writer.AddInt("z", a_BlockEntity.GetPosZ());
switch (a_BlockEntity.GetBlockType())
{
case E_BLOCK_BED:
@ -621,7 +617,6 @@ void cProtocol_1_11_0::WriteBlockEntity(cFastNBTWriter & a_Writer, const cBlockE
a_Writer.AddInt("color", BedEntity.GetColor()); // New: multicoloured beds
break;
}
case E_BLOCK_MOB_SPAWNER:
{
auto & MobSpawnerEntity = static_cast<const cMobSpawnerEntity &>(a_BlockEntity);
@ -631,9 +626,12 @@ void cProtocol_1_11_0::WriteBlockEntity(cFastNBTWriter & a_Writer, const cBlockE
a_Writer.AddShort("Delay", MobSpawnerEntity.GetSpawnDelay());
break;
}
default: Super::WriteBlockEntity(a_Writer, a_BlockEntity);
default: return Super::WriteBlockEntity(a_Writer, a_BlockEntity);
}
a_Writer.AddInt("x", a_BlockEntity.GetPosX());
a_Writer.AddInt("y", a_BlockEntity.GetPosY());
a_Writer.AddInt("z", a_BlockEntity.GetPosZ());
}

View File

@ -3089,10 +3089,6 @@ void cProtocol_1_8_0::SendPacket(cPacketizer & a_Pkt)
void cProtocol_1_8_0::WriteBlockEntity(cFastNBTWriter & a_Writer, const cBlockEntity & a_BlockEntity) const
{
a_Writer.AddInt("x", a_BlockEntity.GetPosX());
a_Writer.AddInt("y", a_BlockEntity.GetPosY());
a_Writer.AddInt("z", a_BlockEntity.GetPosZ());
switch (a_BlockEntity.GetBlockType())
{
case E_BLOCK_WALL_BANNER:
@ -3102,16 +3098,12 @@ void cProtocol_1_8_0::WriteBlockEntity(cFastNBTWriter & a_Writer, const cBlockEn
a_Writer.AddInt("Base", static_cast<Int32>(BannerEntity.GetBaseColor()));
break;
}
case E_BLOCK_BEACON:
case E_BLOCK_CHEST:
{
auto & BeaconEntity = static_cast<const cBeaconEntity &>(a_BlockEntity);
a_Writer.AddInt("Primary", BeaconEntity.GetPrimaryEffect());
a_Writer.AddInt("Secondary", BeaconEntity.GetSecondaryEffect());
a_Writer.AddInt("Levels", BeaconEntity.GetBeaconLevel());
// Nothing!
break;
}
case E_BLOCK_COMMAND_BLOCK:
{
auto & CommandBlockEntity = static_cast<const cCommandBlockEntity &>(a_BlockEntity);
@ -3128,23 +3120,12 @@ void cProtocol_1_8_0::WriteBlockEntity(cFastNBTWriter & a_Writer, const cBlockEn
}
break;
}
case E_BLOCK_ENCHANTMENT_TABLE:
{
auto & EnchantingTableEntity = static_cast<const cEnchantingTableEntity &>(a_BlockEntity);
if (!EnchantingTableEntity.GetCustomName().empty())
{
a_Writer.AddString("CustomName", EnchantingTableEntity.GetCustomName());
}
break;
}
case E_BLOCK_END_PORTAL:
{
// Nothing!
break;
}
case E_BLOCK_HEAD:
{
auto & MobHeadEntity = static_cast<const cMobHeadEntity &>(a_BlockEntity);
@ -3166,7 +3147,6 @@ void cProtocol_1_8_0::WriteBlockEntity(cFastNBTWriter & a_Writer, const cBlockEn
a_Writer.EndCompound();
break;
}
case E_BLOCK_FLOWER_POT:
{
auto & FlowerPotEntity = static_cast<const cFlowerPotEntity &>(a_BlockEntity);
@ -3174,7 +3154,6 @@ void cProtocol_1_8_0::WriteBlockEntity(cFastNBTWriter & a_Writer, const cBlockEn
a_Writer.AddInt("Data", static_cast<Int32>(FlowerPotEntity.GetItem().m_ItemDamage));
break;
}
case E_BLOCK_MOB_SPAWNER:
{
auto & MobSpawnerEntity = static_cast<const cMobSpawnerEntity &>(a_BlockEntity);
@ -3182,12 +3161,15 @@ void cProtocol_1_8_0::WriteBlockEntity(cFastNBTWriter & a_Writer, const cBlockEn
a_Writer.AddShort("Delay", MobSpawnerEntity.GetSpawnDelay());
break;
}
default:
{
break;
return;
}
}
a_Writer.AddInt("x", a_BlockEntity.GetPosX());
a_Writer.AddInt("y", a_BlockEntity.GetPosY());
a_Writer.AddInt("z", a_BlockEntity.GetPosZ());
}

View File

@ -1482,13 +1482,12 @@ void cProtocol_1_9_0::SendEntitySpawn(const cEntity & a_Entity, const UInt8 a_Ob
void cProtocol_1_9_0::WriteBlockEntity(cFastNBTWriter & a_Writer, const cBlockEntity & a_BlockEntity) const
{
a_Writer.AddInt("x", a_BlockEntity.GetPosX());
a_Writer.AddInt("y", a_BlockEntity.GetPosY());
a_Writer.AddInt("z", a_BlockEntity.GetPosZ());
if (a_BlockEntity.GetBlockType() == E_BLOCK_MOB_SPAWNER)
{
auto & MobSpawnerEntity = static_cast<const cMobSpawnerEntity &>(a_BlockEntity);
a_Writer.AddInt("x", a_BlockEntity.GetPosX());
a_Writer.AddInt("y", a_BlockEntity.GetPosY());
a_Writer.AddInt("z", a_BlockEntity.GetPosZ());
a_Writer.BeginCompound("SpawnData"); // New: SpawnData compound
a_Writer.AddString("id", cMonster::MobTypeToVanillaName(MobSpawnerEntity.GetEntity()));
a_Writer.EndCompound();