PocketMine-MP 5.43.3 git-4e2b0ce88fd28aa124b51efe324b94ceebb999fe
Loading...
Searching...
No Matches
vendor/pocketmine/bedrock-protocol/src/types/recipe/ShapelessRecipe.php
1<?php
2
3/*
4 * This file is part of BedrockProtocol.
5 * Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
6 *
7 * BedrockProtocol is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
13declare(strict_types=1);
14
15namespace pocketmine\network\mcpe\protocol\types\recipe;
16
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\VarInt;
22use Ramsey\Uuid\UuidInterface;
23use function count;
24
32 public function __construct(
33 int $typeId,
34 private string $recipeId,
35 private array $inputs,
36 private array $outputs,
37 private UuidInterface $uuid,
38 private string $blockName,
39 private int $priority,
40 private RecipeUnlockingRequirement $unlockingRequirement,
41 private int $recipeNetId
42 ){
43 parent::__construct($typeId);
44 }
45
46 public function getRecipeId() : string{
47 return $this->recipeId;
48 }
49
54 public function getInputs() : array{
55 return $this->inputs;
56 }
57
62 public function getOutputs() : array{
63 return $this->outputs;
64 }
65
66 public function getUuid() : UuidInterface{
67 return $this->uuid;
68 }
69
70 public function getBlockName() : string{
71 return $this->blockName;
72 }
73
74 public function getPriority() : int{
75 return $this->priority;
76 }
77
78 public function getUnlockingRequirement() : RecipeUnlockingRequirement{ return $this->unlockingRequirement; }
79
80 public function getRecipeNetId() : int{
81 return $this->recipeNetId;
82 }
83
84 public static function decode(int $recipeType, ByteBufferReader $in) : self{
85 $recipeId = CommonTypes::getString($in);
86 $input = [];
87 for($j = 0, $ingredientCount = VarInt::readUnsignedInt($in); $j < $ingredientCount; ++$j){
88 $input[] = CommonTypes::getRecipeIngredient($in);
89 }
90 $output = [];
91 for($k = 0, $resultCount = VarInt::readUnsignedInt($in); $k < $resultCount; ++$k){
92 $output[] = CommonTypes::getItemStackWithoutStackId($in);
93 }
94 $uuid = CommonTypes::getUUID($in);
95 $block = CommonTypes::getString($in);
96 $priority = VarInt::readSignedInt($in);
97 $unlockingRequirement = RecipeUnlockingRequirement::read($in);
98
99 $recipeNetId = CommonTypes::readRecipeNetId($in);
100
101 return new self($recipeType, $recipeId, $input, $output, $uuid, $block, $priority, $unlockingRequirement, $recipeNetId);
102 }
103
104 public function encode(ByteBufferWriter $out) : void{
105 CommonTypes::putString($out, $this->recipeId);
106 VarInt::writeUnsignedInt($out, count($this->inputs));
107 foreach($this->inputs as $item){
108 CommonTypes::putRecipeIngredient($out, $item);
109 }
110
111 VarInt::writeUnsignedInt($out, count($this->outputs));
112 foreach($this->outputs as $item){
113 CommonTypes::putItemStackWithoutStackId($out, $item);
114 }
115
116 CommonTypes::putUUID($out, $this->uuid);
117 CommonTypes::putString($out, $this->blockName);
118 VarInt::writeSignedInt($out, $this->priority);
119 $this->unlockingRequirement->write($out);
120
121 CommonTypes::writeRecipeNetId($out, $this->recipeNetId);
122 }
123}
__construct(int $typeId, private string $recipeId, private array $inputs, private array $outputs, private UuidInterface $uuid, private string $blockName, private int $priority, private RecipeUnlockingRequirement $unlockingRequirement, private int $recipeNetId)