mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 00:39:45 +00:00
CraftingDataPacket: read & write potion recipes
This commit is contained in:
parent
8e68655fc7
commit
d8188b807a
@ -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);
|
||||
}
|
||||
|
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\network\mcpe\protocol\types;
|
||||
|
||||
class PotionContainerChangeRecipe{
|
||||
/** @var int */
|
||||
private $inputItemId;
|
||||
/** @var int */
|
||||
private $ingredientItemId;
|
||||
/** @var int */
|
||||
private $outputItemId;
|
||||
|
||||
public function __construct(int $inputItemId, int $ingredientItemId, int $outputItemId){
|
||||
$this->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;
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\network\mcpe\protocol\types;
|
||||
|
||||
class PotionTypeRecipe{
|
||||
/** @var int */
|
||||
private $inputPotionType;
|
||||
/** @var int */
|
||||
private $ingredientItemId;
|
||||
/** @var int */
|
||||
private $outputPotionType;
|
||||
|
||||
public function __construct(int $inputPotionType, int $ingredientItemId, int $outputPotionType){
|
||||
$this->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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user