Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
AkmalFairuz committed Aug 15, 2024
1 parent e728a72 commit f73cee8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/types/inventory/ContainerUIIds.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,23 @@ private function __construct(){
public const CRAFTER = 62;
public const DYNAMIC = 63;

public static function write(PacketSerializer $out, int $containerId) : void{
public static function write(PacketSerializer $out, int $containerId, bool $legacy = false) : void{
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_712){
(new FullContainerName($containerId))->write($out);
return;
}
if($out->getProtocol() < ProtocolInfo::PROTOCOL_560){
if($containerId > self::RECIPE_BOOK){
$containerId--;
}elseif($containerId === self::RECIPE_BOOK){
throw new \InvalidArgumentException("Invalid container ID for protocol version " . $out->getProtocolId());
throw new \InvalidArgumentException("Invalid container ID for protocol version " . $out->getProtocol());
}
}

$out->putByte($containerId);
}

public static function read(PacketSerializer $in) : ?int{
public static function read(PacketSerializer $in, bool $legacy = false) : ?int{
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_712){
return FullContainerName::read($in)->getContainerId();
}
Expand Down
4 changes: 2 additions & 2 deletions src/types/inventory/InventoryTransactionChangedSlotsHack.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function getContainerId() : int{ return $this->containerId; }
public function getChangedSlotIndexes() : array{ return $this->changedSlotIndexes; }

public static function read(PacketSerializer $in) : self{
$containerId = ContainerUIIds::read($in);
$containerId = ContainerUIIds::read($in, true);
$changedSlots = [];
for($i = 0, $len = $in->getUnsignedVarInt(); $i < $len; ++$i){
$changedSlots[] = $in->getByte();
Expand All @@ -41,7 +41,7 @@ public static function read(PacketSerializer $in) : self{
}

public function write(PacketSerializer $out) : void{
ContainerUIIds::write($out, $this->containerId);
ContainerUIIds::write($out, $this->containerId, true);
$out->putUnsignedVarInt(count($this->changedSlotIndexes));
foreach($this->changedSlotIndexes as $index){
$out->putByte($index);
Expand Down

0 comments on commit f73cee8

Please sign in to comment.