Skip to content

Commit

Permalink
Implement 1.21.20 (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShockedPlot7560 committed Aug 18, 2024
1 parent 409933f commit 86450ab
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 44 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
"composer-runtime-api": "^2.0",
"adhocore/json-comment": "~1.2.0",
"fgrosse/phpasn1": "~2.5.0",
"pocketmine/bedrock-block-upgrade-schema": "~4.2.0+bedrock-1.21.0",
"pocketmine/bedrock-data": "~2.11.0+bedrock-1.21.0",
"pocketmine/bedrock-item-upgrade-schema": "~1.10.0+bedrock-1.21.0",
"pocketmine/bedrock-protocol": "~31.0.0+bedrock-1.21.0",
"pocketmine/bedrock-block-upgrade-schema": "~4.3.0+bedrock-1.21.20",
"pocketmine/bedrock-data": "~2.12.0+bedrock-1.21.20",
"pocketmine/bedrock-item-upgrade-schema": "~1.11.0+bedrock-1.21.20",
"pocketmine/bedrock-protocol": "~33.0.0+bedrock-1.21.20",
"pocketmine/binaryutils": "^0.2.1",
"pocketmine/callback-validator": "^1.0.2",
"pocketmine/classloader": "^0.2.0",
Expand Down
54 changes: 27 additions & 27 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/VersionInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

final class VersionInfo{
public const NAME = "PocketMine-MP";
public const BASE_VERSION = "4.30.0";
public const BASE_VERSION = "4.31.1";
public const IS_DEVELOPMENT_BUILD = true;
public const BUILD_CHANNEL = "stable";

Expand Down
11 changes: 7 additions & 4 deletions src/network/mcpe/InventoryManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,14 +451,16 @@ private function sendInventorySlotPackets(int $windowId, int $netSlot, ItemStack
$this->session->sendDataPacket(InventorySlotPacket::create(
$windowId,
$netSlot,
new ItemStackWrapper(0, ItemStack::null())
new ItemStackWrapper(0, ItemStack::null()),
0
));
}
//now send the real contents
$this->session->sendDataPacket(InventorySlotPacket::create(
$windowId,
$netSlot,
$itemStackWrapper
$itemStackWrapper,
0
));
}

Expand All @@ -476,10 +478,11 @@ private function sendInventoryContentPackets(int $windowId, array $itemStackWrap
*/
$this->session->sendDataPacket(InventoryContentPacket::create(
$windowId,
array_fill_keys(array_keys($itemStackWrappers), new ItemStackWrapper(0, ItemStack::null()))
array_fill_keys(array_keys($itemStackWrappers), new ItemStackWrapper(0, ItemStack::null())),
0
));
//now send the real contents
$this->session->sendDataPacket(InventoryContentPacket::create($windowId, $itemStackWrappers));
$this->session->sendDataPacket(InventoryContentPacket::create($windowId, $itemStackWrappers, 0));
}

public function syncSlot(Inventory $inventory, int $slot, ItemStack $itemStack) : void{
Expand Down
9 changes: 7 additions & 2 deletions src/network/mcpe/NetworkSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
use pocketmine\network\mcpe\handler\SpawnResponsePacketHandler;
use pocketmine\network\mcpe\protocol\AvailableCommandsPacket;
use pocketmine\network\mcpe\protocol\ChunkRadiusUpdatedPacket;
use pocketmine\network\mcpe\protocol\ClientboundCloseFormPacket;
use pocketmine\network\mcpe\protocol\ClientboundPacket;
use pocketmine\network\mcpe\protocol\DisconnectPacket;
use pocketmine\network\mcpe\protocol\ModalFormRequestPacket;
Expand Down Expand Up @@ -632,7 +633,7 @@ private function dispose() : void{
public function disconnect(string $reason, bool $notify = true) : void{
$this->tryDisconnect(function() use ($reason, $notify) : void{
if($notify){
$this->sendDataPacket(DisconnectPacket::create(0, $reason));
$this->sendDataPacket(DisconnectPacket::create(0, $reason, ""));
}
if($this->player !== null){
$this->player->onPostDisconnect($reason, null);
Expand All @@ -657,7 +658,7 @@ public function transfer(string $ip, int $port, string $reason = "transfer") : v
*/
public function onPlayerDestroyed(string $reason) : void{
$this->tryDisconnect(function() use ($reason) : void{
$this->sendDataPacket(DisconnectPacket::create(0, $reason));
$this->sendDataPacket(DisconnectPacket::create(0, $reason, ""));
}, $reason);
}

Expand Down Expand Up @@ -1005,6 +1006,10 @@ public function onFormSent(int $id, Form $form) : bool{
return $this->sendDataPacket(ModalFormRequestPacket::create($id, json_encode($form, JSON_THROW_ON_ERROR)));
}

public function onCloseAllForms() : void{
$this->sendDataPacket(ClientboundCloseFormPacket::create());
}

/**
* Instructs the networksession to start using the chunk at the given coordinates. This may occur asynchronously.
* @param \Closure $onCompletion To be called when chunk sending has completed.
Expand Down
4 changes: 3 additions & 1 deletion src/network/mcpe/StandardEntityEventBroadcaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use pocketmine\network\mcpe\protocol\types\entity\Attribute as NetworkAttribute;
use pocketmine\network\mcpe\protocol\types\entity\PropertySyncData;
use pocketmine\network\mcpe\protocol\types\inventory\ContainerIds;
use pocketmine\network\mcpe\protocol\types\inventory\ItemStack;
use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper;
use pocketmine\network\mcpe\protocol\UpdateAttributesPacket;
use function array_map;
Expand Down Expand Up @@ -130,7 +131,8 @@ public function onMobArmorChange(array $recipients, Living $mob) : void{
ItemStackWrapper::legacy($converter->coreItemStackToNet($inv->getHelmet())),
ItemStackWrapper::legacy($converter->coreItemStackToNet($inv->getChestplate())),
ItemStackWrapper::legacy($converter->coreItemStackToNet($inv->getLeggings())),
ItemStackWrapper::legacy($converter->coreItemStackToNet($inv->getBoots()))
ItemStackWrapper::legacy($converter->coreItemStackToNet($inv->getBoots())),
new ItemStackWrapper(0, ItemStack::null())
));
}

Expand Down
8 changes: 4 additions & 4 deletions src/network/mcpe/handler/ItemStackRequestExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ private function matchItemStack(Inventory $inventory, int $slotId, int $clientIt
* @throws ItemStackRequestProcessException
*/
protected function getBuilderInventoryAndSlot(ItemStackRequestSlotInfo $info) : array{
[$windowId, $slotId] = ItemStackContainerIdTranslator::translate($info->getContainerId(), $this->inventoryManager->getCurrentWindowId(), $info->getSlotId());
[$windowId, $slotId] = ItemStackContainerIdTranslator::translate($info->getContainerName()->getContainerId(), $this->inventoryManager->getCurrentWindowId(), $info->getSlotId());
$windowAndSlot = $this->inventoryManager->locateWindowAndSlot($windowId, $slotId);
if($windowAndSlot === null){
throw new ItemStackRequestProcessException("No open inventory matches container UI ID: " . $info->getContainerId() . ", slot ID: " . $info->getSlotId());
throw new ItemStackRequestProcessException("No open inventory matches container UI ID: " . $info->getContainerName()->getContainerId() . ", slot ID: " . $info->getSlotId());
}
[$inventory, $slot] = $windowAndSlot;
if(!$inventory->slotExists($slot)){
Expand All @@ -141,7 +141,7 @@ protected function transferItems(ItemStackRequestSlotInfo $source, ItemStackRequ
* @throws ItemStackRequestProcessException
*/
protected function removeItemFromSlot(ItemStackRequestSlotInfo $slotInfo, int $count) : Item{
if($slotInfo->getContainerId() === ContainerUIIds::CREATED_OUTPUT && $slotInfo->getSlotId() === UIInventorySlotOffset::CREATED_ITEM_OUTPUT){
if($slotInfo->getContainerName()->getContainerId() === ContainerUIIds::CREATED_OUTPUT && $slotInfo->getSlotId() === UIInventorySlotOffset::CREATED_ITEM_OUTPUT){
//special case for the "created item" output slot
//TODO: do we need to send a response for this slot info?
return $this->takeCreatedItem($count);
Expand Down Expand Up @@ -381,7 +381,7 @@ public function generateInventoryTransaction() : InventoryTransaction{
public function buildItemStackResponse() : ItemStackResponse{
$builder = new ItemStackResponseBuilder($this->request->getRequestId(), $this->inventoryManager);
foreach($this->requestSlotInfos as $requestInfo){
$builder->addSlot($requestInfo->getContainerId(), $requestInfo->getSlotId());
$builder->addSlot($requestInfo->getContainerName()->getContainerId(), $requestInfo->getSlotId());
}

return $builder->build();
Expand Down
3 changes: 2 additions & 1 deletion src/network/mcpe/handler/ItemStackResponseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use pocketmine\item\Durable;
use pocketmine\network\mcpe\InventoryManager;
use pocketmine\network\mcpe\protocol\types\inventory\ContainerUIIds;
use pocketmine\network\mcpe\protocol\types\inventory\FullContainerName;
use pocketmine\network\mcpe\protocol\types\inventory\stackresponse\ItemStackResponse;
use pocketmine\network\mcpe\protocol\types\inventory\stackresponse\ItemStackResponseContainerInfo;
use pocketmine\network\mcpe\protocol\types\inventory\stackresponse\ItemStackResponseSlotInfo;
Expand Down Expand Up @@ -99,7 +100,7 @@ public function build() : ItemStackResponse{

$responseContainerInfos = [];
foreach($responseInfosByContainer as $containerInterfaceId => $responseInfos){
$responseContainerInfos[] = new ItemStackResponseContainerInfo($containerInterfaceId, $responseInfos);
$responseContainerInfos[] = new ItemStackResponseContainerInfo(new FullContainerName($containerInterfaceId, 0), $responseInfos);
}

return new ItemStackResponse(ItemStackResponse::RESULT_OK, $this->requestId, $responseContainerInfos);
Expand Down
7 changes: 7 additions & 0 deletions src/player/Player.php
Original file line number Diff line number Diff line change
Expand Up @@ -2122,6 +2122,13 @@ public function onFormSubmit(int $formId, $responseData) : bool{
return true;
}

/**
* Closes the current viewing form and forms in queue.
*/
public function closeAllForms() : void{
$this->getNetworkSession()->onCloseAllForms();
}

/**
* Transfers a player to another server.
*
Expand Down

0 comments on commit 86450ab

Please sign in to comment.