Move crafting action detection from InventoryTransactionPacket to Player

This commit is contained in:
Dylan K. Taylor 2020-06-26 11:59:30 +01:00
parent 24a2889758
commit c5bbb2bcbc
2 changed files with 23 additions and 35 deletions

View File

@ -148,6 +148,7 @@ use pocketmine\network\mcpe\protocol\types\CommandParameter;
use pocketmine\network\mcpe\protocol\types\ContainerIds;
use pocketmine\network\mcpe\protocol\types\DimensionIds;
use pocketmine\network\mcpe\protocol\types\GameMode;
use pocketmine\network\mcpe\protocol\types\NetworkInventoryAction;
use pocketmine\network\mcpe\protocol\types\PersonaPieceTintColor;
use pocketmine\network\mcpe\protocol\types\PersonaSkinPiece;
use pocketmine\network\mcpe\protocol\types\PlayerPermissions;
@ -2368,7 +2369,27 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
/** @var InventoryAction[] $actions */
$actions = [];
$isCraftingPart = false;
$isFinalCraftingPart = false;
foreach($packet->actions as $networkInventoryAction){
if(
$networkInventoryAction->sourceType === NetworkInventoryAction::SOURCE_CONTAINER and
$networkInventoryAction->windowId === ContainerIds::UI and
$networkInventoryAction->inventorySlot === 50 and
!$networkInventoryAction->oldItem->equalsExact($networkInventoryAction->newItem)
){
$isCraftingPart = true;
if(!$networkInventoryAction->oldItem->isNull() and $networkInventoryAction->newItem->isNull()){
$isFinalCraftingPart = true;
}
}elseif(
$networkInventoryAction->sourceType === NetworkInventoryAction::SOURCE_TODO and (
$networkInventoryAction->windowId === NetworkInventoryAction::SOURCE_TYPE_CRAFTING_RESULT or
$networkInventoryAction->windowId === NetworkInventoryAction::SOURCE_TYPE_CRAFTING_USE_INGREDIENT
)
){
$isCraftingPart = true;
}
try{
$action = $networkInventoryAction->createInventoryAction($this);
if($action !== null){
@ -2381,7 +2402,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}
}
if($packet->isCraftingPart){
if($isCraftingPart){
if($this->craftingTransaction === null){
$this->craftingTransaction = new CraftingTransaction($this, $actions);
}else{
@ -2390,7 +2411,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}
}
if($packet->isFinalCraftingPart){
if($isFinalCraftingPart){
//we get the actions for this in several packets, so we need to wait until we have all the pieces before
//trying to execute it

View File

@ -26,7 +26,6 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\network\mcpe\protocol\types\ContainerIds;
use pocketmine\network\mcpe\protocol\types\NetworkInventoryAction;
use function count;
@ -52,19 +51,6 @@ class InventoryTransactionPacket extends DataPacket{
/** @var int */
public $transactionType;
/**
* @var bool
* NOTE: THIS FIELD DOES NOT EXIST IN THE PROTOCOL, it's merely used for convenience for PocketMine-MP to easily
* determine whether we're doing a crafting transaction.
*/
public $isCraftingPart = false;
/**
* @var bool
* NOTE: THIS FIELD DOES NOT EXIST IN THE PROTOCOL, it's merely used for convenience for PocketMine-MP to easily
* determine whether we're doing a crafting transaction.
*/
public $isFinalCraftingPart = false;
/** @var NetworkInventoryAction[] */
public $actions = [];
@ -76,25 +62,6 @@ class InventoryTransactionPacket extends DataPacket{
for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){
$this->actions[] = $action = (new NetworkInventoryAction())->read($this);
if(
$action->sourceType === NetworkInventoryAction::SOURCE_CONTAINER and
$action->windowId === ContainerIds::UI and
$action->inventorySlot === 50 and
!$action->oldItem->equalsExact($action->newItem)
){
$this->isCraftingPart = true;
if(!$action->oldItem->isNull() and $action->newItem->isNull()){
$this->isFinalCraftingPart = true;
}
}elseif(
$action->sourceType === NetworkInventoryAction::SOURCE_TODO and (
$action->windowId === NetworkInventoryAction::SOURCE_TYPE_CRAFTING_RESULT or
$action->windowId === NetworkInventoryAction::SOURCE_TYPE_CRAFTING_USE_INGREDIENT
)
){
$this->isCraftingPart = true;
}
}
$this->trData = new \stdClass();