From d0bfc826ea887dc9d0cb0401aea1f42f78335c5a Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 6 Aug 2015 11:51:41 +0200 Subject: [PATCH] Updated protocol details, anvil menu creation --- src/pocketmine/block/Anvil.php | 2 +- src/pocketmine/inventory/AnvilInventory.php | 25 +++++------ src/pocketmine/inventory/FakeBlockMenu.php | 45 +++++++++++++++++++ src/pocketmine/inventory/InventoryType.php | 2 +- src/pocketmine/network/protocol/Info.php | 2 +- .../network/protocol/StartGamePacket.php | 1 + 6 files changed, 61 insertions(+), 16 deletions(-) create mode 100644 src/pocketmine/inventory/FakeBlockMenu.php diff --git a/src/pocketmine/block/Anvil.php b/src/pocketmine/block/Anvil.php index 30db5c841..3560bb99c 100644 --- a/src/pocketmine/block/Anvil.php +++ b/src/pocketmine/block/Anvil.php @@ -80,7 +80,7 @@ class Anvil extends Fallable{ public function getDrops(Item $item){ return [ - [$this->id, 0, 1], + [$this->id, 0, 1], //TODO break level ]; } } \ No newline at end of file diff --git a/src/pocketmine/inventory/AnvilInventory.php b/src/pocketmine/inventory/AnvilInventory.php index 25e88624d..b0e0115a7 100644 --- a/src/pocketmine/inventory/AnvilInventory.php +++ b/src/pocketmine/inventory/AnvilInventory.php @@ -21,28 +21,27 @@ namespace pocketmine\inventory; -use pocketmine\level\Level; use pocketmine\level\Position; -use pocketmine\math\Vector3; -use pocketmine\network\Network; -use pocketmine\network\protocol\TileEventPacket; use pocketmine\Player; -use pocketmine\Server; -use pocketmine\tile\Chest; -class AnvilInventory extends ContainerInventory implements InventoryHolder{ +class AnvilInventory extends ContainerInventory{ public function __construct(Position $pos){ - parent::__construct($this, InventoryType::get(InventoryType::ANVIL)); - } - - public function getInventory(){ - return $this; + parent::__construct(new FakeBlockMenu($this, $pos), InventoryType::get(InventoryType::ANVIL)); } /** - * @return AnvilInventory + * @return FakeBlockMenu */ public function getHolder(){ return $this->holder; } + + public function onClose(Player $who){ + parent::onClose($who); + + for($i = 0; $i < 2; ++$i){ + $this->getHolder()->getLevel()->dropItem($this->getHolder()->add(0.5, 0.5, 0.5), $this->getItem($i)); + $this->clear($i); + } + } } \ No newline at end of file diff --git a/src/pocketmine/inventory/FakeBlockMenu.php b/src/pocketmine/inventory/FakeBlockMenu.php new file mode 100644 index 000000000..a479b4634 --- /dev/null +++ b/src/pocketmine/inventory/FakeBlockMenu.php @@ -0,0 +1,45 @@ +inventory = $inventory; + parent::__construct($pos->x, $pos->y, $pos->z, $pos->level); + } + + public function getInventory(){ + return $this->inventory; + } +} \ No newline at end of file diff --git a/src/pocketmine/inventory/InventoryType.php b/src/pocketmine/inventory/InventoryType.php index db9f2a99d..7fd05d5a9 100644 --- a/src/pocketmine/inventory/InventoryType.php +++ b/src/pocketmine/inventory/InventoryType.php @@ -65,7 +65,7 @@ class InventoryType{ static::$default[static::STONECUTTER] = new InventoryType(10, "Crafting", 1); //9 CRAFTING slots, 1 RESULT static::$default[static::ENCHANT_TABLE] = new InventoryType(1, "Enchant", 4); //1 INPUT/OUTPUT static::$default[static::BREWING_STAND] = new InventoryType(4, "Brewing", 5); //1 INPUT, 3 POTION - static::$default[static::ANVIL] = new InventoryType(3, "Brewing", 6); //2 INPUT, 1 OUTPUT + static::$default[static::ANVIL] = new InventoryType(3, "Anvil", 6); //2 INPUT, 1 OUTPUT } /** diff --git a/src/pocketmine/network/protocol/Info.php b/src/pocketmine/network/protocol/Info.php index 675350525..79b2127b6 100644 --- a/src/pocketmine/network/protocol/Info.php +++ b/src/pocketmine/network/protocol/Info.php @@ -30,7 +30,7 @@ interface Info{ /** * Actual Minecraft: PE protocol version */ - const CURRENT_PROTOCOL = 31; + const CURRENT_PROTOCOL = 32; const LOGIN_PACKET = 0x87; const PLAY_STATUS_PACKET = 0x88; diff --git a/src/pocketmine/network/protocol/StartGamePacket.php b/src/pocketmine/network/protocol/StartGamePacket.php index 152e0e64a..28df2ec1c 100644 --- a/src/pocketmine/network/protocol/StartGamePacket.php +++ b/src/pocketmine/network/protocol/StartGamePacket.php @@ -56,6 +56,7 @@ class StartGamePacket extends DataPacket{ $this->putFloat($this->x); $this->putFloat($this->y); $this->putFloat($this->z); + $this->putByte(0); } }