mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-28 13:45:52 +00:00
Campfire block's inventory is now null if it hasn't been set in the world
having this created by the block was unreliable anyway. If items were set into the block's created inventory before setting the block in the world, the campfire contents would get overridden when the block was next run through readStateFromWorld() anyway. There needs to be a deeper exploration of how to handle blocks with inventories without requiring plugins to interact with tiles. For now, this isn't the worst solution, but it's not the best either.
This commit is contained in:
parent
15bb0c705c
commit
b76db739fd
src/block
@ -72,24 +72,7 @@ class Campfire extends Transparent{
|
||||
* @deprecated This was added by mistake. It can't be relied on as the inventory won't be initialized if this block
|
||||
* has never been set in the world.
|
||||
*/
|
||||
protected Inventory $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 = self::createInventory();
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* TODO: we need to explore why this is being created in multiple places
|
||||
*/
|
||||
public static function createInventory() : Inventory{
|
||||
$result = new SimpleInventory(4);
|
||||
$result->setMaxStackSize(1);
|
||||
return $result;
|
||||
}
|
||||
protected ?Inventory $inventory = null;
|
||||
|
||||
/**
|
||||
* @var int[] slot => ticks
|
||||
@ -109,7 +92,8 @@ class Campfire extends Transparent{
|
||||
$this->inventory = $tile->getInventory();
|
||||
$this->cookingTimes = $tile->getCookingTimes();
|
||||
}else{
|
||||
$this->inventory = self::createInventory();
|
||||
$this->inventory = null;
|
||||
$this->cookingTimes = [];
|
||||
}
|
||||
|
||||
return $this;
|
||||
@ -153,7 +137,7 @@ class Campfire extends Transparent{
|
||||
* @deprecated This was added by mistake. It can't be relied on as the inventory won't be initialized if this block
|
||||
* has never been set in the world.
|
||||
*/
|
||||
public function getInventory() : Inventory{
|
||||
public function getInventory() : ?Inventory{
|
||||
return $this->inventory;
|
||||
}
|
||||
|
||||
@ -216,10 +200,11 @@ class Campfire extends Transparent{
|
||||
return true;
|
||||
}
|
||||
|
||||
if($this->position->getWorld()->getServer()->getCraftingManager()->getFurnaceRecipeManager($this->getFurnaceType())->match($item) !== null){
|
||||
$inventory = $this->inventory;
|
||||
if($inventory !== null && $this->position->getWorld()->getServer()->getCraftingManager()->getFurnaceRecipeManager($this->getFurnaceType())->match($item) !== null){
|
||||
$ingredient = clone $item;
|
||||
$ingredient->setCount(1);
|
||||
if(count($this->inventory->addItem($ingredient)) === 0){
|
||||
if(count($inventory->addItem($ingredient)) === 0){
|
||||
$item->pop();
|
||||
$this->position->getWorld()->addSound($this->position, new ItemFrameAddItemSound());
|
||||
return true;
|
||||
@ -254,8 +239,8 @@ class Campfire extends Transparent{
|
||||
}
|
||||
|
||||
public function onScheduledUpdate() : void{
|
||||
if($this->lit){
|
||||
$items = $this->inventory->getContents();
|
||||
if($this->lit && ($inventory = $this->inventory) !== null){
|
||||
$items = $inventory->getContents();
|
||||
$furnaceType = $this->getFurnaceType();
|
||||
$maxCookDuration = $furnaceType->getCookDurationTicks();
|
||||
foreach($items as $slot => $item){
|
||||
@ -273,7 +258,7 @@ class Campfire extends Transparent{
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->inventory->setItem($slot, VanillaItems::AIR());
|
||||
$inventory->setItem($slot, VanillaItems::AIR());
|
||||
$this->setCookingTime($slot, 0);
|
||||
$this->position->getWorld()->dropItem($this->position->add(0.5, 1, 0.5), $ev->getResult());
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ namespace pocketmine\block\tile;
|
||||
|
||||
use pocketmine\block\Campfire as BlockCampfire;
|
||||
use pocketmine\inventory\Inventory;
|
||||
use pocketmine\inventory\SimpleInventory;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
@ -51,7 +52,8 @@ class Campfire extends Spawnable implements ContainerTile{
|
||||
|
||||
public function __construct(World $world, Vector3 $pos){
|
||||
parent::__construct($world, $pos);
|
||||
$this->inventory = BlockCampfire::createInventory();
|
||||
$this->inventory = new SimpleInventory(4);
|
||||
$this->inventory->setMaxStackSize(1);
|
||||
}
|
||||
|
||||
public function getInventory() : Inventory{
|
||||
|
Loading…
x
Reference in New Issue
Block a user