mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 18:32:55 +00:00
Read recipes from json
This commit is contained in:
@ -42,32 +42,17 @@ class ShapedRecipe implements Recipe{
|
||||
|
||||
/**
|
||||
* @param Item $result
|
||||
* @param string[] $shape
|
||||
* @param int $height
|
||||
* @param int $width
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct(Item $result, ...$shape){
|
||||
if(count($shape) === 0){
|
||||
throw new \InvalidArgumentException("Must provide a shape");
|
||||
}
|
||||
if(count($shape) > 3){
|
||||
throw new \InvalidStateException("Crafting recipes should be 1, 2, 3 rows, not " . count($shape));
|
||||
}
|
||||
foreach($shape as $y => $row){
|
||||
if(strlen($row) === 0 or strlen($row) > 3){
|
||||
public function __construct(Item $result, $height, $width){
|
||||
for($h =0; $h < $height; $h++){
|
||||
if(strlen($width) === 0 or strlen($width) > 3){
|
||||
throw new \InvalidStateException("Crafting rows should be 1, 2, 3 characters, not " . count($row));
|
||||
}
|
||||
$this->ingredients[] = array_fill(0, strlen($row), null);
|
||||
$len = strlen($row);
|
||||
for($i = 0; $i < $len; ++$i){
|
||||
$this->shape[$row{$i}] = null;
|
||||
|
||||
if(!isset($this->shapeItems[$row{$i}])){
|
||||
$this->shapeItems[$row{$i}] = [new Vector2($i, $y)];
|
||||
}else{
|
||||
$this->shapeItems[$row{$i}][] = new Vector2($i, $y);
|
||||
}
|
||||
}
|
||||
$this->ingredients[] = array_fill(0, $width, null);
|
||||
}
|
||||
|
||||
$this->output = clone $result;
|
||||
@ -97,6 +82,11 @@ class ShapedRecipe implements Recipe{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
public function addIngredient($x, $y, Item $item){
|
||||
$this->ingredients[$y][$x] = clone $item;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param Item $item
|
||||
|
Reference in New Issue
Block a user