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

Separate inventory holder info from container & player inventories #6533

Open
wants to merge 32 commits into
base: major-next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f98cebb
Separate hotbar from player inventory
dktapps Nov 24, 2024
473bbe6
BaseInventory no longer uses viewers to send updates to players
dktapps Nov 24, 2024
45a4282
First look: Split up Inventory & InventoryWindow
dktapps Nov 24, 2024
dcbf1c7
this bites me every single time
dktapps Nov 24, 2024
9c5df90
Burn more junk
dktapps Nov 24, 2024
1d2b527
Chest block now has responsibility for configuring double chest inven…
dktapps Nov 24, 2024
fe1a8d9
namespace tidy
dktapps Nov 24, 2024
1738355
Remove potentially problematic ephemeral window creation
dktapps Nov 24, 2024
7f58122
Avoid unnecessary repeated calls
dktapps Nov 24, 2024
5c22124
Merge branch 'major-next' into inventory-rework
dktapps Nov 24, 2024
6aa4e4c
CS
dktapps Nov 24, 2024
f4d50a1
Merge branch 'major-next' into inventory-rework
dktapps Nov 24, 2024
4dcc14e
Integrate block container animations and SFX into Block classes by wa…
dktapps Nov 25, 2024
edf4e9d
...
dktapps Nov 25, 2024
d69d8d6
EnchantingTableInventoryWindow: cleanup weakref mess
dktapps Nov 25, 2024
3099129
Merge branch 'major-next' into inventory-rework
dktapps Nov 25, 2024
5a35c25
Merge branch 'major-next' into inventory-rework
dktapps Nov 26, 2024
6578d65
Merge branch 'major-next' into inventory-rework
dktapps Dec 6, 2024
ce4d3ae
Rename Container(Trait) -> ContainerTile(Trait)
dktapps Dec 6, 2024
40574be
Shift inventory management responsibility to World
dktapps Dec 6, 2024
4850bd5
Allow blocks to respond to the contents of their containers being upd…
dktapps Dec 6, 2024
76528b2
Remove dodgy code
dktapps Dec 7, 2024
15bb0c7
Remove CampfireInventory
dktapps Dec 7, 2024
b76db73
Campfire block's inventory is now null if it hasn't been set in the w…
dktapps Dec 7, 2024
b5a69c8
smh
dktapps Dec 7, 2024
ef3d165
Revert "Chest block now has responsibility for configuring double che…
dktapps Dec 7, 2024
4906f5b
...
dktapps Dec 7, 2024
699a85a
Replace DoubleChestInventory with a more generic CombinedInventory
dktapps Dec 7, 2024
9e6e508
stfu
dktapps Dec 7, 2024
3ee78e2
BlockInventoryTrait: include a Block ref instead of Position
dktapps Dec 7, 2024
9949e38
CombinedInventory now propagates updates if its backing inventories w…
dktapps Dec 8, 2024
0fe786a
Rename CombinedInventory -> CombinedInventoryProxy
dktapps Dec 8, 2024
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