26 private string $blockName;
36 private string $recipeId,
38 private array $output,
39 private UuidInterface $uuid,
41 private int $priority,
42 private bool $symmetric,
44 private int $recipeNetId
46 parent::__construct($typeId);
47 $rows = count($input);
48 if($rows < 1 or $rows > 3){
49 throw new \InvalidArgumentException(
"Expected 1, 2 or 3 input rows");
52 foreach($input as $rowNumber => $row){
53 if($columns ===
null){
54 $columns = count($row);
55 }elseif(count($row) !== $columns){
56 throw new \InvalidArgumentException(
"Expected each row to be $columns columns, but have " . count($row) .
" in row $rowNumber");
59 $this->blockName = $blockType;
62 public function getRecipeId() : string{
63 return $this->recipeId;
66 public function getWidth() : int{
67 return count($this->input[0]);
70 public function getHeight() : int{
71 return count($this->input);
90 public function getUuid() : UuidInterface{
94 public function getBlockName() : string{
95 return $this->blockName;
98 public function getPriority() : int{
99 return $this->priority;
102 public function isSymmetric() : bool{ return $this->symmetric; }
104 public function getUnlockingRequirement() : RecipeUnlockingRequirement{ return $this->unlockingRequirement; }
106 public function getRecipeNetId() : int{
107 return $this->recipeNetId;
110 public static function decode(
int $recipeType, ByteBufferReader $in) : self{
111 $recipeId = CommonTypes::getString($in);
112 $width = VarInt::readSignedInt($in);
113 $height = VarInt::readSignedInt($in);
115 for($row = 0; $row < $height; ++$row){
116 for($column = 0; $column < $width; ++$column){
117 $input[$row][$column] = CommonTypes::getRecipeIngredient($in);
122 for($k = 0, $resultCount = VarInt::readUnsignedInt($in); $k < $resultCount; ++$k){
123 $output[] = CommonTypes::getItemStackWithoutStackId($in);
125 $uuid = CommonTypes::getUUID($in);
126 $block = CommonTypes::getString($in);
127 $priority = VarInt::readSignedInt($in);
128 $symmetric = CommonTypes::getBool($in);
129 $unlockingRequirement = RecipeUnlockingRequirement::read($in);
131 $recipeNetId = CommonTypes::readRecipeNetId($in);
133 return new self($recipeType, $recipeId, $input, $output, $uuid, $block, $priority, $symmetric, $unlockingRequirement, $recipeNetId);
136 public function encode(ByteBufferWriter $out) : void{
137 CommonTypes::putString($out, $this->recipeId);
138 VarInt::writeSignedInt($out, $this->getWidth());
139 VarInt::writeSignedInt($out, $this->getHeight());
140 foreach($this->input as $row){
141 foreach($row as $ingredient){
142 CommonTypes::putRecipeIngredient($out, $ingredient);
146 VarInt::writeUnsignedInt($out, count($this->output));
147 foreach($this->output as $item){
148 CommonTypes::putItemStackWithoutStackId($out, $item);
151 CommonTypes::putUUID($out, $this->uuid);
152 CommonTypes::putString($out, $this->blockName);
153 VarInt::writeSignedInt($out, $this->priority);
154 CommonTypes::putBool($out, $this->symmetric);
155 $this->unlockingRequirement->write($out);
157 CommonTypes::writeRecipeNetId($out, $this->recipeNetId);
__construct(int $typeId, private string $recipeId, private array $input, private array $output, private UuidInterface $uuid, string $blockType, private int $priority, private bool $symmetric, private RecipeUnlockingRequirement $unlockingRequirement, private int $recipeNetId)