Skip to content

Commit

Permalink
CraftingEventPacket readded
Browse files Browse the repository at this point in the history
  • Loading branch information
dries-c committed Dec 7, 2023
1 parent 60e01ec commit 471d51e
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
83 changes: 83 additions & 0 deletions src/CraftingEventPacket.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

/*
* This file is part of BedrockProtocol.
* Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
*
* BedrockProtocol is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/

declare(strict_types=1);

namespace pocketmine\network\mcpe\protocol;

use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper;
use Ramsey\Uuid\UuidInterface;
use function count;

class CraftingEventPacket extends DataPacket implements ServerboundPacket{
public const NETWORK_ID = ProtocolInfo::CRAFTING_EVENT_PACKET;

Check failure on line 23 in src/CraftingEventPacket.php

View workflow job for this annotation

GitHub Actions / Tests (PHP 8.1)

Access to undefined constant pocketmine\network\mcpe\protocol\ProtocolInfo::CRAFTING_EVENT_PACKET.

Check failure on line 23 in src/CraftingEventPacket.php

View workflow job for this annotation

GitHub Actions / Tests (PHP 8.2)

Access to undefined constant pocketmine\network\mcpe\protocol\ProtocolInfo::CRAFTING_EVENT_PACKET.

Check failure on line 23 in src/CraftingEventPacket.php

View workflow job for this annotation

GitHub Actions / Tests (PHP 8.3)

Access to undefined constant pocketmine\network\mcpe\protocol\ProtocolInfo::CRAFTING_EVENT_PACKET.

public int $windowId;
public int $windowType;
public UuidInterface $recipeUUID;
/** @var ItemStackWrapper[] */
public array $input = [];
/** @var ItemStackWrapper[] */
public array $output = [];

/**
* @generate-create-func
* @param ItemStackWrapper[] $input
* @param ItemStackWrapper[] $output
*/
public static function create(int $windowId, int $windowType, UuidInterface $recipeUUID, array $input, array $output) : self{
$result = new self;
$result->windowId = $windowId;
$result->windowType = $windowType;
$result->recipeUUID = $recipeUUID;
$result->input = $input;
$result->output = $output;
return $result;
}

protected function decodePayload(PacketSerializer $in) : void{
$this->windowId = $in->getByte();
$this->windowType = $in->getVarInt();
$this->recipeUUID = $in->getUUID();

$size = $in->getUnsignedVarInt();
for($i = 0; $i < $size and $i < 128; ++$i){
$this->input[] = ItemStackWrapper::read($in);
}

$size = $in->getUnsignedVarInt();
for($i = 0; $i < $size and $i < 128; ++$i){
$this->output[] = ItemStackWrapper::read($in);
}
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putByte($this->windowId);
$out->putVarInt($this->windowType);
$out->putUUID($this->recipeUUID);

$out->putUnsignedVarInt(count($this->input));
foreach($this->input as $item){
$item->write($out);
}

$out->putUnsignedVarInt(count($this->output));
foreach($this->output as $item){
$item->write($out);
}
}

public function handle(PacketHandlerInterface $handler) : bool{
return $handler->handleCraftingEvent($this);
}
}
4 changes: 4 additions & 0 deletions src/PacketHandlerDefaultImplTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ public function handleCraftingData(CraftingDataPacket $packet) : bool{
return false;
}

public function handleCraftingEvent(CraftingEventPacket $packet) : bool{
return false;
}

public function handleGuiDataPickItem(GuiDataPickItemPacket $packet) : bool{
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions src/PacketHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ public function handleContainerSetData(ContainerSetDataPacket $packet) : bool;

public function handleCraftingData(CraftingDataPacket $packet) : bool;

public function handleCraftingEvent(CraftingEventPacket $packet) : bool;

public function handleGuiDataPickItem(GuiDataPickItemPacket $packet) : bool;

public function handleBlockActorData(BlockActorDataPacket $packet) : bool;
Expand Down
1 change: 1 addition & 0 deletions src/PacketPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function __construct(){
$this->registerPacket(new InventorySlotPacket());
$this->registerPacket(new ContainerSetDataPacket());
$this->registerPacket(new CraftingDataPacket());
$this->registerPacket(new CraftingEventPacket());
$this->registerPacket(new GuiDataPickItemPacket());
$this->registerPacket(new BlockActorDataPacket());
$this->registerPacket(new PlayerInputPacket());
Expand Down

0 comments on commit 471d51e

Please sign in to comment.