From d8188b807a3d3e708c32483f463342da12d8f3a1 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 30 Nov 2019 21:18:54 +0000 Subject: [PATCH] CraftingDataPacket: read & write potion recipes --- .../mcpe/protocol/CraftingDataPacket.php | 30 +++++++++++ .../types/PotionContainerChangeRecipe.php | 51 +++++++++++++++++++ .../mcpe/protocol/types/PotionTypeRecipe.php | 51 +++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 src/pocketmine/network/mcpe/protocol/types/PotionContainerChangeRecipe.php create mode 100644 src/pocketmine/network/mcpe/protocol/types/PotionTypeRecipe.php diff --git a/src/pocketmine/network/mcpe/protocol/CraftingDataPacket.php b/src/pocketmine/network/mcpe/protocol/CraftingDataPacket.php index bb5f7cd8f..a05d2bc27 100644 --- a/src/pocketmine/network/mcpe/protocol/CraftingDataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/CraftingDataPacket.php @@ -33,6 +33,8 @@ use pocketmine\item\Item; use pocketmine\item\ItemFactory; use pocketmine\network\mcpe\NetworkBinaryStream; use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\protocol\types\PotionContainerChangeRecipe; +use pocketmine\network\mcpe\protocol\types\PotionTypeRecipe; #ifndef COMPILE use pocketmine\utils\Binary; #endif @@ -53,6 +55,10 @@ class CraftingDataPacket extends DataPacket{ /** @var object[] */ public $entries = []; + /** @var PotionTypeRecipe[] */ + public $potionTypeRecipes = []; + /** @var PotionContainerChangeRecipe[] */ + public $potionContainerRecipes = []; /** @var bool */ public $cleanRecipes = false; @@ -140,6 +146,18 @@ class CraftingDataPacket extends DataPacket{ } $this->decodedEntries[] = $entry; } + for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){ + $input = $this->getVarInt(); + $ingredient = $this->getVarInt(); + $output = $this->getVarInt(); + $this->potionTypeRecipes[] = new PotionTypeRecipe($input, $ingredient, $output); + } + for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){ + $input = $this->getVarInt(); + $ingredient = $this->getVarInt(); + $output = $this->getVarInt(); + $this->potionContainerRecipes[] = new PotionContainerChangeRecipe($input, $ingredient, $output); + } $this->cleanRecipes = $this->getBool(); } @@ -240,6 +258,18 @@ class CraftingDataPacket extends DataPacket{ $writer->reset(); } + $this->putUnsignedVarInt(count($this->potionTypeRecipes)); + foreach($this->potionTypeRecipes as $recipe){ + $this->putVarInt($recipe->getInputPotionType()); + $this->putVarInt($recipe->getIngredientItemId()); + $this->putVarInt($recipe->getOutputPotionType()); + } + $this->putUnsignedVarInt(count($this->potionContainerRecipes)); + foreach($this->potionContainerRecipes as $recipe){ + $this->putVarInt($recipe->getInputItemId()); + $this->putVarInt($recipe->getIngredientItemId()); + $this->putVarInt($recipe->getOutputItemId()); + } $this->putBool($this->cleanRecipes); } diff --git a/src/pocketmine/network/mcpe/protocol/types/PotionContainerChangeRecipe.php b/src/pocketmine/network/mcpe/protocol/types/PotionContainerChangeRecipe.php new file mode 100644 index 000000000..8d3ad196e --- /dev/null +++ b/src/pocketmine/network/mcpe/protocol/types/PotionContainerChangeRecipe.php @@ -0,0 +1,51 @@ +inputItemId = $inputItemId; + $this->ingredientItemId = $ingredientItemId; + $this->outputItemId = $outputItemId; + } + + public function getInputItemId() : int{ + return $this->inputItemId; + } + + public function getIngredientItemId() : int{ + return $this->ingredientItemId; + } + + public function getOutputItemId() : int{ + return $this->outputItemId; + } +} \ No newline at end of file diff --git a/src/pocketmine/network/mcpe/protocol/types/PotionTypeRecipe.php b/src/pocketmine/network/mcpe/protocol/types/PotionTypeRecipe.php new file mode 100644 index 000000000..faacb6bf1 --- /dev/null +++ b/src/pocketmine/network/mcpe/protocol/types/PotionTypeRecipe.php @@ -0,0 +1,51 @@ +inputPotionType = $inputPotionType; + $this->ingredientItemId = $ingredientItemId; + $this->outputPotionType = $outputPotionType; + } + + public function getInputPotionType() : int{ + return $this->inputPotionType; + } + + public function getIngredientItemId() : int{ + return $this->ingredientItemId; + } + + public function getOutputPotionType() : int{ + return $this->outputPotionType; + } +} \ No newline at end of file