Conver High ItemID to Old ItemId

This commit is contained in:
yefengeeeeeeeeeee 2025-04-25 17:19:22 +08:00
parent 6b7563d8ea
commit fd23ba04ec
9 changed files with 36 additions and 10 deletions

View file

@ -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;
}
}

View file

@ -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);

View file

@ -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

View file

@ -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);
}
}

View file

@ -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);
}

View file

@ -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);}
}

View file

@ -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]);
}
}
}

View file

@ -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);
}

View file

@ -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());
}