Skip to content

Commit

Permalink
Protocol changes for 1.16.100
Browse files Browse the repository at this point in the history
  • Loading branch information
dktapps committed Nov 21, 2020
1 parent 8273f78 commit 98cdc80
Show file tree
Hide file tree
Showing 35 changed files with 1,206 additions and 219 deletions.
24 changes: 21 additions & 3 deletions src/pocketmine/Player.php
Expand Up @@ -100,6 +100,7 @@
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\DoubleTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\network\mcpe\convert\ItemTypeDictionary;
use pocketmine\network\mcpe\PlayerNetworkSessionAdapter;
use pocketmine\network\mcpe\protocol\ActorEventPacket;
use pocketmine\network\mcpe\protocol\AdventureSettingsPacket;
Expand Down Expand Up @@ -148,6 +149,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\Experiments;
use pocketmine\network\mcpe\protocol\types\GameMode;
use pocketmine\network\mcpe\protocol\types\inventory\UIInventorySlotOffset;
use pocketmine\network\mcpe\protocol\types\NetworkInventoryAction;
Expand Down Expand Up @@ -1939,7 +1941,8 @@ public function handleLogin(LoginPacket $packet) : bool{
$animation["ImageWidth"],
base64_decode($animation["Image"], true)),
$animation["Type"],
$animation["Frames"]
$animation["Frames"],
$animation["AnimationExpression"]
);
}

Expand Down Expand Up @@ -2179,6 +2182,7 @@ public function handleResourcePackClientResponse(ResourcePackClientResponsePacke
//but it does have an annoying side-effect when true: it makes
//the client remove its own non-server-supplied resource packs.
$pk->mustAccept = false;
$pk->experiments = new Experiments([], false);
$this->dataPacket($pk);
break;
case ResourcePackClientResponsePacket::STATUS_COMPLETED:
Expand Down Expand Up @@ -2244,6 +2248,8 @@ protected function completeLoginSequence(){
$pk->commandsEnabled = true;
$pk->levelId = "";
$pk->worldName = $this->server->getMotd();
$pk->experiments = new Experiments([], false);
$pk->itemTable = ItemTypeDictionary::getInstance()->getEntries();
$this->dataPacket($pk);

$this->sendDataPacket(new AvailableActorIdentifiersPacket());
Expand Down Expand Up @@ -2870,7 +2876,7 @@ public function handleBlockPickRequest(BlockPickRequestPacket $packet) : bool{
}

public function handlePlayerAction(PlayerActionPacket $packet) : bool{
if(!$this->spawned or (!$this->isAlive() and $packet->action !== PlayerActionPacket::ACTION_RESPAWN and $packet->action !== PlayerActionPacket::ACTION_DIMENSION_CHANGE_REQUEST)){
if(!$this->spawned or (!$this->isAlive() and $packet->action !== PlayerActionPacket::ACTION_RESPAWN)){
return true;
}

Expand Down Expand Up @@ -2957,7 +2963,10 @@ public function handlePlayerAction(PlayerActionPacket $packet) : bool{
case PlayerActionPacket::ACTION_STOP_SWIMMING:
//TODO: handle this when it doesn't spam every damn tick (yet another spam bug!!)
break;
case PlayerActionPacket::ACTION_INTERACT_BLOCK: //ignored (for now)
case PlayerActionPacket::ACTION_INTERACT_BLOCK: //TODO: ignored (for now)
break;
case PlayerActionPacket::ACTION_CREATIVE_PLAYER_DESTROY_BLOCK:
//TODO: do we need to handle this?
break;
default:
$this->server->getLogger()->debug("Unhandled/unknown player action type " . $packet->action . " from " . $this->getName());
Expand Down Expand Up @@ -3039,6 +3048,12 @@ public function dropItem(Item $item) : bool{
return true;
}

/** @var int|null */
private $closingWindowId = null;

/** @internal */
public function getClosingWindowId() : ?int{ return $this->closingWindowId; }

public function handleContainerClose(ContainerClosePacket $packet) : bool{
if(!$this->spawned){
return true;
Expand All @@ -3050,12 +3065,15 @@ public function handleContainerClose(ContainerClosePacket $packet) : bool{
unset($this->openHardcodedWindows[$packet->windowId]);
$pk = new ContainerClosePacket();
$pk->windowId = $packet->windowId;
$pk->server = false;
$this->sendDataPacket($pk);
return true;
}
if(isset($this->windowIndex[$packet->windowId])){
$this->closingWindowId = $packet->windowId;
(new InventoryCloseEvent($this->windowIndex[$packet->windowId], $this))->call();
$this->removeWindow($this->windowIndex[$packet->windowId]);
$this->closingWindowId = null;
//removeWindow handles sending the appropriate
return true;
}
Expand Down
1 change: 1 addition & 0 deletions src/pocketmine/inventory/ContainerInventory.php
Expand Up @@ -64,6 +64,7 @@ public function onOpen(Player $who) : void{
public function onClose(Player $who) : void{
$pk = new ContainerClosePacket();
$pk->windowId = $who->getWindowId($this);
$pk->server = $who->getClosingWindowId() !== $pk->windowId;
$who->dataPacket($pk);
parent::onClose($who);
}
Expand Down
Expand Up @@ -163,6 +163,7 @@ protected function sendInventories() : void{
*/
$pk = new ContainerClosePacket();
$pk->windowId = Player::HARDCODED_CRAFTING_GRID_WINDOW_ID;
$pk->server = true;
$this->source->dataPacket($pk);
}

Expand Down
65 changes: 47 additions & 18 deletions src/pocketmine/network/mcpe/NetworkBinaryStream.php
Expand Up @@ -35,6 +35,9 @@
use pocketmine\nbt\NetworkLittleEndianNBTStream;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\NamedTag;
use pocketmine\network\mcpe\convert\ItemTranslator;
use pocketmine\network\mcpe\convert\ItemTypeDictionary;
use pocketmine\network\mcpe\protocol\types\CommandOriginData;
use pocketmine\network\mcpe\protocol\types\EntityLink;
use pocketmine\network\mcpe\protocol\types\GameRuleType;
Expand Down Expand Up @@ -91,7 +94,8 @@ public function getSkin() : SkinData{
$skinImage = $this->getSkinImage();
$animationType = $this->getLInt();
$animationFrames = $this->getLFloat();
$animations[] = new SkinAnimation($skinImage, $animationType, $animationFrames);
$expressionType = $this->getLInt();
$animations[] = new SkinAnimation($skinImage, $animationType, $animationFrames, $expressionType);
}
$capeData = $this->getSkinImage();
$geometryData = $this->getString();
Expand Down Expand Up @@ -186,15 +190,17 @@ private function putSkinImage(SkinImage $image) : void{
}

public function getSlot() : Item{
$id = $this->getVarInt();
if($id === 0){
$netId = $this->getVarInt();
if($netId === 0){
return ItemFactory::get(0, 0, 0);
}

$auxValue = $this->getVarInt();
$data = $auxValue >> 8;
$netData = $auxValue >> 8;
$cnt = $auxValue & 0xff;

[$id, $meta] = ItemTranslator::getInstance()->fromNetworkId($netId, $netData);

$nbtLen = $this->getLShort();

/** @var CompoundTag|null $nbt */
Expand Down Expand Up @@ -223,12 +229,12 @@ public function getSlot() : Item{
$this->getString();
}

if($id === ItemIds::SHIELD){
if($netId === ItemTypeDictionary::getInstance()->fromStringId("minecraft:shield")){
$this->getVarLong(); //"blocking tick" (ffs mojang)
}
if($nbt !== null){
if($nbt->hasTag(self::DAMAGE_TAG, IntTag::class)){
$data = $nbt->getInt(self::DAMAGE_TAG);
$meta = $nbt->getInt(self::DAMAGE_TAG);
$nbt->removeTag(self::DAMAGE_TAG);
if($nbt->count() === 0){
$nbt = null;
Expand All @@ -242,7 +248,7 @@ public function getSlot() : Item{
}
}
end:
return ItemFactory::get($id, $data, $cnt, $nbt);
return ItemFactory::get($id, $meta, $cnt, $nbt);
}

public function putSlot(Item $item) : void{
Expand All @@ -252,8 +258,10 @@ public function putSlot(Item $item) : void{
return;
}

$this->putVarInt($item->getId());
$auxValue = (($item->getDamage() & 0x7fff) << 8) | $item->getCount();
[$netId, $netData] = ItemTranslator::getInstance()->toNetworkId($item->getId(), $item->getDamage());

$this->putVarInt($netId);
$auxValue = (($netData & 0x7fff) << 8) | $item->getCount();
$this->putVarInt($auxValue);

$nbt = null;
Expand Down Expand Up @@ -284,20 +292,18 @@ public function putSlot(Item $item) : void{
$this->putVarInt(0); //CanPlaceOn entry count (TODO)
$this->putVarInt(0); //CanDestroy entry count (TODO)

if($item->getId() === ItemIds::SHIELD){
if($netId === ItemTypeDictionary::getInstance()->fromStringId("minecraft:shield")){
$this->putVarLong(0); //"blocking tick" (ffs mojang)
}
}

public function getRecipeIngredient() : Item{
$id = $this->getVarInt();
if($id === 0){
$netId = $this->getVarInt();
if($netId === 0){
return ItemFactory::get(ItemIds::AIR, 0, 0);
}
$meta = $this->getVarInt();
if($meta === 0x7fff){
$meta = -1;
}
$netData = $this->getVarInt();
[$id, $meta] = ItemTranslator::getInstance()->fromNetworkIdWithWildcardHandling($netId, $netData);
$count = $this->getVarInt();
return ItemFactory::get($id, $meta, $count);
}
Expand All @@ -306,8 +312,14 @@ public function putRecipeIngredient(Item $item) : void{
if($item->isNull()){
$this->putVarInt(0);
}else{
$this->putVarInt($item->getId());
$this->putVarInt($item->getDamage() & 0x7fff);
if($item->hasAnyDamageValue()){
[$netId, ] = ItemTranslator::getInstance()->toNetworkId($item->getId(), 0);
$netData = 0x7fff;
}else{
[$netId, $netData] = ItemTranslator::getInstance()->toNetworkId($item->getId(), $item->getDamage());
}
$this->putVarInt($netId);
$this->putVarInt($netData);
$this->putVarInt($item->getCount());
}
}
Expand Down Expand Up @@ -750,6 +762,23 @@ protected function putStructureEditorData(StructureEditorData $structureEditorDa
$this->putVarInt($structureEditorData->structureRedstoneSaveMove);
}

public function getNbtRoot() : NamedTag{
$offset = $this->getOffset();
try{
return (new NetworkLittleEndianNBTStream())->read($this->getBuffer(), false, $offset, 512);
}finally{
$this->setOffset($offset);
}
}

public function getNbtCompoundRoot() : CompoundTag{
$root = $this->getNbtRoot();
if(!($root instanceof CompoundTag)){
throw new \UnexpectedValueException("Expected TAG_Compound root");
}
return $root;
}

public function readGenericTypeNetworkId() : int{
return $this->getVarInt();
}
Expand Down
40 changes: 30 additions & 10 deletions src/pocketmine/network/mcpe/NetworkSession.php
Expand Up @@ -24,7 +24,6 @@
namespace pocketmine\network\mcpe;

use pocketmine\network\mcpe\protocol\ActorEventPacket;
use pocketmine\network\mcpe\protocol\ActorFallPacket;
use pocketmine\network\mcpe\protocol\ActorPickRequestPacket;
use pocketmine\network\mcpe\protocol\AddActorPacket;
use pocketmine\network\mcpe\protocol\AddBehaviorTreePacket;
Expand All @@ -33,6 +32,7 @@
use pocketmine\network\mcpe\protocol\AddPaintingPacket;
use pocketmine\network\mcpe\protocol\AddPlayerPacket;
use pocketmine\network\mcpe\protocol\AdventureSettingsPacket;
use pocketmine\network\mcpe\protocol\AnimateEntityPacket;
use pocketmine\network\mcpe\protocol\AnimatePacket;
use pocketmine\network\mcpe\protocol\AnvilDamagePacket;
use pocketmine\network\mcpe\protocol\AutomationClientConnectPacket;
Expand All @@ -45,6 +45,7 @@
use pocketmine\network\mcpe\protocol\BookEditPacket;
use pocketmine\network\mcpe\protocol\BossEventPacket;
use pocketmine\network\mcpe\protocol\CameraPacket;
use pocketmine\network\mcpe\protocol\CameraShakePacket;
use pocketmine\network\mcpe\protocol\ChangeDimensionPacket;
use pocketmine\network\mcpe\protocol\ChunkRadiusUpdatedPacket;
use pocketmine\network\mcpe\protocol\ClientboundMapItemDataPacket;
Expand All @@ -60,6 +61,7 @@
use pocketmine\network\mcpe\protocol\ContainerClosePacket;
use pocketmine\network\mcpe\protocol\ContainerOpenPacket;
use pocketmine\network\mcpe\protocol\ContainerSetDataPacket;
use pocketmine\network\mcpe\protocol\CorrectPlayerMovePredictionPacket;
use pocketmine\network\mcpe\protocol\CraftingDataPacket;
use pocketmine\network\mcpe\protocol\CraftingEventPacket;
use pocketmine\network\mcpe\protocol\CreativeContentPacket;
Expand All @@ -77,6 +79,7 @@
use pocketmine\network\mcpe\protocol\InventoryContentPacket;
use pocketmine\network\mcpe\protocol\InventorySlotPacket;
use pocketmine\network\mcpe\protocol\InventoryTransactionPacket;
use pocketmine\network\mcpe\protocol\ItemComponentPacket;
use pocketmine\network\mcpe\protocol\ItemFrameDropItemPacket;
use pocketmine\network\mcpe\protocol\ItemStackRequestPacket;
use pocketmine\network\mcpe\protocol\ItemStackResponsePacket;
Expand All @@ -96,6 +99,7 @@
use pocketmine\network\mcpe\protocol\MobEquipmentPacket;
use pocketmine\network\mcpe\protocol\ModalFormRequestPacket;
use pocketmine\network\mcpe\protocol\ModalFormResponsePacket;
use pocketmine\network\mcpe\protocol\MotionPredictionHintsPacket;
use pocketmine\network\mcpe\protocol\MoveActorAbsolutePacket;
use pocketmine\network\mcpe\protocol\MoveActorDeltaPacket;
use pocketmine\network\mcpe\protocol\MovePlayerPacket;
Expand All @@ -111,6 +115,7 @@
use pocketmine\network\mcpe\protocol\PlayerArmorDamagePacket;
use pocketmine\network\mcpe\protocol\PlayerAuthInputPacket;
use pocketmine\network\mcpe\protocol\PlayerEnchantOptionsPacket;
use pocketmine\network\mcpe\protocol\PlayerFogPacket;
use pocketmine\network\mcpe\protocol\PlayerHotbarPacket;
use pocketmine\network\mcpe\protocol\PlayerInputPacket;
use pocketmine\network\mcpe\protocol\PlayerListPacket;
Expand Down Expand Up @@ -171,7 +176,6 @@
use pocketmine\network\mcpe\protocol\TransferPacket;
use pocketmine\network\mcpe\protocol\UpdateAttributesPacket;
use pocketmine\network\mcpe\protocol\UpdateBlockPacket;
use pocketmine\network\mcpe\protocol\UpdateBlockPropertiesPacket;
use pocketmine\network\mcpe\protocol\UpdateBlockSyncedPacket;
use pocketmine\network\mcpe\protocol\UpdateEquipPacket;
use pocketmine\network\mcpe\protocol\UpdatePlayerGameTypePacket;
Expand Down Expand Up @@ -325,10 +329,6 @@ public function handlePlayerAction(PlayerActionPacket $packet) : bool{
return false;
}

public function handleActorFall(ActorFallPacket $packet) : bool{
return false;
}

public function handleHurtArmor(HurtArmorPacket $packet) : bool{
return false;
}
Expand Down Expand Up @@ -705,10 +705,6 @@ public function handleStructureTemplateDataResponse(StructureTemplateDataRespons
return false;
}

public function handleUpdateBlockProperties(UpdateBlockPropertiesPacket $packet) : bool{
return false;
}

public function handleClientCacheBlobStatus(ClientCacheBlobStatusPacket $packet) : bool{
return false;
}
Expand Down Expand Up @@ -796,4 +792,28 @@ public function handleDebugInfo(DebugInfoPacket $packet) : bool{
public function handlePacketViolationWarning(PacketViolationWarningPacket $packet) : bool{
return false;
}

public function handleMotionPredictionHints(MotionPredictionHintsPacket $packet) : bool{
return false;
}

public function handleAnimateEntity(AnimateEntityPacket $packet) : bool{
return false;
}

public function handleCameraShake(CameraShakePacket $packet) : bool{
return false;
}

public function handlePlayerFog(PlayerFogPacket $packet) : bool{
return false;
}

public function handleCorrectPlayerMovePrediction(CorrectPlayerMovePredictionPacket $packet) : bool{
return false;
}

public function handleItemComponent(ItemComponentPacket $packet) : bool{
return false;
}
}
5 changes: 0 additions & 5 deletions src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter.php
Expand Up @@ -25,7 +25,6 @@

use pocketmine\event\server\DataPacketReceiveEvent;
use pocketmine\network\mcpe\protocol\ActorEventPacket;
use pocketmine\network\mcpe\protocol\ActorFallPacket;
use pocketmine\network\mcpe\protocol\ActorPickRequestPacket;
use pocketmine\network\mcpe\protocol\AdventureSettingsPacket;
use pocketmine\network\mcpe\protocol\AnimatePacket;
Expand Down Expand Up @@ -174,10 +173,6 @@ public function handlePlayerAction(PlayerActionPacket $packet) : bool{
return $this->player->handlePlayerAction($packet);
}

public function handleActorFall(ActorFallPacket $packet) : bool{
return true; //Not used
}

public function handleAnimate(AnimatePacket $packet) : bool{
return $this->player->handleAnimate($packet);
}
Expand Down

0 comments on commit 98cdc80

Please sign in to comment.