Limit blockitem metadata hack to just blockitems

for some reason putting NBT on some items makes the creative inventory go haywire. Sadly, we currently need this hack, so I limit it to only stuff which actually needs it (blockitems).
closes #4159
This commit is contained in:
Dylan K. Taylor 2021-04-16 00:41:19 +01:00
parent b94bbf6f5e
commit 3c8eb29d4e
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -310,8 +310,15 @@ class NetworkBinaryStream extends BinaryStream{
$writeExtraCrapInTheMiddle($this); $writeExtraCrapInTheMiddle($this);
$block = $item->getBlock(); $blockRuntimeId = 0;
$this->putVarInt($block->getId() === BlockIds::AIR ? 0 : RuntimeBlockMapping::toStaticRuntimeId($block->getId(), $block->getDamage())); $isBlockItem = $item->getId() < 256;
if($isBlockItem){
$block = $item->getBlock();
if($block->getId() !== BlockIds::AIR){
$blockRuntimeId = RuntimeBlockMapping::toStaticRuntimeId($block->getId(), $block->getDamage());
}
}
$this->putVarInt($blockRuntimeId);
$nbt = null; $nbt = null;
if($item->hasCompoundTag()){ if($item->hasCompoundTag()){
@ -328,7 +335,7 @@ class NetworkBinaryStream extends BinaryStream{
$nbt = new CompoundTag(); $nbt = new CompoundTag();
} }
$nbt->setInt(self::DAMAGE_TAG, $coreData); $nbt->setInt(self::DAMAGE_TAG, $coreData);
}elseif($block->getId() !== BlockIds::AIR && $coreData !== 0){ }elseif($isBlockItem && $coreData !== 0){
//TODO HACK: This foul-smelling code ensures that we can correctly deserialize an item when the //TODO HACK: This foul-smelling code ensures that we can correctly deserialize an item when the
//client sends it back to us, because as of 1.16.220, blockitems quietly discard their metadata //client sends it back to us, because as of 1.16.220, blockitems quietly discard their metadata
//client-side. Aside from being very annoying, this also breaks various server-side behaviours. //client-side. Aside from being very annoying, this also breaks various server-side behaviours.