mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 16:51:42 +00:00
BlockInventoryTrait: include a Block ref instead of Position
This commit is contained in:
parent
9e6e5082cd
commit
3ee78e20a5
@ -83,7 +83,7 @@ class Anvil extends Transparent implements Fallable{
|
||||
|
||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
||||
if($player instanceof Player){
|
||||
$player->setCurrentWindow(new AnvilInventoryWindow($player, $this->position));
|
||||
$player->setCurrentWindow(new AnvilInventoryWindow($player, $this));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -89,7 +89,7 @@ class Barrel extends Opaque implements AnimatedContainer{
|
||||
return true;
|
||||
}
|
||||
|
||||
$player->setCurrentWindow(new BlockInventoryWindow($player, $barrel->getInventory(), $this->position));
|
||||
$player->setCurrentWindow(new BlockInventoryWindow($player, $barrel->getInventory(), $this));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ class BrewingStand extends Transparent{
|
||||
if($player instanceof Player){
|
||||
$stand = $this->position->getWorld()->getTile($this->position);
|
||||
if($stand instanceof TileBrewingStand && $stand->canOpenWith($item->getCustomName())){
|
||||
$player->setCurrentWindow(new BrewingStandInventoryWindow($player, $stand->getInventory(), $this->position));
|
||||
$player->setCurrentWindow(new BrewingStandInventoryWindow($player, $stand->getInventory(), $this));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ final class CartographyTable extends Opaque{
|
||||
|
||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
||||
if($player !== null){
|
||||
$player->setCurrentWindow(new CartographyTableInventoryWindow($player, $this->position));
|
||||
$player->setCurrentWindow(new CartographyTableInventoryWindow($player, $this));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -117,7 +117,7 @@ class Chest extends Transparent implements AnimatedContainer{
|
||||
}
|
||||
|
||||
if($pair !== null){
|
||||
[$left, $right] = $pairOnLeft ? [$pair->getPosition(), $this->position] : [$this->position, $pair->getPosition()];
|
||||
[$left, $right] = $pairOnLeft ? [$pair->getBlock(), $this] : [$this, $pair->getBlock()];
|
||||
|
||||
//TODO: we should probably construct DoubleChestInventory here directly too using the same logic
|
||||
//right now it uses some weird logic in TileChest which produces incorrect results
|
||||
@ -125,7 +125,7 @@ class Chest extends Transparent implements AnimatedContainer{
|
||||
$window = new DoubleChestInventoryWindow($player, $chest->getInventory(), $left, $right);
|
||||
}
|
||||
|
||||
$player->setCurrentWindow($window ?? new BlockInventoryWindow($player, $chest->getInventory(), $this->position));
|
||||
$player->setCurrentWindow($window ?? new BlockInventoryWindow($player, $chest->getInventory(), $this));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ class CraftingTable extends Opaque{
|
||||
|
||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
||||
if($player instanceof Player){
|
||||
$player->setCurrentWindow(new CraftingTableInventoryWindow($player, $this->position));
|
||||
$player->setCurrentWindow(new CraftingTableInventoryWindow($player, $this));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -48,7 +48,7 @@ class EnchantingTable extends Transparent{
|
||||
if($player instanceof Player){
|
||||
//TODO lock
|
||||
|
||||
$player->setCurrentWindow(new EnchantingTableInventoryWindow($player, $this->position));
|
||||
$player->setCurrentWindow(new EnchantingTableInventoryWindow($player, $this));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -68,7 +68,7 @@ class EnderChest extends Transparent implements AnimatedContainer{
|
||||
if($player instanceof Player){
|
||||
$enderChest = $this->position->getWorld()->getTile($this->position);
|
||||
if($enderChest instanceof TileEnderChest && $this->getSide(Facing::UP)->isTransparent()){
|
||||
$player->setCurrentWindow(new BlockInventoryWindow($player, $player->getEnderInventory(), $this->position));
|
||||
$player->setCurrentWindow(new BlockInventoryWindow($player, $player->getEnderInventory(), $this));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ class Furnace extends Opaque{
|
||||
if($player instanceof Player){
|
||||
$furnace = $this->position->getWorld()->getTile($this->position);
|
||||
if($furnace instanceof TileFurnace && $furnace->canOpenWith($item->getCustomName())){
|
||||
$player->setCurrentWindow(new FurnaceInventoryWindow($player, $furnace->getInventory(), $this->position, $this->furnaceType));
|
||||
$player->setCurrentWindow(new FurnaceInventoryWindow($player, $furnace->getInventory(), $this, $this->furnaceType));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ class Hopper extends Transparent{
|
||||
if($player !== null){
|
||||
$tile = $this->position->getWorld()->getTile($this->position);
|
||||
if($tile instanceof TileHopper){ //TODO: find a way to have inventories open on click without this boilerplate in every block
|
||||
$player->setCurrentWindow(new HopperInventoryWindow($player, $tile->getInventory(), $this->position));
|
||||
$player->setCurrentWindow(new HopperInventoryWindow($player, $tile->getInventory(), $this));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ final class Loom extends Opaque{
|
||||
|
||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
||||
if($player !== null){
|
||||
$player->setCurrentWindow(new LoomInventoryWindow($player, $this->position));
|
||||
$player->setCurrentWindow(new LoomInventoryWindow($player, $this));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -115,7 +115,7 @@ class ShulkerBox extends Opaque implements AnimatedContainer{
|
||||
return true;
|
||||
}
|
||||
|
||||
$player->setCurrentWindow(new BlockInventoryWindow($player, $shulker->getInventory(), $this->position));
|
||||
$player->setCurrentWindow(new BlockInventoryWindow($player, $shulker->getInventory(), $this));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ final class SmithingTable extends Opaque{
|
||||
|
||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
||||
if($player !== null){
|
||||
$player->setCurrentWindow(new SmithingTableInventoryWindow($player, $this->position));
|
||||
$player->setCurrentWindow(new SmithingTableInventoryWindow($player, $this));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -37,7 +37,7 @@ class Stonecutter extends Transparent{
|
||||
|
||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
||||
if($player !== null){
|
||||
$player->setCurrentWindow(new StonecutterInventoryWindow($player, $this->position));
|
||||
$player->setCurrentWindow(new StonecutterInventoryWindow($player, $this));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -23,10 +23,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory\window;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\inventory\SimpleInventory;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\player\TemporaryInventoryWindow;
|
||||
use pocketmine\world\Position;
|
||||
|
||||
final class AnvilInventoryWindow extends BlockInventoryWindow implements TemporaryInventoryWindow{
|
||||
public const SLOT_INPUT = 0;
|
||||
@ -34,7 +34,7 @@ final class AnvilInventoryWindow extends BlockInventoryWindow implements Tempora
|
||||
|
||||
public function __construct(
|
||||
Player $viewer,
|
||||
Position $holder
|
||||
Block $holder
|
||||
){
|
||||
parent::__construct($viewer, new SimpleInventory(2), $holder);
|
||||
}
|
||||
|
@ -23,36 +23,34 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory\window;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\utils\AnimatedContainer;
|
||||
use pocketmine\inventory\Inventory;
|
||||
use pocketmine\player\InventoryWindow;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\world\Position;
|
||||
|
||||
class BlockInventoryWindow extends InventoryWindow{
|
||||
|
||||
public function __construct(
|
||||
Player $viewer,
|
||||
Inventory $inventory,
|
||||
protected Position $holder
|
||||
protected Block $holder
|
||||
){
|
||||
parent::__construct($viewer, $inventory);
|
||||
}
|
||||
|
||||
public function getHolder() : Position{ return $this->holder; }
|
||||
public function getHolder() : Block{ return $this->holder; }
|
||||
|
||||
public function onOpen() : void{
|
||||
parent::onOpen();
|
||||
$block = $this->holder->getWorld()->getBlock($this->holder);
|
||||
if($block instanceof AnimatedContainer){
|
||||
$block->onContainerOpen();
|
||||
if($this->holder instanceof AnimatedContainer){
|
||||
$this->holder->onContainerOpen();
|
||||
}
|
||||
}
|
||||
|
||||
public function onClose() : void{
|
||||
$block = $this->holder->getWorld()->getBlock($this->holder);
|
||||
if($block instanceof AnimatedContainer){
|
||||
$block->onContainerClose();
|
||||
if($this->holder instanceof AnimatedContainer){
|
||||
$this->holder->onContainerClose();
|
||||
}
|
||||
parent::onClose();
|
||||
}
|
||||
|
@ -23,16 +23,16 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory\window;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\inventory\SimpleInventory;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\player\TemporaryInventoryWindow;
|
||||
use pocketmine\world\Position;
|
||||
|
||||
final class CartographyTableInventoryWindow extends BlockInventoryWindow implements TemporaryInventoryWindow{
|
||||
|
||||
public function __construct(
|
||||
Player $viewer,
|
||||
Position $holder
|
||||
Block $holder
|
||||
){
|
||||
parent::__construct($viewer, new SimpleInventory(2), $holder);
|
||||
}
|
||||
|
@ -23,15 +23,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory\window;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\crafting\CraftingGrid;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\world\Position;
|
||||
|
||||
final class CraftingTableInventoryWindow extends BlockInventoryWindow{
|
||||
|
||||
public function __construct(
|
||||
Player $viewer,
|
||||
Position $holder
|
||||
Block $holder
|
||||
){
|
||||
//TODO: generics would be good for this, since it has special methods
|
||||
parent::__construct($viewer, new CraftingGrid(CraftingGrid::SIZE_BIG), $holder);
|
||||
|
@ -23,22 +23,22 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory\window;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\inventory\Inventory;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\world\Position;
|
||||
|
||||
final class DoubleChestInventoryWindow extends BlockInventoryWindow{
|
||||
|
||||
public function __construct(
|
||||
Player $viewer,
|
||||
Inventory $inventory,
|
||||
private Position $left,
|
||||
private Position $right
|
||||
private Block $left,
|
||||
private Block $right
|
||||
){
|
||||
parent::__construct($viewer, $inventory, $this->left);
|
||||
}
|
||||
|
||||
public function getLeft() : Position{ return $this->left; }
|
||||
public function getLeft() : Block{ return $this->left; }
|
||||
|
||||
public function getRight() : Position{ return $this->right; }
|
||||
public function getRight() : Block{ return $this->right; }
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory\window;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\event\player\PlayerEnchantingOptionsRequestEvent;
|
||||
use pocketmine\inventory\CallbackInventoryListener;
|
||||
use pocketmine\inventory\Inventory;
|
||||
@ -32,7 +33,6 @@ use pocketmine\item\enchantment\EnchantingHelper as Helper;
|
||||
use pocketmine\item\enchantment\EnchantingOption;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\world\Position;
|
||||
use function array_values;
|
||||
use function count;
|
||||
|
||||
@ -47,7 +47,7 @@ final class EnchantingTableInventoryWindow extends BlockInventoryWindow{
|
||||
|
||||
public function __construct(
|
||||
Player $viewer,
|
||||
Position $holder
|
||||
Block $holder
|
||||
){
|
||||
parent::__construct($viewer, new SimpleInventory(2), $holder);
|
||||
|
||||
@ -75,7 +75,7 @@ final class EnchantingTableInventoryWindow extends BlockInventoryWindow{
|
||||
private function regenerateOptions() : void{
|
||||
$this->options = [];
|
||||
$item = $this->getInput();
|
||||
$options = Helper::generateOptions($this->holder, $item, $this->viewer->getEnchantmentSeed());
|
||||
$options = Helper::generateOptions($this->holder->getPosition(), $item, $this->viewer->getEnchantmentSeed());
|
||||
|
||||
$event = new PlayerEnchantingOptionsRequestEvent($this->viewer, $this, $options);
|
||||
$event->call();
|
||||
|
@ -23,11 +23,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory\window;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\crafting\FurnaceType;
|
||||
use pocketmine\inventory\Inventory;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\world\Position;
|
||||
|
||||
final class FurnaceInventoryWindow extends BlockInventoryWindow{
|
||||
public const SLOT_INPUT = 0;
|
||||
@ -37,7 +37,7 @@ final class FurnaceInventoryWindow extends BlockInventoryWindow{
|
||||
public function __construct(
|
||||
Player $viewer,
|
||||
Inventory $inventory,
|
||||
Position $holder,
|
||||
Block $holder,
|
||||
private FurnaceType $furnaceType
|
||||
){
|
||||
parent::__construct($viewer, $inventory, $holder);
|
||||
|
@ -23,10 +23,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory\window;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\inventory\SimpleInventory;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\player\TemporaryInventoryWindow;
|
||||
use pocketmine\world\Position;
|
||||
|
||||
final class LoomInventoryWindow extends BlockInventoryWindow implements TemporaryInventoryWindow{
|
||||
|
||||
@ -36,7 +36,7 @@ final class LoomInventoryWindow extends BlockInventoryWindow implements Temporar
|
||||
|
||||
public function __construct(
|
||||
Player $viewer,
|
||||
Position $holder
|
||||
Block $holder
|
||||
){
|
||||
parent::__construct($viewer, new SimpleInventory(3), $holder);
|
||||
}
|
||||
|
@ -23,13 +23,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory\window;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\inventory\SimpleInventory;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\player\TemporaryInventoryWindow;
|
||||
use pocketmine\world\Position;
|
||||
|
||||
final class SmithingTableInventoryWindow extends BlockInventoryWindow implements TemporaryInventoryWindow{
|
||||
public function __construct(Player $viewer, Position $holder){
|
||||
public function __construct(Player $viewer, Block $holder){
|
||||
parent::__construct($viewer, new SimpleInventory(3), $holder);
|
||||
}
|
||||
}
|
||||
|
@ -23,15 +23,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory\window;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\inventory\SimpleInventory;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\player\TemporaryInventoryWindow;
|
||||
use pocketmine\world\Position;
|
||||
|
||||
final class StonecutterInventoryWindow extends BlockInventoryWindow implements TemporaryInventoryWindow{
|
||||
public const SLOT_INPUT = 0;
|
||||
|
||||
public function __construct(Player $viewer, Position $holder){
|
||||
public function __construct(Player $viewer, Block $holder){
|
||||
parent::__construct($viewer, new SimpleInventory(1), $holder);
|
||||
}
|
||||
}
|
||||
|
@ -382,7 +382,7 @@ class InventoryManager implements InventoryListener{
|
||||
//TODO: we should be using some kind of tagging system to identify the types. Instanceof is flaky especially
|
||||
//if the class isn't final, not to mention being inflexible.
|
||||
if($window instanceof BlockInventoryWindow){
|
||||
$blockPosition = BlockPosition::fromVector3($window->getHolder());
|
||||
$blockPosition = BlockPosition::fromVector3($window->getHolder()->getPosition());
|
||||
$windowType = match(true){
|
||||
$window instanceof LoomInventoryWindow => WindowTypes::LOOM,
|
||||
$window instanceof FurnaceInventoryWindow => match($window->getFurnaceType()){
|
||||
|
Loading…
x
Reference in New Issue
Block a user