mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-15 18:29:46 +00:00
All BlockInventory descendents now have a Position as holder
this allows multiple problems to be solved: 1) Cycle between tile and inventory is now removed. 2) BlockInventory now provides a consistent API for plugins to get the block holding an inventory.
This commit is contained in:
parent
358fea9645
commit
9353f616a2
@ -53,11 +53,11 @@ class BrewingStand extends Spawnable implements Container, Nameable{
|
||||
|
||||
|
||||
public function __construct(World $world, Vector3 $pos){
|
||||
parent::__construct($world, $pos);
|
||||
$this->inventory = new BrewingStandInventory($this);
|
||||
$this->inventory->addChangeListeners(CallbackInventoryChangeListener::onAnyChange(function(Inventory $unused){
|
||||
$this->world->scheduleDelayedBlockUpdate($this->getBlock()->getPos(), 1);
|
||||
}));
|
||||
parent::__construct($world, $pos);
|
||||
}
|
||||
|
||||
public function readSaveData(CompoundTag $nbt) : void{
|
||||
|
@ -54,8 +54,8 @@ class Chest extends Spawnable implements Container, Nameable{
|
||||
private $pairZ;
|
||||
|
||||
public function __construct(World $world, Vector3 $pos){
|
||||
$this->inventory = new ChestInventory($this);
|
||||
parent::__construct($world, $pos);
|
||||
$this->inventory = new ChestInventory($this);
|
||||
}
|
||||
|
||||
public function readSaveData(CompoundTag $nbt) : void{
|
||||
@ -152,9 +152,9 @@ class Chest extends Spawnable implements Container, Nameable{
|
||||
$this->doubleInventory = $pair->doubleInventory;
|
||||
}else{
|
||||
if(($pair->x + ($pair->z << 15)) > ($this->x + ($this->z << 15))){ //Order them correctly
|
||||
$this->doubleInventory = $pair->doubleInventory = new DoubleChestInventory($pair, $this);
|
||||
$this->doubleInventory = $pair->doubleInventory = new DoubleChestInventory($pair->inventory, $this->inventory);
|
||||
}else{
|
||||
$this->doubleInventory = $pair->doubleInventory = new DoubleChestInventory($this, $pair);
|
||||
$this->doubleInventory = $pair->doubleInventory = new DoubleChestInventory($this->inventory, $pair->inventory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,14 +56,13 @@ class Furnace extends Spawnable implements Container, Nameable{
|
||||
private $maxFuelTime = 0;
|
||||
|
||||
public function __construct(World $world, Vector3 $pos){
|
||||
parent::__construct($world, $pos);
|
||||
$this->inventory = new FurnaceInventory($this);
|
||||
$this->inventory->addChangeListeners(CallbackInventoryChangeListener::onAnyChange(
|
||||
function(Inventory $unused) : void{
|
||||
$this->world->scheduleDelayedBlockUpdate($this->asVector3(), 1);
|
||||
})
|
||||
);
|
||||
|
||||
parent::__construct($world, $pos);
|
||||
}
|
||||
|
||||
public function readSaveData(CompoundTag $nbt) : void{
|
||||
|
@ -42,8 +42,8 @@ class Hopper extends Spawnable implements Container, Nameable{
|
||||
private $transferCooldown = 0;
|
||||
|
||||
public function __construct(World $world, Vector3 $pos){
|
||||
$this->inventory = new HopperInventory($this);
|
||||
parent::__construct($world, $pos);
|
||||
$this->inventory = new HopperInventory($this);
|
||||
}
|
||||
|
||||
public function readSaveData(CompoundTag $nbt) : void{
|
||||
|
@ -50,8 +50,8 @@ abstract class Tile extends Position{
|
||||
protected $timings;
|
||||
|
||||
public function __construct(World $world, Vector3 $pos){
|
||||
$this->timings = Timings::getTileEntityTimings($this);
|
||||
parent::__construct($pos->getFloorX(), $pos->getFloorY(), $pos->getFloorZ(), $world);
|
||||
$this->timings = Timings::getTileEntityTimings($this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,19 +28,8 @@ use pocketmine\world\Position;
|
||||
|
||||
class AnvilInventory extends BlockInventory{
|
||||
|
||||
/** @var Position */
|
||||
protected $holder;
|
||||
|
||||
public function __construct(Position $pos){
|
||||
parent::__construct($pos->asPosition(), 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* This override is here for documentation and code completion purposes only.
|
||||
* @return Position
|
||||
*/
|
||||
public function getHolder(){
|
||||
return $this->holder;
|
||||
public function __construct(Position $holder){
|
||||
parent::__construct($holder, 2);
|
||||
}
|
||||
|
||||
public function onClose(Player $who) : void{
|
||||
|
@ -23,19 +23,19 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\inventory;
|
||||
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\world\Position;
|
||||
|
||||
class BlockInventory extends BaseInventory{
|
||||
/** @var Vector3 */
|
||||
/** @var Position */
|
||||
protected $holder;
|
||||
|
||||
public function __construct(Vector3 $holder, int $size){
|
||||
$this->holder = $holder;
|
||||
public function __construct(Position $holder, int $size){
|
||||
$this->holder = $holder->asPosition();
|
||||
parent::__construct($size);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Vector3
|
||||
* @return Position
|
||||
*/
|
||||
public function getHolder(){
|
||||
return $this->holder;
|
||||
|
@ -23,11 +23,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\inventory;
|
||||
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\world\Position;
|
||||
|
||||
class BrewingStandInventory extends BlockInventory{
|
||||
|
||||
public function __construct(Vector3 $holder, int $size = 5){
|
||||
public function __construct(Position $holder, int $size = 5){
|
||||
parent::__construct($holder, $size);
|
||||
}
|
||||
}
|
||||
|
@ -23,9 +23,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\inventory;
|
||||
|
||||
use pocketmine\block\tile\Chest;
|
||||
use pocketmine\network\mcpe\protocol\BlockEventPacket;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\world\Position;
|
||||
use pocketmine\world\sound\ChestCloseSound;
|
||||
use pocketmine\world\sound\ChestOpenSound;
|
||||
use pocketmine\world\sound\Sound;
|
||||
@ -33,22 +33,11 @@ use function count;
|
||||
|
||||
class ChestInventory extends BlockInventory{
|
||||
|
||||
/** @var Chest */
|
||||
protected $holder;
|
||||
|
||||
/**
|
||||
* @param Chest $tile
|
||||
* @param Position $holder
|
||||
*/
|
||||
public function __construct(Chest $tile){
|
||||
parent::__construct($tile, 27);
|
||||
}
|
||||
|
||||
/**
|
||||
* This override is here for documentation and code completion purposes only.
|
||||
* @return Chest
|
||||
*/
|
||||
public function getHolder(){
|
||||
return $this->holder;
|
||||
public function __construct(Position $holder){
|
||||
parent::__construct($holder, 27);
|
||||
}
|
||||
|
||||
protected function getOpenSound() : Sound{
|
||||
|
@ -23,9 +23,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\inventory;
|
||||
|
||||
use pocketmine\block\tile\Chest;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\world\Position;
|
||||
use function count;
|
||||
|
||||
class DoubleChestInventory extends ChestInventory implements InventoryHolder{
|
||||
@ -34,9 +34,9 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{
|
||||
/** @var ChestInventory */
|
||||
private $right;
|
||||
|
||||
public function __construct(Chest $left, Chest $right){
|
||||
$this->left = $left->getRealInventory();
|
||||
$this->right = $right->getRealInventory();
|
||||
public function __construct(ChestInventory $left, ChestInventory $right){
|
||||
$this->left = $left;
|
||||
$this->right = $right;
|
||||
BaseInventory::__construct($this->left->getSize() + $this->right->getSize());
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Chest
|
||||
* @return Position
|
||||
*/
|
||||
public function getHolder(){
|
||||
return $this->left->getHolder();
|
||||
|
@ -28,19 +28,8 @@ use pocketmine\world\Position;
|
||||
|
||||
class EnchantInventory extends BlockInventory{
|
||||
|
||||
/** @var Position */
|
||||
protected $holder;
|
||||
|
||||
public function __construct(Position $pos){
|
||||
parent::__construct($pos->asPosition(), 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* This override is here for documentation and code completion purposes only.
|
||||
* @return Position
|
||||
*/
|
||||
public function getHolder(){
|
||||
return $this->holder;
|
||||
public function __construct(Position $holder){
|
||||
parent::__construct($holder, 2);
|
||||
}
|
||||
|
||||
public function onClose(Player $who) : void{
|
||||
|
@ -23,7 +23,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\inventory;
|
||||
|
||||
use pocketmine\block\tile\EnderChest;
|
||||
use pocketmine\world\Position;
|
||||
use pocketmine\world\sound\EnderChestCloseSound;
|
||||
use pocketmine\world\sound\EnderChestOpenSound;
|
||||
@ -31,21 +30,15 @@ use pocketmine\world\sound\Sound;
|
||||
|
||||
class EnderChestInventory extends ChestInventory{
|
||||
|
||||
/** @var Position */
|
||||
protected $holder;
|
||||
|
||||
public function __construct(){
|
||||
BlockInventory::__construct(new Position(), 27);
|
||||
parent::__construct(new Position(0, 0, 0, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the holder's position to that of a tile
|
||||
*
|
||||
* @param EnderChest $enderChest
|
||||
* @param Position $pos
|
||||
*/
|
||||
public function setHolderPosition(EnderChest $enderChest) : void{
|
||||
$this->holder->setComponents($enderChest->getFloorX(), $enderChest->getFloorY(), $enderChest->getFloorZ());
|
||||
$this->holder->setWorld($enderChest->getWorld());
|
||||
public function setHolderPosition(Position $pos) : void{
|
||||
$this->holder = $pos->asPosition();
|
||||
}
|
||||
|
||||
protected function getOpenSound() : Sound{
|
||||
@ -55,12 +48,4 @@ class EnderChestInventory extends ChestInventory{
|
||||
protected function getCloseSound() : Sound{
|
||||
return new EnderChestCloseSound();
|
||||
}
|
||||
|
||||
/**
|
||||
* This override is here for documentation and code completion purposes only.
|
||||
* @return Position
|
||||
*/
|
||||
public function getHolder(){
|
||||
return $this->holder;
|
||||
}
|
||||
}
|
||||
|
@ -23,23 +23,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\inventory;
|
||||
|
||||
use pocketmine\block\tile\Furnace;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\world\Position;
|
||||
|
||||
class FurnaceInventory extends BlockInventory{
|
||||
/** @var Furnace */
|
||||
protected $holder;
|
||||
|
||||
public function __construct(Furnace $tile){
|
||||
parent::__construct($tile, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* This override is here for documentation and code completion purposes only.
|
||||
* @return Furnace
|
||||
*/
|
||||
public function getHolder(){
|
||||
return $this->holder;
|
||||
public function __construct(Position $holder){
|
||||
parent::__construct($holder, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -23,11 +23,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\inventory;
|
||||
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\world\Position;
|
||||
|
||||
class HopperInventory extends BlockInventory{
|
||||
|
||||
public function __construct(Vector3 $holder, int $size = 5){
|
||||
public function __construct(Position $holder, int $size = 5){
|
||||
parent::__construct($holder, $size);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user