Added missing ItemStackRequest protocol changes

This commit is contained in:
Dylan K. Taylor 2021-02-03 23:37:41 +00:00
parent b1bb9fbd1c
commit bc14660e55
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
3 changed files with 81 additions and 4 deletions

View File

@ -0,0 +1,59 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program 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.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol\types\inventory\stackrequest;
use pocketmine\network\mcpe\NetworkBinaryStream;
/**
* Renames an item in an anvil, or map on a cartography table.
*/
final class CraftRecipeOptionalStackRequestAction extends ItemStackRequestAction{
/** @var int */
private $recipeId;
/** @var int */
private $filterStringIndex;
public function __construct(int $type, int $filterStringIndex){
$this->recipeId = $type;
$this->filterStringIndex = $filterStringIndex;
}
public function getRecipeId() : int{ return $this->recipeId; }
public function getFilterStringIndex() : int{ return $this->filterStringIndex; }
public static function getTypeId() : int{ return ItemStackRequestActionType::CRAFTING_RECIPE_OPTIONAL; }
public static function read(NetworkBinaryStream $in) : self{
$recipeId = $in->readGenericTypeNetworkId();
$filterStringIndex = $in->getLInt();
return new self($recipeId, $filterStringIndex);
}
public function write(NetworkBinaryStream $out) : void{
$out->writeGenericTypeNetworkId($this->recipeId);
$out->putLInt($this->filterStringIndex);
}
}

View File

@ -32,13 +32,21 @@ final class ItemStackRequest{
private $requestId;
/** @var ItemStackRequestAction[] */
private $actions;
/**
* @var string[]
* @phpstan-var list<string>
*/
private $filterStrings;
/**
* @param ItemStackRequestAction[] $actions
* @param string[] $filterStrings
* @phpstan-param list<string> $filterStrings
*/
public function __construct(int $requestId, array $actions){
public function __construct(int $requestId, array $actions, array $filterStrings){
$this->requestId = $requestId;
$this->actions = $actions;
$this->filterStrings = $filterStrings;
}
public function getRequestId() : int{ return $this->requestId; }
@ -60,6 +68,7 @@ final class ItemStackRequest{
case CraftRecipeStackRequestAction::getTypeId(): return CraftRecipeStackRequestAction::read($in);
case CraftRecipeAutoStackRequestAction::getTypeId(): return CraftRecipeAutoStackRequestAction::read($in);
case CreativeCreateStackRequestAction::getTypeId(): return CreativeCreateStackRequestAction::read($in);
case CraftRecipeOptionalStackRequestAction::getTypeId(): return CraftRecipeOptionalStackRequestAction::read($in);
case DeprecatedCraftingNonImplementedStackRequestAction::getTypeId(): return DeprecatedCraftingNonImplementedStackRequestAction::read($in);
case DeprecatedCraftingResultsStackRequestAction::getTypeId(): return DeprecatedCraftingResultsStackRequestAction::read($in);
}
@ -73,7 +82,11 @@ final class ItemStackRequest{
$typeId = $in->getByte();
$actions[] = self::readAction($in, $typeId);
}
return new self($requestId, $actions);
$filterStrings = [];
for($i = 0, $len = $in->getUnsignedVarInt(); $i < $len; ++$i){
$filterStrings[] = $in->getString();
}
return new self($requestId, $actions, $filterStrings);
}
public function write(NetworkBinaryStream $out) : void{
@ -83,5 +96,9 @@ final class ItemStackRequest{
$out->putByte($action::getTypeId());
$action->write($out);
}
$out->putUnsignedVarInt(count($this->filterStrings));
foreach($this->filterStrings as $string){
$out->putString($string);
}
}
}

View File

@ -41,6 +41,7 @@ final class ItemStackRequestActionType{
public const CRAFTING_RECIPE = 9;
public const CRAFTING_RECIPE_AUTO = 10; //recipe book?
public const CREATIVE_CREATE = 11;
public const CRAFTING_NON_IMPLEMENTED_DEPRECATED_ASK_TY_LAING = 12; //anvils aren't fully implemented yet
public const CRAFTING_RESULTS_DEPRECATED_ASK_TY_LAING = 13; //no idea what this is for
public const CRAFTING_RECIPE_OPTIONAL = 12; //anvil/cartography table rename
public const CRAFTING_NON_IMPLEMENTED_DEPRECATED_ASK_TY_LAING = 13;
public const CRAFTING_RESULTS_DEPRECATED_ASK_TY_LAING = 14; //no idea what this is for
}