mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-14 09:49:50 +00:00
Added CustomInventory, StoneCutter inventory type, network IDs, fixed viewer list bugs
This commit is contained in:
parent
f9103772c3
commit
1fd7e0431b
@ -319,11 +319,11 @@ abstract class BaseInventory implements Inventory{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onOpen(Player $who){
|
public function onOpen(Player $who){
|
||||||
|
$this->viewers->attach($who);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onClose(Player $who){
|
public function onClose(Player $who){
|
||||||
|
$this->viewers->detach($who);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onSlotChange($index, $before){
|
public function onSlotChange($index, $before){
|
||||||
|
@ -24,26 +24,22 @@ namespace pocketmine\inventory;
|
|||||||
use pocketmine\network\protocol\ContainerClosePacket;
|
use pocketmine\network\protocol\ContainerClosePacket;
|
||||||
use pocketmine\network\protocol\ContainerOpenPacket;
|
use pocketmine\network\protocol\ContainerOpenPacket;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
use pocketmine\tile\Chest;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\tile\Furnace;
|
|
||||||
|
|
||||||
abstract class ContainerInventory extends BaseInventory{
|
abstract class ContainerInventory extends BaseInventory{
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Chest|Furnace
|
|
||||||
*/
|
|
||||||
public function getHolder(){
|
|
||||||
return $this->holder;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onOpen(Player $who){
|
public function onOpen(Player $who){
|
||||||
$pk = new ContainerOpenPacket;
|
$pk = new ContainerOpenPacket;
|
||||||
$pk->windowid = $who->getWindowId($this);
|
$pk->windowid = $who->getWindowId($this);
|
||||||
$pk->type = 0;
|
$pk->type = $this->getType()->getNetworkType();
|
||||||
$pk->slots = $this->getSize();
|
$pk->slots = $this->getSize();
|
||||||
$pk->x = $this->getHolder()->getX();
|
if($this->holder instanceof Vector3){
|
||||||
$pk->y = $this->getHolder()->getY();
|
$pk->x = $this->holder->getX();
|
||||||
$pk->z = $this->getHolder()->getZ();
|
$pk->y = $this->holder->getY();
|
||||||
|
$pk->z = $this->holder->getZ();
|
||||||
|
}else{
|
||||||
|
$pk->x = $pk->y = $pk->z = 0;
|
||||||
|
}
|
||||||
|
|
||||||
$who->dataPacket($pk);
|
$who->dataPacket($pk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
29
src/pocketmine/inventory/CustomInventory.php
Normal file
29
src/pocketmine/inventory/CustomInventory.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?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/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\inventory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All plugins that want to create their custom inventory should use this class as a base
|
||||||
|
*/
|
||||||
|
abstract class CustomInventory extends ContainerInventory{
|
||||||
|
|
||||||
|
}
|
@ -31,12 +31,19 @@ class InventoryType{
|
|||||||
const FURNACE = 3;
|
const FURNACE = 3;
|
||||||
const CRAFTING = 4;
|
const CRAFTING = 4;
|
||||||
const WORKBENCH = 5;
|
const WORKBENCH = 5;
|
||||||
|
const STONECUTTER = 6;
|
||||||
|
|
||||||
private static $default = [];
|
private static $default = [];
|
||||||
|
|
||||||
private $size;
|
private $size;
|
||||||
private $title;
|
private $title;
|
||||||
|
private $typeId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $index
|
||||||
|
*
|
||||||
|
* @return InventoryType
|
||||||
|
*/
|
||||||
public static function get($index){
|
public static function get($index){
|
||||||
return isset(static::$default[$index]) ? static::$default[$index] : null;
|
return isset(static::$default[$index]) ? static::$default[$index] : null;
|
||||||
}
|
}
|
||||||
@ -46,21 +53,24 @@ class InventoryType{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static::$default[static::CHEST] = new InventoryType(27, "Chest");
|
static::$default[static::CHEST] = new InventoryType(27, "Chest", 0);
|
||||||
static::$default[static::DOUBLE_CHEST] = new InventoryType(27 + 27, "Double Chest");
|
static::$default[static::DOUBLE_CHEST] = new InventoryType(27 + 27, "Double Chest", 0);
|
||||||
static::$default[static::PLAYER] = new InventoryType(31, "Player"); //27 CONTAINER, 4 ARMOR (9 reference HOTBAR slots)
|
static::$default[static::PLAYER] = new InventoryType(31, "Player", 0); //27 CONTAINER, 4 ARMOR (9 reference HOTBAR slots)
|
||||||
static::$default[static::FURNACE] = new InventoryType(3, "Furnace");
|
static::$default[static::FURNACE] = new InventoryType(3, "Furnace", 2);
|
||||||
static::$default[static::CRAFTING] = new InventoryType(5, "Crafting"); //4 CRAFTING slots, 1 RESULT
|
static::$default[static::CRAFTING] = new InventoryType(5, "Crafting", 1); //4 CRAFTING slots, 1 RESULT
|
||||||
static::$default[static::WORKBENCH] = new InventoryType(10, "Crafting"); //9 CRAFTING slots, 1 RESULT
|
static::$default[static::WORKBENCH] = new InventoryType(10, "Crafting", 1); //9 CRAFTING slots, 1 RESULT
|
||||||
|
static::$default[static::STONECUTTER] = new InventoryType(10, "Crafting", 3); //9 CRAFTING slots, 1 RESULT
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $defaultSize
|
* @param int $defaultSize
|
||||||
* @param string $defaultTitle
|
* @param string $defaultTitle
|
||||||
|
* @param int $typeId
|
||||||
*/
|
*/
|
||||||
private function __construct($defaultSize, $defaultTitle){
|
private function __construct($defaultSize, $defaultTitle, $typeId = 0){
|
||||||
$this->size = $defaultSize;
|
$this->size = $defaultSize;
|
||||||
$this->title = $defaultTitle;
|
$this->title = $defaultTitle;
|
||||||
|
$this->typeId = $typeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,4 +86,11 @@ class InventoryType{
|
|||||||
public function getDefaultTitle(){
|
public function getDefaultTitle(){
|
||||||
return $this->title;
|
return $this->title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getNetworkType(){
|
||||||
|
return $this->typeId;
|
||||||
|
}
|
||||||
}
|
}
|
@ -141,7 +141,7 @@ class PlayerInventory extends BaseInventory{
|
|||||||
if($player === $this->getHolder()){
|
if($player === $this->getHolder()){
|
||||||
//TODO: Check if Mojang enabled sending a single slot this
|
//TODO: Check if Mojang enabled sending a single slot this
|
||||||
//$this->sendSlot($this->getHeldItemSlot());
|
//$this->sendSlot($this->getHeldItemSlot());
|
||||||
$this->sendContents($this->getHolder());
|
$this->sendContents($player);
|
||||||
}else{
|
}else{
|
||||||
$player->dataPacket(clone $pk);
|
$player->dataPacket(clone $pk);
|
||||||
}
|
}
|
||||||
@ -153,11 +153,6 @@ class PlayerInventory extends BaseInventory{
|
|||||||
|
|
||||||
if($index >= $this->getSize()){
|
if($index >= $this->getSize()){
|
||||||
$this->sendArmorContents($this->getHolder()->getViewers());
|
$this->sendArmorContents($this->getHolder()->getViewers());
|
||||||
if($this->getHolder() instanceof Player){
|
|
||||||
$this->sendArmorContents($this->getHolder());
|
|
||||||
}
|
|
||||||
}elseif($this->getHolder() instanceof Player){
|
|
||||||
$this->sendSlot($index, $this->getHolder());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,8 +208,8 @@ class PlayerInventory extends BaseInventory{
|
|||||||
if($index >= $this->getSize()){ //Armor change
|
if($index >= $this->getSize()){ //Armor change
|
||||||
Server::getInstance()->getPluginManager()->callEvent($ev = new EntityArmorChangeEvent($this->getHolder(), $this->getItem($index), $item, $index));
|
Server::getInstance()->getPluginManager()->callEvent($ev = new EntityArmorChangeEvent($this->getHolder(), $this->getItem($index), $item, $index));
|
||||||
if($ev->isCancelled() and $this->getHolder() instanceof Player){
|
if($ev->isCancelled() and $this->getHolder() instanceof Player){
|
||||||
$this->sendArmorContents($this->getHolder());
|
$this->sendArmorContents($this->getViewers());
|
||||||
$this->sendContents($this->getHolder());
|
$this->sendContents($this->getViewers());
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -235,8 +230,8 @@ class PlayerInventory extends BaseInventory{
|
|||||||
if($index >= $this->getSize() and $index < $this->size){ //Armor change
|
if($index >= $this->getSize() and $index < $this->size){ //Armor change
|
||||||
Server::getInstance()->getPluginManager()->callEvent($ev = new EntityArmorChangeEvent($this->getHolder(), $old, $item, $index));
|
Server::getInstance()->getPluginManager()->callEvent($ev = new EntityArmorChangeEvent($this->getHolder(), $old, $item, $index));
|
||||||
if($ev->isCancelled()){
|
if($ev->isCancelled()){
|
||||||
$this->sendArmorContents($this);
|
$this->sendArmorContents($this->getViewers());
|
||||||
$this->sendContents($this);
|
$this->sendContents($this->getViewers());
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user