diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index ddd309d9..5e44794d 100755 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -644,4 +644,30 @@ class BlockAPI{ } } } + + public static function convertHighItemIdsToOldItemIds(int $protocolId, int $itemId){ + if ($protocolId >= ProtocolInfo::CURRENT_PROTOCOL) { + return $itemId; + } + + $idMap = []; + if ($protocolId < ProtocolInfo9::CURRENT_PROTOCOL_9) { + $idMap += [ + 87 => 49, + 405 => 336, + 406 => 336, + ]; + } + if ($protocolId < ProtocolInfo12::CURRENT_PROTOCOL_12) { + $idMap += [ + 91 => 103, + 361 => 362, + 400 => 297, + 457 => 295, + 458 => 297, + ]; + } + + return $idMap[$itemId] ?? $itemId; + } } diff --git a/src/network/protocol/packet/AddItemEntityPacket.php b/src/network/protocol/packet/AddItemEntityPacket.php index fb68f60a..b9d66cf3 100644 --- a/src/network/protocol/packet/AddItemEntityPacket.php +++ b/src/network/protocol/packet/AddItemEntityPacket.php @@ -21,7 +21,7 @@ class AddItemEntityPacket extends RakNetDataPacket{ public function encode(){ $this->reset(); $this->putInt($this->eid); - $this->putSlot($this->item); + $this->putSlot($this->PROTOCOL, $this->item); $this->putFloat($this->x); $this->putFloat($this->y); $this->putFloat($this->z); diff --git a/src/network/protocol/packet/ContainerSetContentPacket.php b/src/network/protocol/packet/ContainerSetContentPacket.php index e8ae387c..9df71cdc 100644 --- a/src/network/protocol/packet/ContainerSetContentPacket.php +++ b/src/network/protocol/packet/ContainerSetContentPacket.php @@ -35,7 +35,7 @@ class ContainerSetContentPacket extends RakNetDataPacket{ $this->putByte($this->windowid); $this->putShort(count($this->slots)); foreach($this->slots as $slot){ - $this->putSlot($slot); + $this->putSlot($this->PROTOCOL, $slot); } if($this->windowid === 0 and count($this->hotbar) > 0){ $this->putShort(count($this->hotbar));//null diff --git a/src/network/protocol/packet/ContainerSetSlotPacket.php b/src/network/protocol/packet/ContainerSetSlotPacket.php index 2a012112..70fb6b39 100644 --- a/src/network/protocol/packet/ContainerSetSlotPacket.php +++ b/src/network/protocol/packet/ContainerSetSlotPacket.php @@ -26,7 +26,7 @@ class ContainerSetSlotPacket extends RakNetDataPacket{ $this->reset(); $this->putByte($this->windowid); $this->putShort($this->slot); - $this->putSlot($this->item); + $this->putSlot($this->PROTOCOL, $this->item); } } \ No newline at end of file diff --git a/src/network/protocol/packet/PlaceBlockPacket.php b/src/network/protocol/packet/PlaceBlockPacket.php index 22cbf9dc..950115ef 100644 --- a/src/network/protocol/packet/PlaceBlockPacket.php +++ b/src/network/protocol/packet/PlaceBlockPacket.php @@ -32,7 +32,7 @@ class PlaceBlockPacket extends RakNetDataPacket{ $this->putInt($this->x); $this->putInt($this->z); $this->putByte($this->y); - $this->putByte($this->block); + $this->putByte(BlockAPI::convertHighItemIdsToOldItemIds($this->PROTOCOL, $this->block)); $this->putByte($this->meta); $this->putByte($this->face); } diff --git a/src/network/protocol/packet/PlayerEquipmentPacket.php b/src/network/protocol/packet/PlayerEquipmentPacket.php index 2bcb648f..d95ef3be 100644 --- a/src/network/protocol/packet/PlayerEquipmentPacket.php +++ b/src/network/protocol/packet/PlayerEquipmentPacket.php @@ -23,7 +23,7 @@ class PlayerEquipmentPacket extends RakNetDataPacket{ public function encode(){ $this->reset(); $this->putInt($this->eid); - $this->putShort($this->item); + $this->putShort(BlockAPI::convertHighItemIdsToOldItemIds($this->PROTOCOL, $this->item)); $this->putShort($this->meta); if($this->PROTOCOL === ProtocolInfo::CURRENT_PROTOCOL){$this->putByte($this->slot);} } diff --git a/src/network/protocol/packet/SendInventoryPacket.php b/src/network/protocol/packet/SendInventoryPacket.php index 8bfaef4a..78410a52 100644 --- a/src/network/protocol/packet/SendInventoryPacket.php +++ b/src/network/protocol/packet/SendInventoryPacket.php @@ -37,11 +37,11 @@ class SendInventoryPacket extends RakNetDataPacket{ $this->putByte($this->windowid); $this->putShort(count($this->slots)); foreach($this->slots as $slot){ - $this->putSlot($slot); + $this->putSlot($this->PROTOCOL, $slot); } if($this->windowid === 1 and count($this->armor) === 4){ for($s = 0; $s < 4; ++$s){ - $this->putSlot($this->armor[$s]); + $this->putSlot($this->PROTOCOL, $this->armor[$s]); } } } diff --git a/src/network/protocol/packet/UpdateBlockPacket.php b/src/network/protocol/packet/UpdateBlockPacket.php index d75eb806..76c92815 100644 --- a/src/network/protocol/packet/UpdateBlockPacket.php +++ b/src/network/protocol/packet/UpdateBlockPacket.php @@ -23,7 +23,7 @@ class UpdateBlockPacket extends RakNetDataPacket{ $this->putInt($this->x); $this->putInt($this->z); $this->putByte($this->y); - $this->putByte($this->block); + $this->putByte(BlockAPI::convertHighItemIdsToOldItemIds($this->PROTOCOL, $this->block)); $this->putByte($this->meta); } diff --git a/src/network/raknet/RakNetDataPacket.php b/src/network/raknet/RakNetDataPacket.php index ba0ab963..765b5851 100755 --- a/src/network/raknet/RakNetDataPacket.php +++ b/src/network/raknet/RakNetDataPacket.php @@ -150,8 +150,8 @@ abstract class RakNetDataPacket extends stdClass{ return ord($this->get(1)); } - protected function putSlot(Item $item){ - $this->putShort($item->getID()); + protected function putSlot(Int $protocolId, Item $item){ + $this->putShort(BlockAPI::convertHighItemIdsToOldItemIds($protocolId, $item->getID())); $this->putByte($item->count); $this->putShort($item->getMetadata()); }