Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inventory rework #6533

Draft
wants to merge 17 commits into
base: major-next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/block/Anvil.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace pocketmine\block;

use pocketmine\block\inventory\AnvilInventory;
use pocketmine\block\inventory\AnvilInventoryWindow;
use pocketmine\block\utils\Fallable;
use pocketmine\block\utils\FallableTrait;
use pocketmine\block\utils\HorizontalFacingTrait;
Expand Down Expand Up @@ -83,7 +83,7 @@ public function getSupportType(int $facing) : SupportType{

public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
if($player instanceof Player){
$player->setCurrentWindow(new AnvilInventory($this->position));
$player->setCurrentWindow(new AnvilInventoryWindow($player, $this->position));
}

return true;
Expand Down
3 changes: 2 additions & 1 deletion src/block/Barrel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace pocketmine\block;

use pocketmine\block\inventory\BarrelInventoryWindow;
use pocketmine\block\tile\Barrel as TileBarrel;
use pocketmine\block\utils\AnyFacingTrait;
use pocketmine\data\runtime\RuntimeDataDescriber;
Expand Down Expand Up @@ -81,7 +82,7 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player
return true;
}

$player->setCurrentWindow($barrel->getInventory());
$player->setCurrentWindow(new BarrelInventoryWindow($player, $barrel->getInventory(), $this->position));
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/block/BrewingStand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace pocketmine\block;

use pocketmine\block\inventory\BrewingStandInventoryWindow;
use pocketmine\block\tile\BrewingStand as TileBrewingStand;
use pocketmine\block\utils\BrewingStandSlot;
use pocketmine\block\utils\SupportType;
Expand Down Expand Up @@ -99,7 +100,7 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player
if($player instanceof Player){
$stand = $this->position->getWorld()->getTile($this->position);
if($stand instanceof TileBrewingStand && $stand->canOpenWith($item->getCustomName())){
$player->setCurrentWindow($stand->getInventory());
$player->setCurrentWindow(new BrewingStandInventoryWindow($player, $stand->getInventory(), $this->position));
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/block/Campfire.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ class Campfire extends Transparent{

protected CampfireInventory $inventory;

public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){
parent::__construct($idInfo, $name, $typeInfo);
//TODO: this should never have been in the block - it creates problems for setting blocks in different positions
//as inventories aren't designed to be cloned
$this->inventory = new CampfireInventory();
}

/**
* @var int[] slot => ticks
* @phpstan-var array<int, int>
Expand All @@ -89,7 +96,7 @@ public function readStateFromWorld() : Block{
$this->inventory = $tile->getInventory();
$this->cookingTimes = $tile->getCookingTimes();
}else{
$this->inventory = new CampfireInventory($this->position);
$this->inventory = new CampfireInventory();
}

return $this;
Expand Down
4 changes: 2 additions & 2 deletions src/block/CartographyTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace pocketmine\block;

use pocketmine\block\inventory\CartographyTableInventory;
use pocketmine\block\inventory\CartographyTableInventoryWindow;
use pocketmine\item\Item;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
Expand All @@ -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 CartographyTableInventory($this->position));
$player->setCurrentWindow(new CartographyTableInventoryWindow($player, $this->position));
}

return true;
Expand Down
23 changes: 20 additions & 3 deletions src/block/Chest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

namespace pocketmine\block;

use pocketmine\block\inventory\ChestInventoryWindow;
use pocketmine\block\inventory\DoubleChestInventoryWindow;
use pocketmine\block\tile\Chest as TileChest;
use pocketmine\block\utils\FacesOppositePlacingPlayerTrait;
use pocketmine\block\utils\SupportType;
Expand Down Expand Up @@ -74,8 +76,8 @@ public function onPostPlace() : void{

public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
if($player instanceof Player){

$chest = $this->position->getWorld()->getTile($this->position);
$world = $this->position->getWorld();
$chest = $world->getTile($this->position);
if($chest instanceof TileChest){
if(
!$this->getSide(Facing::UP)->isTransparent() ||
Expand All @@ -85,7 +87,22 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player
return true;
}

$player->setCurrentWindow($chest->getInventory());
foreach([false, true] as $clockwise){
$sideFacing = Facing::rotateY($this->facing, $clockwise);
$side = $this->position->getSide($sideFacing);
$pair = $world->getTile($side);
if($pair instanceof TileChest && $pair->getPair() === $chest){
[$left, $right] = $clockwise ? [$side, $this->position] : [$this->position, $side];

//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
//however I'm not sure if this is currently possible
$window = new DoubleChestInventoryWindow($player, $chest->getInventory(), $left, $right);
break;
}
}

$player->setCurrentWindow($window ?? new ChestInventoryWindow($player, $chest->getInventory(), $this->position));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/block/CraftingTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace pocketmine\block;

use pocketmine\block\inventory\CraftingTableInventory;
use pocketmine\block\inventory\CraftingTableInventoryWindow;
use pocketmine\item\Item;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
Expand All @@ -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 CraftingTableInventory($this->position));
$player->setCurrentWindow(new CraftingTableInventoryWindow($player, $this->position));
}

return true;
Expand Down
4 changes: 2 additions & 2 deletions src/block/EnchantingTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace pocketmine\block;

use pocketmine\block\inventory\EnchantInventory;
use pocketmine\block\inventory\EnchantingTableInventoryWindow;
use pocketmine\block\utils\SupportType;
use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB;
Expand All @@ -48,7 +48,7 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player
if($player instanceof Player){
//TODO lock

$player->setCurrentWindow(new EnchantInventory($this->position));
$player->setCurrentWindow(new EnchantingTableInventoryWindow($player, $this->position));
}

return true;
Expand Down
5 changes: 2 additions & 3 deletions src/block/EnderChest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace pocketmine\block;

use pocketmine\block\inventory\EnderChestInventory;
use pocketmine\block\inventory\EnderChestInventoryWindow;
use pocketmine\block\tile\EnderChest as TileEnderChest;
use pocketmine\block\utils\FacesOppositePlacingPlayerTrait;
use pocketmine\block\utils\SupportType;
Expand Down Expand Up @@ -56,8 +56,7 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player
if($player instanceof Player){
$enderChest = $this->position->getWorld()->getTile($this->position);
if($enderChest instanceof TileEnderChest && $this->getSide(Facing::UP)->isTransparent()){
$enderChest->setViewerCount($enderChest->getViewerCount() + 1);
$player->setCurrentWindow(new EnderChestInventory($this->position, $player->getEnderInventory()));
$player->setCurrentWindow(new EnderChestInventoryWindow($player, $player->getEnderInventory(), $this->position));
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/block/Furnace.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace pocketmine\block;

use pocketmine\block\inventory\FurnaceInventoryWindow;
use pocketmine\block\tile\Furnace as TileFurnace;
use pocketmine\block\utils\FacesOppositePlacingPlayerTrait;
use pocketmine\block\utils\LightableTrait;
Expand Down Expand Up @@ -61,7 +62,7 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player
if($player instanceof Player){
$furnace = $this->position->getWorld()->getTile($this->position);
if($furnace instanceof TileFurnace && $furnace->canOpenWith($item->getCustomName())){
$player->setCurrentWindow($furnace->getInventory());
$player->setCurrentWindow(new FurnaceInventoryWindow($player, $furnace->getInventory(), $this->position, $this->furnaceType));
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/block/Hopper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace pocketmine\block;

use pocketmine\block\inventory\HopperInventoryWindow;
use pocketmine\block\tile\Hopper as TileHopper;
use pocketmine\block\utils\PoweredByRedstoneTrait;
use pocketmine\block\utils\SupportType;
Expand Down Expand Up @@ -84,7 +85,7 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player
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($tile->getInventory());
$player->setCurrentWindow(new HopperInventoryWindow($player, $tile->getInventory(), $this->position));
}
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/block/Loom.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace pocketmine\block;

use pocketmine\block\inventory\LoomInventory;
use pocketmine\block\inventory\LoomInventoryWindow;
use pocketmine\block\utils\FacesOppositePlacingPlayerTrait;
use pocketmine\item\Item;
use pocketmine\math\Vector3;
Expand All @@ -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 LoomInventory($this->position));
$player->setCurrentWindow(new LoomInventoryWindow($player, $this->position));
return true;
}
return false;
Expand Down
3 changes: 2 additions & 1 deletion src/block/ShulkerBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace pocketmine\block;

use pocketmine\block\inventory\ShulkerBoxInventoryWindow;
use pocketmine\block\tile\ShulkerBox as TileShulkerBox;
use pocketmine\block\utils\AnyFacingTrait;
use pocketmine\block\utils\SupportType;
Expand Down Expand Up @@ -105,7 +106,7 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player
return true;
}

$player->setCurrentWindow($shulker->getInventory());
$player->setCurrentWindow(new ShulkerBoxInventoryWindow($player, $shulker->getInventory(), $this->position));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/block/SmithingTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace pocketmine\block;

use pocketmine\block\inventory\SmithingTableInventory;
use pocketmine\block\inventory\SmithingTableInventoryWindow;
use pocketmine\item\Item;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
Expand All @@ -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 SmithingTableInventory($this->position));
$player->setCurrentWindow(new SmithingTableInventoryWindow($player, $this->position));
}

return true;
Expand Down
4 changes: 2 additions & 2 deletions src/block/Stonecutter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace pocketmine\block;

use pocketmine\block\inventory\StonecutterInventory;
use pocketmine\block\inventory\StonecutterInventoryWindow;
use pocketmine\block\utils\FacesOppositePlacingPlayerTrait;
use pocketmine\block\utils\SupportType;
use pocketmine\item\Item;
Expand All @@ -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 StonecutterInventory($this->position));
$player->setCurrentWindow(new StonecutterInventoryWindow($player, $this->position));
}
return true;
}
Expand Down
67 changes: 0 additions & 67 deletions src/block/inventory/AnimatedBlockInventoryTrait.php

This file was deleted.

Loading