mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-12 12:55:21 +00:00
Move crafting action detection from InventoryTransactionPacket to Player
This commit is contained in:
parent
24a2889758
commit
c5bbb2bcbc
@ -148,6 +148,7 @@ use pocketmine\network\mcpe\protocol\types\CommandParameter;
|
|||||||
use pocketmine\network\mcpe\protocol\types\ContainerIds;
|
use pocketmine\network\mcpe\protocol\types\ContainerIds;
|
||||||
use pocketmine\network\mcpe\protocol\types\DimensionIds;
|
use pocketmine\network\mcpe\protocol\types\DimensionIds;
|
||||||
use pocketmine\network\mcpe\protocol\types\GameMode;
|
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\PersonaPieceTintColor;
|
||||||
use pocketmine\network\mcpe\protocol\types\PersonaSkinPiece;
|
use pocketmine\network\mcpe\protocol\types\PersonaSkinPiece;
|
||||||
use pocketmine\network\mcpe\protocol\types\PlayerPermissions;
|
use pocketmine\network\mcpe\protocol\types\PlayerPermissions;
|
||||||
@ -2368,7 +2369,27 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
|
|
||||||
/** @var InventoryAction[] $actions */
|
/** @var InventoryAction[] $actions */
|
||||||
$actions = [];
|
$actions = [];
|
||||||
|
$isCraftingPart = false;
|
||||||
|
$isFinalCraftingPart = false;
|
||||||
foreach($packet->actions as $networkInventoryAction){
|
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{
|
try{
|
||||||
$action = $networkInventoryAction->createInventoryAction($this);
|
$action = $networkInventoryAction->createInventoryAction($this);
|
||||||
if($action !== null){
|
if($action !== null){
|
||||||
@ -2381,7 +2402,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($packet->isCraftingPart){
|
if($isCraftingPart){
|
||||||
if($this->craftingTransaction === null){
|
if($this->craftingTransaction === null){
|
||||||
$this->craftingTransaction = new CraftingTransaction($this, $actions);
|
$this->craftingTransaction = new CraftingTransaction($this, $actions);
|
||||||
}else{
|
}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
|
//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
|
//trying to execute it
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ namespace pocketmine\network\mcpe\protocol;
|
|||||||
#include <rules/DataPacket.h>
|
#include <rules/DataPacket.h>
|
||||||
|
|
||||||
use pocketmine\network\mcpe\NetworkSession;
|
use pocketmine\network\mcpe\NetworkSession;
|
||||||
use pocketmine\network\mcpe\protocol\types\ContainerIds;
|
|
||||||
use pocketmine\network\mcpe\protocol\types\NetworkInventoryAction;
|
use pocketmine\network\mcpe\protocol\types\NetworkInventoryAction;
|
||||||
use function count;
|
use function count;
|
||||||
|
|
||||||
@ -52,19 +51,6 @@ class InventoryTransactionPacket extends DataPacket{
|
|||||||
/** @var int */
|
/** @var int */
|
||||||
public $transactionType;
|
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[] */
|
/** @var NetworkInventoryAction[] */
|
||||||
public $actions = [];
|
public $actions = [];
|
||||||
|
|
||||||
@ -76,25 +62,6 @@ class InventoryTransactionPacket extends DataPacket{
|
|||||||
|
|
||||||
for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){
|
for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){
|
||||||
$this->actions[] = $action = (new NetworkInventoryAction())->read($this);
|
$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();
|
$this->trData = new \stdClass();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user