mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-14 17:59:41 +00:00
Merge commit '8480ee82e'
# Conflicts: # resources/vanilla # src/pocketmine/Player.php # src/pocketmine/block/CraftingTable.php
This commit is contained in:
commit
e9eadd3a26
@ -91,6 +91,7 @@ use pocketmine\network\mcpe\protocol\types\inventory\UseItemTransactionData;
|
|||||||
use pocketmine\network\mcpe\protocol\types\inventory\WindowTypes;
|
use pocketmine\network\mcpe\protocol\types\inventory\WindowTypes;
|
||||||
use pocketmine\player\Player;
|
use pocketmine\player\Player;
|
||||||
use pocketmine\utils\AssumptionFailedError;
|
use pocketmine\utils\AssumptionFailedError;
|
||||||
|
use function array_key_exists;
|
||||||
use function array_push;
|
use function array_push;
|
||||||
use function base64_encode;
|
use function base64_encode;
|
||||||
use function count;
|
use function count;
|
||||||
@ -125,6 +126,15 @@ class InGamePacketHandler extends PacketHandler{
|
|||||||
/** @var Vector3|null */
|
/** @var Vector3|null */
|
||||||
protected $lastRightClickPos = null;
|
protected $lastRightClickPos = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: HACK! This tracks GUIs for inventories that the server considers "always open" so that the client can't
|
||||||
|
* open them twice. (1.16 hack)
|
||||||
|
* @var true[]
|
||||||
|
* @phpstan-var array<int, true>
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
protected $openHardcodedWindows = [];
|
||||||
|
|
||||||
public function __construct(Player $player, NetworkSession $session){
|
public function __construct(Player $player, NetworkSession $session){
|
||||||
$this->player = $player;
|
$this->player = $player;
|
||||||
$this->session = $session;
|
$this->session = $session;
|
||||||
@ -320,9 +330,13 @@ class InGamePacketHandler extends PacketHandler{
|
|||||||
$blockPos = $data->getBlockPos();
|
$blockPos = $data->getBlockPos();
|
||||||
if(!$this->player->interactBlock($blockPos, $data->getFace(), $clickPos)){
|
if(!$this->player->interactBlock($blockPos, $data->getFace(), $clickPos)){
|
||||||
$this->onFailedBlockAction($blockPos, $data->getFace());
|
$this->onFailedBlockAction($blockPos, $data->getFace());
|
||||||
}elseif($this->player->getWorld()->getBlock($blockPos)->getId() === BlockLegacyIds::CRAFTING_TABLE){
|
}elseif(
|
||||||
|
$this->player->getWorld()->getBlock($blockPos)->getId() === BlockLegacyIds::CRAFTING_TABLE &&
|
||||||
|
!array_key_exists($windowId = InventoryManager::HARDCODED_CRAFTING_GRID_WINDOW_ID, $this->openHardcodedWindows)
|
||||||
|
){
|
||||||
//TODO: HACK! crafting grid doesn't fit very well into the current PM container system, so this hack
|
//TODO: HACK! crafting grid doesn't fit very well into the current PM container system, so this hack
|
||||||
//allows it to carry on working approximately the same way as it did in 1.14
|
//allows it to carry on working approximately the same way as it did in 1.14
|
||||||
|
$this->openHardcodedWindows[$windowId] = true;
|
||||||
$this->session->sendDataPacket(ContainerOpenPacket::blockInvVec3(
|
$this->session->sendDataPacket(ContainerOpenPacket::blockInvVec3(
|
||||||
InventoryManager::HARDCODED_CRAFTING_GRID_WINDOW_ID,
|
InventoryManager::HARDCODED_CRAFTING_GRID_WINDOW_ID,
|
||||||
WindowTypes::WORKBENCH,
|
WindowTypes::WORKBENCH,
|
||||||
@ -431,10 +445,14 @@ class InGamePacketHandler extends PacketHandler{
|
|||||||
if($target === null){
|
if($target === null){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if($packet->action === InteractPacket::ACTION_OPEN_INVENTORY && $target === $this->player){
|
if(
|
||||||
|
$packet->action === InteractPacket::ACTION_OPEN_INVENTORY && $target === $this->player &&
|
||||||
|
!array_key_exists($windowId = InventoryManager::HARDCODED_INVENTORY_WINDOW_ID, $this->openHardcodedWindows)
|
||||||
|
){
|
||||||
//TODO: HACK! this restores 1.14ish behaviour, but this should be able to be listened to and
|
//TODO: HACK! this restores 1.14ish behaviour, but this should be able to be listened to and
|
||||||
//controlled by plugins. However, the player is always a subscriber to their own inventory so it
|
//controlled by plugins. However, the player is always a subscriber to their own inventory so it
|
||||||
//doesn't integrate well with the regular container system right now.
|
//doesn't integrate well with the regular container system right now.
|
||||||
|
$this->openHardcodedWindows[$windowId] = true;
|
||||||
$this->session->sendDataPacket(ContainerOpenPacket::entityInv(
|
$this->session->sendDataPacket(ContainerOpenPacket::entityInv(
|
||||||
InventoryManager::HARDCODED_INVENTORY_WINDOW_ID,
|
InventoryManager::HARDCODED_INVENTORY_WINDOW_ID,
|
||||||
WindowTypes::INVENTORY,
|
WindowTypes::INVENTORY,
|
||||||
@ -531,7 +549,11 @@ class InGamePacketHandler extends PacketHandler{
|
|||||||
public function handleContainerClose(ContainerClosePacket $packet) : bool{
|
public function handleContainerClose(ContainerClosePacket $packet) : bool{
|
||||||
$this->player->doCloseInventory();
|
$this->player->doCloseInventory();
|
||||||
|
|
||||||
|
if(array_key_exists($packet->windowId, $this->openHardcodedWindows)){
|
||||||
|
unset($this->openHardcodedWindows[$packet->windowId]);
|
||||||
|
}else{
|
||||||
$this->session->getInvManager()->onClientRemoveWindow($packet->windowId);
|
$this->session->getInvManager()->onClientRemoveWindow($packet->windowId);
|
||||||
|
}
|
||||||
|
|
||||||
$this->session->sendDataPacket(ContainerClosePacket::create($packet->windowId));
|
$this->session->sendDataPacket(ContainerClosePacket::create($packet->windowId));
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user