mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-13 01:09:44 +00:00
Clean up whitespace disaster and add getIngredient back
This commit is contained in:
parent
bfb1ad1327
commit
6a31628e78
@ -39,10 +39,11 @@ class CraftingGrid extends BaseInventory{
|
|||||||
/** @var int */
|
/** @var int */
|
||||||
public $offset;
|
public $offset;
|
||||||
/** @var Player */
|
/** @var Player */
|
||||||
private $holder;
|
protected $holder;
|
||||||
|
|
||||||
/** @var int */
|
/** @var int */
|
||||||
private $gridWidth;
|
private $gridWidth;
|
||||||
|
|
||||||
/** @var int|null */
|
/** @var int|null */
|
||||||
private $startX;
|
private $startX;
|
||||||
/** @var int|null */
|
/** @var int|null */
|
||||||
@ -86,8 +87,10 @@ class CraftingGrid extends BaseInventory{
|
|||||||
public function setItem(int $index, Item $item, bool $send = true) : bool{
|
public function setItem(int $index, Item $item, bool $send = true) : bool{
|
||||||
if(parent::setItem($index + $this->offset, $item, $send)){
|
if(parent::setItem($index + $this->offset, $item, $send)){
|
||||||
$this->seekRecipeBounds();
|
$this->seekRecipeBounds();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,20 +112,26 @@ class CraftingGrid extends BaseInventory{
|
|||||||
private function seekRecipeBounds() : void{
|
private function seekRecipeBounds() : void{
|
||||||
$minX = PHP_INT_MAX;
|
$minX = PHP_INT_MAX;
|
||||||
$maxX = 0;
|
$maxX = 0;
|
||||||
|
|
||||||
$minY = PHP_INT_MAX;
|
$minY = PHP_INT_MAX;
|
||||||
$maxY = 0;
|
$maxY = 0;
|
||||||
|
|
||||||
$empty = true;
|
$empty = true;
|
||||||
|
|
||||||
for($y = 0; $y < $this->gridWidth; ++$y){
|
for($y = 0; $y < $this->gridWidth; ++$y){
|
||||||
for($x = 0; $x < $this->gridWidth; ++$x){
|
for($x = 0; $x < $this->gridWidth; ++$x){
|
||||||
if(!$this->isSlotEmpty($y * $this->gridWidth + $x)){
|
if(!$this->isSlotEmpty($y * $this->gridWidth + $x)){
|
||||||
$minX = min($minX, $x);
|
$minX = min($minX, $x);
|
||||||
$maxX = max($maxX, $x);
|
$maxX = max($maxX, $x);
|
||||||
|
|
||||||
$minY = min($minY, $y);
|
$minY = min($minY, $y);
|
||||||
$maxY = max($maxY, $y);
|
$maxY = max($maxY, $y);
|
||||||
|
|
||||||
$empty = false;
|
$empty = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$empty){
|
if(!$empty){
|
||||||
$this->startX = $minX;
|
$this->startX = $minX;
|
||||||
$this->xLen = $maxX - $minX + 1;
|
$this->xLen = $maxX - $minX + 1;
|
||||||
@ -133,6 +142,22 @@ class CraftingGrid extends BaseInventory{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the item at offset x,y, offset by where the starts of the recipe rectangle are.
|
||||||
|
*
|
||||||
|
* @param int $x
|
||||||
|
* @param int $y
|
||||||
|
*
|
||||||
|
* @return Item
|
||||||
|
*/
|
||||||
|
public function getIngredient(int $x, int $y) : Item{
|
||||||
|
if($this->startX !== null and $this->startY !== null){
|
||||||
|
return $this->getItem(($y + $this->startY) * $this->gridWidth + ($x + $this->startX));
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new \InvalidStateException("No ingredients found in grid");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the width of the recipe we're trying to craft, based on items currently in the grid.
|
* Returns the width of the recipe we're trying to craft, based on items currently in the grid.
|
||||||
*
|
*
|
||||||
|
@ -26,11 +26,8 @@ namespace pocketmine\inventory;
|
|||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
|
|
||||||
class PlayerCursorInventory extends BaseInventory{
|
class PlayerCursorInventory extends BaseInventory{
|
||||||
|
|
||||||
/** @var Player */
|
/** @var Player */
|
||||||
protected $holder;
|
protected $holder;
|
||||||
/** @var int */
|
|
||||||
protected $offset = 0;
|
|
||||||
|
|
||||||
public function __construct(Player $holder){
|
public function __construct(Player $holder){
|
||||||
$this->holder = $holder;
|
$this->holder = $holder;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user