This commit is contained in:
Dylan K. Taylor 2025-04-30 19:52:49 +01:00
parent 1245ee2575
commit ce55183d71
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
24 changed files with 37 additions and 38 deletions

View File

@ -80,7 +80,7 @@ class Anvil extends Transparent implements Fallable{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
if($player instanceof Player){ if($player instanceof Player){
$player->setCurrentWindow(new AnvilInventoryWindow($player, $this)); $player->setCurrentWindow(new AnvilInventoryWindow($player, $this->position));
} }
return true; return true;

View File

@ -89,7 +89,7 @@ class Barrel extends Opaque implements AnimatedContainer{
return true; return true;
} }
$player->setCurrentWindow(new BlockInventoryWindow($player, $barrel->getInventory(), $this)); $player->setCurrentWindow(new BlockInventoryWindow($player, $barrel->getInventory(), $this->position));
} }
} }

View File

@ -100,7 +100,7 @@ class BrewingStand extends Transparent{
if($player instanceof Player){ if($player instanceof Player){
$stand = $this->position->getWorld()->getTile($this->position); $stand = $this->position->getWorld()->getTile($this->position);
if($stand instanceof TileBrewingStand && $stand->canOpenWith($item->getCustomName())){ if($stand instanceof TileBrewingStand && $stand->canOpenWith($item->getCustomName())){
$player->setCurrentWindow(new BrewingStandInventoryWindow($player, $stand->getInventory(), $this)); $player->setCurrentWindow(new BrewingStandInventoryWindow($player, $stand->getInventory(), $this->position));
} }
} }

View File

@ -32,7 +32,7 @@ final class CartographyTable extends Opaque{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
if($player !== null){ if($player !== null){
$player->setCurrentWindow(new CartographyTableInventoryWindow($player, $this)); $player->setCurrentWindow(new CartographyTableInventoryWindow($player, $this->position));
} }
return true; return true;

View File

@ -119,10 +119,10 @@ class Chest extends Transparent implements AnimatedContainer{
//TODO: we should probably construct DoubleChestInventory here directly too using the same logic //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 //right now it uses some weird logic in TileChest which produces incorrect results
//however I'm not sure if this is currently possible //however I'm not sure if this is currently possible
$window = new DoubleChestInventoryWindow($player, $chest->getInventory(), $left, $right); $window = new DoubleChestInventoryWindow($player, $chest->getInventory(), $left->position, $right->position);
} }
$player->setCurrentWindow($window ?? new BlockInventoryWindow($player, $chest->getInventory(), $this)); $player->setCurrentWindow($window ?? new BlockInventoryWindow($player, $chest->getInventory(), $this->position));
} }
} }

View File

@ -32,7 +32,7 @@ class CraftingTable extends Opaque{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
if($player instanceof Player){ if($player instanceof Player){
$player->setCurrentWindow(new CraftingTableInventoryWindow($player, $this)); $player->setCurrentWindow(new CraftingTableInventoryWindow($player, $this->position));
} }
return true; return true;

View File

@ -45,7 +45,7 @@ class EnchantingTable extends Transparent{
if($player instanceof Player){ if($player instanceof Player){
//TODO lock //TODO lock
$player->setCurrentWindow(new EnchantingTableInventoryWindow($player, $this)); $player->setCurrentWindow(new EnchantingTableInventoryWindow($player, $this->position));
} }
return true; return true;

View File

@ -65,7 +65,7 @@ class EnderChest extends Transparent implements AnimatedContainer{
if($player instanceof Player){ if($player instanceof Player){
$enderChest = $this->position->getWorld()->getTile($this->position); $enderChest = $this->position->getWorld()->getTile($this->position);
if($enderChest instanceof TileEnderChest && $this->getSide(Facing::UP)->isTransparent()){ if($enderChest instanceof TileEnderChest && $this->getSide(Facing::UP)->isTransparent()){
$player->setCurrentWindow(new BlockInventoryWindow($player, $player->getEnderInventory(), $this)); $player->setCurrentWindow(new BlockInventoryWindow($player, $player->getEnderInventory(), $this->position));
} }
} }

View File

@ -62,7 +62,7 @@ class Furnace extends Opaque{
if($player instanceof Player){ if($player instanceof Player){
$furnace = $this->position->getWorld()->getTile($this->position); $furnace = $this->position->getWorld()->getTile($this->position);
if($furnace instanceof TileFurnace && $furnace->canOpenWith($item->getCustomName())){ if($furnace instanceof TileFurnace && $furnace->canOpenWith($item->getCustomName())){
$player->setCurrentWindow(new FurnaceInventoryWindow($player, $furnace->getInventory(), $this, $this->furnaceType)); $player->setCurrentWindow(new FurnaceInventoryWindow($player, $furnace->getInventory(), $this->position, $this->furnaceType));
} }
} }

View File

@ -85,7 +85,7 @@ class Hopper extends Transparent{
if($player !== null){ if($player !== null){
$tile = $this->position->getWorld()->getTile($this->position); $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 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)); $player->setCurrentWindow(new HopperInventoryWindow($player, $tile->getInventory(), $this->position));
} }
return true; return true;
} }

View File

@ -34,7 +34,7 @@ final class Loom extends Opaque{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
if($player !== null){ if($player !== null){
$player->setCurrentWindow(new LoomInventoryWindow($player, $this)); $player->setCurrentWindow(new LoomInventoryWindow($player, $this->position));
return true; return true;
} }
return false; return false;

View File

@ -115,7 +115,7 @@ class ShulkerBox extends Opaque implements AnimatedContainer{
return true; return true;
} }
$player->setCurrentWindow(new BlockInventoryWindow($player, $shulker->getInventory(), $this)); $player->setCurrentWindow(new BlockInventoryWindow($player, $shulker->getInventory(), $this->position));
} }
} }

View File

@ -32,7 +32,7 @@ final class SmithingTable extends Opaque{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
if($player !== null){ if($player !== null){
$player->setCurrentWindow(new SmithingTableInventoryWindow($player, $this)); $player->setCurrentWindow(new SmithingTableInventoryWindow($player, $this->position));
} }
return true; return true;

View File

@ -37,7 +37,7 @@ class Stonecutter extends Transparent{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
if($player !== null){ if($player !== null){
$player->setCurrentWindow(new StonecutterInventoryWindow($player, $this)); $player->setCurrentWindow(new StonecutterInventoryWindow($player, $this->position));
} }
return true; return true;
} }

View File

@ -23,10 +23,10 @@ declare(strict_types=1);
namespace pocketmine\block\inventory\window; namespace pocketmine\block\inventory\window;
use pocketmine\block\Block;
use pocketmine\inventory\SimpleInventory; use pocketmine\inventory\SimpleInventory;
use pocketmine\player\Player; use pocketmine\player\Player;
use pocketmine\player\TemporaryInventoryWindow; use pocketmine\player\TemporaryInventoryWindow;
use pocketmine\world\Position;
final class AnvilInventoryWindow extends BlockInventoryWindow implements TemporaryInventoryWindow{ final class AnvilInventoryWindow extends BlockInventoryWindow implements TemporaryInventoryWindow{
public const SLOT_INPUT = 0; public const SLOT_INPUT = 0;
@ -34,7 +34,7 @@ final class AnvilInventoryWindow extends BlockInventoryWindow implements Tempora
public function __construct( public function __construct(
Player $viewer, Player $viewer,
Block $holder Position $holder
){ ){
parent::__construct($viewer, new SimpleInventory(2), $holder); parent::__construct($viewer, new SimpleInventory(2), $holder);
} }

View File

@ -23,7 +23,6 @@ declare(strict_types=1);
namespace pocketmine\block\inventory\window; namespace pocketmine\block\inventory\window;
use pocketmine\block\Block;
use pocketmine\block\utils\AnimatedContainer; use pocketmine\block\utils\AnimatedContainer;
use pocketmine\inventory\Inventory; use pocketmine\inventory\Inventory;
use pocketmine\player\InventoryWindow; use pocketmine\player\InventoryWindow;

View File

@ -23,16 +23,16 @@ declare(strict_types=1);
namespace pocketmine\block\inventory\window; namespace pocketmine\block\inventory\window;
use pocketmine\block\Block;
use pocketmine\inventory\SimpleInventory; use pocketmine\inventory\SimpleInventory;
use pocketmine\player\Player; use pocketmine\player\Player;
use pocketmine\player\TemporaryInventoryWindow; use pocketmine\player\TemporaryInventoryWindow;
use pocketmine\world\Position;
final class CartographyTableInventoryWindow extends BlockInventoryWindow implements TemporaryInventoryWindow{ final class CartographyTableInventoryWindow extends BlockInventoryWindow implements TemporaryInventoryWindow{
public function __construct( public function __construct(
Player $viewer, Player $viewer,
Block $holder Position $holder
){ ){
parent::__construct($viewer, new SimpleInventory(2), $holder); parent::__construct($viewer, new SimpleInventory(2), $holder);
} }

View File

@ -23,15 +23,15 @@ declare(strict_types=1);
namespace pocketmine\block\inventory\window; namespace pocketmine\block\inventory\window;
use pocketmine\block\Block;
use pocketmine\crafting\CraftingGrid; use pocketmine\crafting\CraftingGrid;
use pocketmine\player\Player; use pocketmine\player\Player;
use pocketmine\world\Position;
final class CraftingTableInventoryWindow extends BlockInventoryWindow{ final class CraftingTableInventoryWindow extends BlockInventoryWindow{
public function __construct( public function __construct(
Player $viewer, Player $viewer,
Block $holder Position $holder
){ ){
//TODO: generics would be good for this, since it has special methods //TODO: generics would be good for this, since it has special methods
parent::__construct($viewer, new CraftingGrid(CraftingGrid::SIZE_BIG), $holder); parent::__construct($viewer, new CraftingGrid(CraftingGrid::SIZE_BIG), $holder);

View File

@ -23,22 +23,22 @@ declare(strict_types=1);
namespace pocketmine\block\inventory\window; namespace pocketmine\block\inventory\window;
use pocketmine\block\Block;
use pocketmine\inventory\Inventory; use pocketmine\inventory\Inventory;
use pocketmine\player\Player; use pocketmine\player\Player;
use pocketmine\world\Position;
final class DoubleChestInventoryWindow extends BlockInventoryWindow{ final class DoubleChestInventoryWindow extends BlockInventoryWindow{
public function __construct( public function __construct(
Player $viewer, Player $viewer,
Inventory $inventory, Inventory $inventory,
private Block $left, private Position $left,
private Block $right private Position $right
){ ){
parent::__construct($viewer, $inventory, $this->left); parent::__construct($viewer, $inventory, $this->left);
} }
public function getLeft() : Block{ return $this->left; } public function getLeft() : Position{ return $this->left; }
public function getRight() : Block{ return $this->right; } public function getRight() : Position{ return $this->right; }
} }

View File

@ -23,7 +23,6 @@ declare(strict_types=1);
namespace pocketmine\block\inventory\window; namespace pocketmine\block\inventory\window;
use pocketmine\block\Block;
use pocketmine\event\player\PlayerEnchantingOptionsRequestEvent; use pocketmine\event\player\PlayerEnchantingOptionsRequestEvent;
use pocketmine\inventory\CallbackInventoryListener; use pocketmine\inventory\CallbackInventoryListener;
use pocketmine\inventory\Inventory; use pocketmine\inventory\Inventory;
@ -33,6 +32,7 @@ use pocketmine\item\enchantment\EnchantingHelper as Helper;
use pocketmine\item\enchantment\EnchantingOption; use pocketmine\item\enchantment\EnchantingOption;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\player\Player; use pocketmine\player\Player;
use pocketmine\world\Position;
use function array_values; use function array_values;
use function count; use function count;
@ -47,7 +47,7 @@ final class EnchantingTableInventoryWindow extends BlockInventoryWindow{
public function __construct( public function __construct(
Player $viewer, Player $viewer,
Block $holder Position $holder
){ ){
parent::__construct($viewer, new SimpleInventory(2), $holder); parent::__construct($viewer, new SimpleInventory(2), $holder);
@ -75,7 +75,7 @@ final class EnchantingTableInventoryWindow extends BlockInventoryWindow{
private function regenerateOptions() : void{ private function regenerateOptions() : void{
$this->options = []; $this->options = [];
$item = $this->getInput(); $item = $this->getInput();
$options = Helper::generateOptions($this->holder->getPosition(), $item, $this->viewer->getEnchantmentSeed()); $options = Helper::generateOptions($this->holder, $item, $this->viewer->getEnchantmentSeed());
$event = new PlayerEnchantingOptionsRequestEvent($this->viewer, $this, $options); $event = new PlayerEnchantingOptionsRequestEvent($this->viewer, $this, $options);
$event->call(); $event->call();

View File

@ -23,11 +23,11 @@ declare(strict_types=1);
namespace pocketmine\block\inventory\window; namespace pocketmine\block\inventory\window;
use pocketmine\block\Block;
use pocketmine\crafting\FurnaceType; use pocketmine\crafting\FurnaceType;
use pocketmine\inventory\Inventory; use pocketmine\inventory\Inventory;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\player\Player; use pocketmine\player\Player;
use pocketmine\world\Position;
final class FurnaceInventoryWindow extends BlockInventoryWindow{ final class FurnaceInventoryWindow extends BlockInventoryWindow{
public const SLOT_INPUT = 0; public const SLOT_INPUT = 0;
@ -37,7 +37,7 @@ final class FurnaceInventoryWindow extends BlockInventoryWindow{
public function __construct( public function __construct(
Player $viewer, Player $viewer,
Inventory $inventory, Inventory $inventory,
Block $holder, Position $holder,
private FurnaceType $furnaceType private FurnaceType $furnaceType
){ ){
parent::__construct($viewer, $inventory, $holder); parent::__construct($viewer, $inventory, $holder);

View File

@ -23,10 +23,10 @@ declare(strict_types=1);
namespace pocketmine\block\inventory\window; namespace pocketmine\block\inventory\window;
use pocketmine\block\Block;
use pocketmine\inventory\SimpleInventory; use pocketmine\inventory\SimpleInventory;
use pocketmine\player\Player; use pocketmine\player\Player;
use pocketmine\player\TemporaryInventoryWindow; use pocketmine\player\TemporaryInventoryWindow;
use pocketmine\world\Position;
final class LoomInventoryWindow extends BlockInventoryWindow implements TemporaryInventoryWindow{ final class LoomInventoryWindow extends BlockInventoryWindow implements TemporaryInventoryWindow{
@ -36,7 +36,7 @@ final class LoomInventoryWindow extends BlockInventoryWindow implements Temporar
public function __construct( public function __construct(
Player $viewer, Player $viewer,
Block $holder Position $holder
){ ){
parent::__construct($viewer, new SimpleInventory(3), $holder); parent::__construct($viewer, new SimpleInventory(3), $holder);
} }

View File

@ -23,13 +23,13 @@ declare(strict_types=1);
namespace pocketmine\block\inventory\window; namespace pocketmine\block\inventory\window;
use pocketmine\block\Block;
use pocketmine\inventory\SimpleInventory; use pocketmine\inventory\SimpleInventory;
use pocketmine\player\Player; use pocketmine\player\Player;
use pocketmine\player\TemporaryInventoryWindow; use pocketmine\player\TemporaryInventoryWindow;
use pocketmine\world\Position;
final class SmithingTableInventoryWindow extends BlockInventoryWindow implements TemporaryInventoryWindow{ final class SmithingTableInventoryWindow extends BlockInventoryWindow implements TemporaryInventoryWindow{
public function __construct(Player $viewer, Block $holder){ public function __construct(Player $viewer, Position $holder){
parent::__construct($viewer, new SimpleInventory(3), $holder); parent::__construct($viewer, new SimpleInventory(3), $holder);
} }
} }

View File

@ -23,15 +23,15 @@ declare(strict_types=1);
namespace pocketmine\block\inventory\window; namespace pocketmine\block\inventory\window;
use pocketmine\block\Block;
use pocketmine\inventory\SimpleInventory; use pocketmine\inventory\SimpleInventory;
use pocketmine\player\Player; use pocketmine\player\Player;
use pocketmine\player\TemporaryInventoryWindow; use pocketmine\player\TemporaryInventoryWindow;
use pocketmine\world\Position;
final class StonecutterInventoryWindow extends BlockInventoryWindow implements TemporaryInventoryWindow{ final class StonecutterInventoryWindow extends BlockInventoryWindow implements TemporaryInventoryWindow{
public const SLOT_INPUT = 0; public const SLOT_INPUT = 0;
public function __construct(Player $viewer, Block $holder){ public function __construct(Player $viewer, Position $holder){
parent::__construct($viewer, new SimpleInventory(1), $holder); parent::__construct($viewer, new SimpleInventory(1), $holder);
} }
} }