mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
CreativeInventory per Player (#5694)
This commit is contained in:
parent
8f217ca6e0
commit
c01d2dc718
@ -23,7 +23,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\inventory\transaction\action;
|
||||
|
||||
use pocketmine\inventory\CreativeInventory;
|
||||
use pocketmine\inventory\transaction\TransactionValidationException;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\VanillaItems;
|
||||
@ -43,7 +42,7 @@ class CreateItemAction extends InventoryAction{
|
||||
if($source->hasFiniteResources()){
|
||||
throw new TransactionValidationException("Player has finite resources, cannot create items");
|
||||
}
|
||||
if(!CreativeInventory::getInstance()->contains($this->sourceItem)){
|
||||
if(!$source->getCreativeInventory()->contains($this->sourceItem)){
|
||||
throw new TransactionValidationException("Creative inventory does not contain requested item");
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,6 @@ use pocketmine\block\inventory\LoomInventory;
|
||||
use pocketmine\block\inventory\SmithingTableInventory;
|
||||
use pocketmine\block\inventory\StonecutterInventory;
|
||||
use pocketmine\crafting\FurnaceType;
|
||||
use pocketmine\inventory\CreativeInventory;
|
||||
use pocketmine\inventory\Inventory;
|
||||
use pocketmine\inventory\transaction\action\SlotChangeAction;
|
||||
use pocketmine\inventory\transaction\InventoryTransaction;
|
||||
@ -603,7 +602,7 @@ class InventoryManager{
|
||||
}
|
||||
|
||||
public function syncCreative() : void{
|
||||
$this->session->sendDataPacket(CreativeInventoryCache::getInstance()->getCache(CreativeInventory::getInstance()));
|
||||
$this->session->sendDataPacket(CreativeInventoryCache::getInstance()->getCache($this->player->getCreativeInventory()));
|
||||
}
|
||||
|
||||
private function newItemStackId() : int{
|
||||
|
@ -23,7 +23,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\network\mcpe\handler;
|
||||
|
||||
use pocketmine\inventory\CreativeInventory;
|
||||
use pocketmine\inventory\Inventory;
|
||||
use pocketmine\inventory\transaction\action\CreateItemAction;
|
||||
use pocketmine\inventory\transaction\action\DestroyItemAction;
|
||||
@ -327,7 +326,7 @@ class ItemStackRequestExecutor{
|
||||
$this->builder->addAction(new DestroyItemAction($destroyed));
|
||||
|
||||
}elseif($action instanceof CreativeCreateStackRequestAction){
|
||||
$item = CreativeInventory::getInstance()->getItem($action->getCreativeItemId());
|
||||
$item = $this->player->getCreativeInventory()->getItem($action->getCreativeItemId());
|
||||
if($item === null){
|
||||
throw new ItemStackRequestProcessException("No such creative item index: " . $action->getCreativeItemId());
|
||||
}
|
||||
|
@ -80,6 +80,7 @@ use pocketmine\event\player\PlayerViewDistanceChangeEvent;
|
||||
use pocketmine\form\Form;
|
||||
use pocketmine\form\FormValidationException;
|
||||
use pocketmine\inventory\CallbackInventoryListener;
|
||||
use pocketmine\inventory\CreativeInventory;
|
||||
use pocketmine\inventory\Inventory;
|
||||
use pocketmine\inventory\PlayerCraftingInventory;
|
||||
use pocketmine\inventory\PlayerCursorInventory;
|
||||
@ -217,6 +218,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
protected array $permanentWindows = [];
|
||||
protected PlayerCursorInventory $cursorInventory;
|
||||
protected PlayerCraftingInventory $craftingGrid;
|
||||
protected CreativeInventory $creativeInventory;
|
||||
|
||||
protected int $messageCounter = 2;
|
||||
|
||||
@ -307,6 +309,8 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
$this->uuid = $this->playerInfo->getUuid();
|
||||
$this->xuid = $this->playerInfo instanceof XboxLivePlayerInfo ? $this->playerInfo->getXuid() : "";
|
||||
|
||||
$this->creativeInventory = CreativeInventory::getInstance();
|
||||
|
||||
$rootPermissions = [DefaultPermissions::ROOT_USER => true];
|
||||
if($this->server->isOp($this->username)){
|
||||
$rootPermissions[DefaultPermissions::ROOT_OPERATOR] = true;
|
||||
@ -2532,6 +2536,24 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
return $this->craftingGrid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the creative inventory shown to the player.
|
||||
* Unless changed by a plugin, this is usually the same for all players.
|
||||
*/
|
||||
public function getCreativeInventory() : CreativeInventory{
|
||||
return $this->creativeInventory;
|
||||
}
|
||||
|
||||
/**
|
||||
* To set a custom creative inventory, you need to make a clone of a CreativeInventory instance.
|
||||
*/
|
||||
public function setCreativeInventory(CreativeInventory $inventory) : void{
|
||||
$this->creativeInventory = $inventory;
|
||||
if($this->spawned && $this->isConnected()){
|
||||
$this->getNetworkSession()->getInvManager()?->syncCreative();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal Called to clean up crafting grid and cursor inventory when it is detected that the player closed their
|
||||
* inventory.
|
||||
|
Loading…
x
Reference in New Issue
Block a user