mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 19:02:59 +00:00
namespace tidy
This commit is contained in:
65
src/block/inventory/window/AnimatedBlockInventoryWindow.php
Normal file
65
src/block/inventory/window/AnimatedBlockInventoryWindow.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory\window;
|
||||
|
||||
use pocketmine\world\Position;
|
||||
use pocketmine\world\sound\Sound;
|
||||
use function count;
|
||||
|
||||
abstract class AnimatedBlockInventoryWindow extends BlockInventoryWindow{
|
||||
|
||||
protected function getViewerCount() : int{
|
||||
return count($this->inventory->getViewers());
|
||||
}
|
||||
|
||||
abstract protected function getOpenSound() : Sound;
|
||||
|
||||
abstract protected function getCloseSound() : Sound;
|
||||
|
||||
abstract protected function animateBlock(Position $position, bool $isOpen) : void;
|
||||
|
||||
protected function playSound(Position $position, bool $isOpen) : void{
|
||||
$position->getWorld()->addSound($position->add(0.5, 0.5, 0.5), $isOpen ? $this->getOpenSound() : $this->getCloseSound());
|
||||
}
|
||||
|
||||
protected function doBlockEffects(bool $isOpen) : void{
|
||||
$position = $this->holder;
|
||||
$this->animateBlock($position, $isOpen);
|
||||
$this->playSound($position, $isOpen);
|
||||
}
|
||||
|
||||
public function onOpen() : void{
|
||||
parent::onOpen();
|
||||
if($this->getViewerCount() === 1){
|
||||
$this->doBlockEffects(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function onClose() : void{
|
||||
if($this->getViewerCount() === 1){
|
||||
$this->doBlockEffects(false);
|
||||
}
|
||||
parent::onClose();
|
||||
}
|
||||
}
|
41
src/block/inventory/window/AnvilInventoryWindow.php
Normal file
41
src/block/inventory/window/AnvilInventoryWindow.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory\window;
|
||||
|
||||
use pocketmine\inventory\SimpleInventory;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\player\TemporaryInventoryWindow;
|
||||
use pocketmine\world\Position;
|
||||
|
||||
final class AnvilInventoryWindow extends BlockInventoryWindow implements TemporaryInventoryWindow{
|
||||
public const SLOT_INPUT = 0;
|
||||
public const SLOT_MATERIAL = 1;
|
||||
|
||||
public function __construct(
|
||||
Player $viewer,
|
||||
Position $holder
|
||||
){
|
||||
parent::__construct($viewer, new SimpleInventory(2), $holder);
|
||||
}
|
||||
}
|
49
src/block/inventory/window/BarrelInventoryWindow.php
Normal file
49
src/block/inventory/window/BarrelInventoryWindow.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory\window;
|
||||
|
||||
use pocketmine\block\Barrel;
|
||||
use pocketmine\world\Position;
|
||||
use pocketmine\world\sound\BarrelCloseSound;
|
||||
use pocketmine\world\sound\BarrelOpenSound;
|
||||
use pocketmine\world\sound\Sound;
|
||||
|
||||
final class BarrelInventoryWindow extends AnimatedBlockInventoryWindow{
|
||||
|
||||
protected function getOpenSound() : Sound{
|
||||
return new BarrelOpenSound();
|
||||
}
|
||||
|
||||
protected function getCloseSound() : Sound{
|
||||
return new BarrelCloseSound();
|
||||
}
|
||||
|
||||
protected function animateBlock(Position $position, bool $isOpen) : void{
|
||||
$world = $position->getWorld();
|
||||
$block = $world->getBlock($position);
|
||||
if($block instanceof Barrel){
|
||||
$world->setBlock($position, $block->setOpen($isOpen));
|
||||
}
|
||||
}
|
||||
}
|
42
src/block/inventory/window/BlockInventoryWindow.php
Normal file
42
src/block/inventory/window/BlockInventoryWindow.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory\window;
|
||||
|
||||
use pocketmine\inventory\Inventory;
|
||||
use pocketmine\player\InventoryWindow;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\world\Position;
|
||||
|
||||
class BlockInventoryWindow extends InventoryWindow{
|
||||
|
||||
public function __construct(
|
||||
Player $viewer,
|
||||
Inventory $inventory,
|
||||
protected Position $holder
|
||||
){
|
||||
parent::__construct($viewer, $inventory);
|
||||
}
|
||||
|
||||
public function getHolder() : Position{ return $this->holder; }
|
||||
}
|
32
src/block/inventory/window/BrewingStandInventoryWindow.php
Normal file
32
src/block/inventory/window/BrewingStandInventoryWindow.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory\window;
|
||||
|
||||
final class BrewingStandInventoryWindow extends BlockInventoryWindow{
|
||||
public const SLOT_INGREDIENT = 0;
|
||||
public const SLOT_BOTTLE_LEFT = 1;
|
||||
public const SLOT_BOTTLE_MIDDLE = 2;
|
||||
public const SLOT_BOTTLE_RIGHT = 3;
|
||||
public const SLOT_FUEL = 4;
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory\window;
|
||||
|
||||
use pocketmine\inventory\SimpleInventory;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\player\TemporaryInventoryWindow;
|
||||
use pocketmine\world\Position;
|
||||
|
||||
final class CartographyTableInventoryWindow extends BlockInventoryWindow implements TemporaryInventoryWindow{
|
||||
|
||||
public function __construct(
|
||||
Player $viewer,
|
||||
Position $holder
|
||||
){
|
||||
parent::__construct($viewer, new SimpleInventory(2), $holder);
|
||||
}
|
||||
}
|
48
src/block/inventory/window/ChestInventoryWindow.php
Normal file
48
src/block/inventory/window/ChestInventoryWindow.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory\window;
|
||||
|
||||
use pocketmine\network\mcpe\protocol\BlockEventPacket;
|
||||
use pocketmine\network\mcpe\protocol\types\BlockPosition;
|
||||
use pocketmine\world\Position;
|
||||
use pocketmine\world\sound\ChestCloseSound;
|
||||
use pocketmine\world\sound\ChestOpenSound;
|
||||
use pocketmine\world\sound\Sound;
|
||||
|
||||
class ChestInventoryWindow extends AnimatedBlockInventoryWindow{
|
||||
|
||||
protected function getOpenSound() : Sound{
|
||||
return new ChestOpenSound();
|
||||
}
|
||||
|
||||
protected function getCloseSound() : Sound{
|
||||
return new ChestCloseSound();
|
||||
}
|
||||
|
||||
protected function animateBlock(Position $position, bool $isOpen) : void{
|
||||
//event ID is always 1 for a chest
|
||||
//TODO: we probably shouldn't be sending a packet directly here, but it doesn't fit anywhere into existing systems
|
||||
$position->getWorld()->broadcastPacketToViewers($position, BlockEventPacket::create(BlockPosition::fromVector3($position), 1, $isOpen ? 1 : 0));
|
||||
}
|
||||
}
|
39
src/block/inventory/window/CraftingTableInventoryWindow.php
Normal file
39
src/block/inventory/window/CraftingTableInventoryWindow.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory\window;
|
||||
|
||||
use pocketmine\crafting\CraftingGrid;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\world\Position;
|
||||
|
||||
final class CraftingTableInventoryWindow extends BlockInventoryWindow{
|
||||
|
||||
public function __construct(
|
||||
Player $viewer,
|
||||
Position $holder
|
||||
){
|
||||
//TODO: generics would be good for this, since it has special methods
|
||||
parent::__construct($viewer, new CraftingGrid(CraftingGrid::SIZE_BIG), $holder);
|
||||
}
|
||||
}
|
52
src/block/inventory/window/DoubleChestInventoryWindow.php
Normal file
52
src/block/inventory/window/DoubleChestInventoryWindow.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory\window;
|
||||
|
||||
use pocketmine\inventory\Inventory;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\world\Position;
|
||||
|
||||
final class DoubleChestInventoryWindow extends ChestInventoryWindow{
|
||||
|
||||
public function __construct(
|
||||
Player $viewer,
|
||||
Inventory $inventory,
|
||||
private Position $left,
|
||||
private Position $right
|
||||
){
|
||||
parent::__construct($viewer, $inventory, $this->left);
|
||||
}
|
||||
|
||||
public function getLeft() : Position{ return $this->left; }
|
||||
|
||||
public function getRight() : Position{ return $this->right; }
|
||||
|
||||
protected function doBlockEffects(bool $isOpen) : void{
|
||||
$this->animateBlock($this->left, $isOpen);
|
||||
$this->animateBlock($this->right, $isOpen);
|
||||
|
||||
$this->playSound($this->left, $isOpen);
|
||||
$this->playSound($this->right, $isOpen);
|
||||
}
|
||||
}
|
110
src/block/inventory/window/EnchantingTableInventoryWindow.php
Normal file
110
src/block/inventory/window/EnchantingTableInventoryWindow.php
Normal file
@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory\window;
|
||||
|
||||
use pocketmine\event\player\PlayerEnchantingOptionsRequestEvent;
|
||||
use pocketmine\inventory\CallbackInventoryListener;
|
||||
use pocketmine\inventory\Inventory;
|
||||
use pocketmine\inventory\InventoryListener;
|
||||
use pocketmine\inventory\SimpleInventory;
|
||||
use pocketmine\item\enchantment\EnchantingHelper as Helper;
|
||||
use pocketmine\item\enchantment\EnchantingOption;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\world\Position;
|
||||
use function array_values;
|
||||
use function count;
|
||||
|
||||
final class EnchantingTableInventoryWindow extends BlockInventoryWindow{
|
||||
public const SLOT_INPUT = 0;
|
||||
public const SLOT_LAPIS = 1;
|
||||
|
||||
/** @var EnchantingOption[] $options */
|
||||
private array $options = [];
|
||||
|
||||
/** @phpstan-var \WeakReference<InventoryListener> */
|
||||
private \WeakReference $listener;
|
||||
|
||||
public function __construct(
|
||||
Player $viewer,
|
||||
Position $holder
|
||||
){
|
||||
parent::__construct($viewer, new SimpleInventory(2), $holder);
|
||||
|
||||
/** @phpstan-var \WeakReference<self> $weakThis */
|
||||
$weakThis = \WeakReference::create($this);
|
||||
$listener = new CallbackInventoryListener(
|
||||
onSlotChange: static function(Inventory $_, int $slot) use ($weakThis) : void{ //remaining params unneeded
|
||||
if($slot === self::SLOT_INPUT && ($strongThis = $weakThis->get()) !== null){
|
||||
$strongThis->regenerateOptions();
|
||||
}
|
||||
},
|
||||
onContentChange: static function() use ($weakThis) : void{
|
||||
if(($strongThis = $weakThis->get()) !== null){
|
||||
$strongThis->regenerateOptions();
|
||||
}
|
||||
}
|
||||
);
|
||||
$this->inventory->getListeners()->add($listener);
|
||||
|
||||
$this->listener = \WeakReference::create($listener);
|
||||
}
|
||||
|
||||
public function __destruct(){
|
||||
$listener = $this->listener->get();
|
||||
if($listener !== null){
|
||||
$this->inventory->getListeners()->remove($listener);
|
||||
}
|
||||
}
|
||||
|
||||
private function regenerateOptions() : void{
|
||||
$this->options = [];
|
||||
$item = $this->getInput();
|
||||
$options = Helper::generateOptions($this->holder, $item, $this->viewer->getEnchantmentSeed());
|
||||
|
||||
$event = new PlayerEnchantingOptionsRequestEvent($this->viewer, $this, $options);
|
||||
$event->call();
|
||||
if(!$event->isCancelled() && count($event->getOptions()) > 0){
|
||||
$this->options = array_values($event->getOptions());
|
||||
$this->viewer->getNetworkSession()->getInvManager()?->syncEnchantingTableOptions($this->options);
|
||||
}
|
||||
}
|
||||
|
||||
public function getInput() : Item{
|
||||
return $this->inventory->getItem(self::SLOT_INPUT);
|
||||
}
|
||||
|
||||
public function getLapis() : Item{
|
||||
return $this->inventory->getItem(self::SLOT_LAPIS);
|
||||
}
|
||||
|
||||
public function getOutput(int $optionId) : ?Item{
|
||||
$option = $this->getOption($optionId);
|
||||
return $option === null ? null : Helper::enchantItem($this->getInput(), $option->getEnchantments());
|
||||
}
|
||||
|
||||
public function getOption(int $optionId) : ?EnchantingOption{
|
||||
return $this->options[$optionId] ?? null;
|
||||
}
|
||||
}
|
73
src/block/inventory/window/EnderChestInventoryWindow.php
Normal file
73
src/block/inventory/window/EnderChestInventoryWindow.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory\window;
|
||||
|
||||
use pocketmine\block\tile\EnderChest;
|
||||
use pocketmine\network\mcpe\protocol\BlockEventPacket;
|
||||
use pocketmine\network\mcpe\protocol\types\BlockPosition;
|
||||
use pocketmine\world\Position;
|
||||
use pocketmine\world\sound\EnderChestCloseSound;
|
||||
use pocketmine\world\sound\EnderChestOpenSound;
|
||||
use pocketmine\world\sound\Sound;
|
||||
|
||||
final class EnderChestInventoryWindow extends AnimatedBlockInventoryWindow{
|
||||
|
||||
protected function getViewerCount() : int{
|
||||
$enderChest = $this->holder->getWorld()->getTile($this->getHolder());
|
||||
if(!$enderChest instanceof EnderChest){
|
||||
return 0;
|
||||
}
|
||||
return $enderChest->getViewerCount();
|
||||
}
|
||||
|
||||
private function updateViewerCount(int $amount) : void{
|
||||
$enderChest = $this->holder->getWorld()->getTile($this->getHolder());
|
||||
if($enderChest instanceof EnderChest){
|
||||
$enderChest->setViewerCount($enderChest->getViewerCount() + $amount);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getOpenSound() : Sound{
|
||||
return new EnderChestOpenSound();
|
||||
}
|
||||
|
||||
protected function getCloseSound() : Sound{
|
||||
return new EnderChestCloseSound();
|
||||
}
|
||||
|
||||
protected function animateBlock(Position $position, bool $isOpen) : void{
|
||||
//event ID is always 1 for a chest
|
||||
$position->getWorld()->broadcastPacketToViewers($position, BlockEventPacket::create(BlockPosition::fromVector3($position), 1, $isOpen ? 1 : 0));
|
||||
}
|
||||
|
||||
public function onOpen() : void{
|
||||
parent::onOpen();
|
||||
$this->updateViewerCount(1);
|
||||
}
|
||||
|
||||
public function onClose() : void{
|
||||
parent::onClose();
|
||||
$this->updateViewerCount(-1);
|
||||
}
|
||||
}
|
71
src/block/inventory/window/FurnaceInventoryWindow.php
Normal file
71
src/block/inventory/window/FurnaceInventoryWindow.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory\window;
|
||||
|
||||
use pocketmine\crafting\FurnaceType;
|
||||
use pocketmine\inventory\Inventory;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\world\Position;
|
||||
|
||||
final class FurnaceInventoryWindow extends BlockInventoryWindow{
|
||||
public const SLOT_INPUT = 0;
|
||||
public const SLOT_FUEL = 1;
|
||||
public const SLOT_RESULT = 2;
|
||||
|
||||
public function __construct(
|
||||
Player $viewer,
|
||||
Inventory $inventory,
|
||||
Position $holder,
|
||||
private FurnaceType $furnaceType
|
||||
){
|
||||
parent::__construct($viewer, $inventory, $holder);
|
||||
}
|
||||
|
||||
public function getFurnaceType() : FurnaceType{ return $this->furnaceType; }
|
||||
|
||||
public function getResult() : Item{
|
||||
return $this->inventory->getItem(self::SLOT_RESULT);
|
||||
}
|
||||
|
||||
public function getFuel() : Item{
|
||||
return $this->inventory->getItem(self::SLOT_FUEL);
|
||||
}
|
||||
|
||||
public function getSmelting() : Item{
|
||||
return $this->inventory->getItem(self::SLOT_INPUT);
|
||||
}
|
||||
|
||||
public function setResult(Item $item) : void{
|
||||
$this->inventory->setItem(self::SLOT_RESULT, $item);
|
||||
}
|
||||
|
||||
public function setFuel(Item $item) : void{
|
||||
$this->inventory->setItem(self::SLOT_FUEL, $item);
|
||||
}
|
||||
|
||||
public function setSmelting(Item $item) : void{
|
||||
$this->inventory->setItem(self::SLOT_INPUT, $item);
|
||||
}
|
||||
}
|
28
src/block/inventory/window/HopperInventoryWindow.php
Normal file
28
src/block/inventory/window/HopperInventoryWindow.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory\window;
|
||||
|
||||
final class HopperInventoryWindow extends BlockInventoryWindow{
|
||||
|
||||
}
|
43
src/block/inventory/window/LoomInventoryWindow.php
Normal file
43
src/block/inventory/window/LoomInventoryWindow.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory\window;
|
||||
|
||||
use pocketmine\inventory\SimpleInventory;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\player\TemporaryInventoryWindow;
|
||||
use pocketmine\world\Position;
|
||||
|
||||
final class LoomInventoryWindow extends BlockInventoryWindow implements TemporaryInventoryWindow{
|
||||
|
||||
public const SLOT_BANNER = 0;
|
||||
public const SLOT_DYE = 1;
|
||||
public const SLOT_PATTERN = 2;
|
||||
|
||||
public function __construct(
|
||||
Player $viewer,
|
||||
Position $holder
|
||||
){
|
||||
parent::__construct($viewer, new SimpleInventory(3), $holder);
|
||||
}
|
||||
}
|
46
src/block/inventory/window/ShulkerBoxInventoryWindow.php
Normal file
46
src/block/inventory/window/ShulkerBoxInventoryWindow.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory\window;
|
||||
|
||||
use pocketmine\network\mcpe\protocol\BlockEventPacket;
|
||||
use pocketmine\network\mcpe\protocol\types\BlockPosition;
|
||||
use pocketmine\world\Position;
|
||||
use pocketmine\world\sound\ShulkerBoxCloseSound;
|
||||
use pocketmine\world\sound\ShulkerBoxOpenSound;
|
||||
use pocketmine\world\sound\Sound;
|
||||
|
||||
final class ShulkerBoxInventoryWindow extends AnimatedBlockInventoryWindow{
|
||||
protected function getOpenSound() : Sound{
|
||||
return new ShulkerBoxOpenSound();
|
||||
}
|
||||
|
||||
protected function getCloseSound() : Sound{
|
||||
return new ShulkerBoxCloseSound();
|
||||
}
|
||||
|
||||
protected function animateBlock(Position $position, bool $isOpen) : void{
|
||||
//event ID is always 1 for a chest
|
||||
$position->getWorld()->broadcastPacketToViewers($position, BlockEventPacket::create(BlockPosition::fromVector3($position), 1, $isOpen ? 1 : 0));
|
||||
}
|
||||
}
|
35
src/block/inventory/window/SmithingTableInventoryWindow.php
Normal file
35
src/block/inventory/window/SmithingTableInventoryWindow.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory\window;
|
||||
|
||||
use pocketmine\inventory\SimpleInventory;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\player\TemporaryInventoryWindow;
|
||||
use pocketmine\world\Position;
|
||||
|
||||
final class SmithingTableInventoryWindow extends BlockInventoryWindow implements TemporaryInventoryWindow{
|
||||
public function __construct(Player $viewer, Position $holder){
|
||||
parent::__construct($viewer, new SimpleInventory(3), $holder);
|
||||
}
|
||||
}
|
37
src/block/inventory/window/StonecutterInventoryWindow.php
Normal file
37
src/block/inventory/window/StonecutterInventoryWindow.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory\window;
|
||||
|
||||
use pocketmine\inventory\SimpleInventory;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\player\TemporaryInventoryWindow;
|
||||
use pocketmine\world\Position;
|
||||
|
||||
final class StonecutterInventoryWindow extends BlockInventoryWindow implements TemporaryInventoryWindow{
|
||||
public const SLOT_INPUT = 0;
|
||||
|
||||
public function __construct(Player $viewer, Position $holder){
|
||||
parent::__construct($viewer, new SimpleInventory(1), $holder);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user