diff --git a/src/Player.php b/src/Player.php index 0cb7f8b56..c73c5df69 100644 --- a/src/Player.php +++ b/src/Player.php @@ -51,6 +51,8 @@ class Player{ var $loggedIn = false; public $gamemode; public $lastBreak; + public $windowCnt = 0; + public $windows = array(); private $chunksLoaded = array(); private $chunksOrder = array(); @@ -786,7 +788,44 @@ class Player{ } } break; - case MC_SEND_INVENTORY: //TODO + case MC_CONTAINER_CLOSE: + unset($this->windows[$data["windowid"]]); + $this->dataPacket(MC_CONTAINER_CLOSE, array( + "windowid" => $id, + )); + break; + case MC_CONTAINER_SET_SLOT: + if(!isset($this->windows[$data["windowid"]])){ + break; + } + $tile = $this->windows[$data["windowid"]]; + $done = false; + foreach($tile->data["Items"] as $i => $slot){ + if($slot["Slot"] === $data["slot"]){ + $done = true; + $s = $tile->data["Items"][$i] = array( + "Count" => $data["stack"] & 0xFFFF, + "Slot" => $data["slot"], + "id" => $data["block"] & 0xFFFF, + "Damage" => $data["meta"] & 0xFFFF + ); + break; + } + } + if($done === false){ + $tile->data["Items"][] = $s = array( + "Count" => $data["stack"] & 0xFFFF, + "Slot" => $data["slot"], + "id" => $data["block"] & 0xFFFF, + "Damage" => $data["meta"] & 0xFFFF + ); + } + $this->server->api->dhandle("tile.container.slot", array( + "tile" => $tile, + "slot" => $data["slot"], + )); + break; + case MC_SEND_INVENTORY: //TODO, Mojang, enable this ´^_^` break; default: console("[DEBUG] Unhandled 0x".dechex($data["id"])." Data Packet for Client ID ".$this->clientID.": ".print_r($data, true), true, true, 2); diff --git a/src/material/Block.php b/src/material/Block.php index 7ceec768c..bc54461ee 100644 --- a/src/material/Block.php +++ b/src/material/Block.php @@ -218,5 +218,4 @@ require_once("block/FallableBlock.php"); require_once("block/LiquidBlock.php"); require_once("block/StairBlock.php"); require_once("block/DoorBlock.php"); -require_once("block/ContainerBlock.php"); /***REM_END***/ diff --git a/src/material/block/ContainerBlock.php b/src/material/block/ContainerBlock.php deleted file mode 100644 index a8fb6dfc2..000000000 --- a/src/material/block/ContainerBlock.php +++ /dev/null @@ -1,57 +0,0 @@ -inWorld === true){ - $server = ServerAPI::request(); - $t = $server->api->tileentity->get($this); - if($t !== false){ - if(is_array($t)){ - foreach($t as $ts){ - if($ts->class === TILE_CHEST){ - $server->api->tileentity->remove($ts->id); - } - } - }elseif($t->class === TILE_CHEST){ - $server->api->tileentity->remove($t->id); - } - } - $level->setBlock($this, 0, 0); - return true; - } - return false; - } - - public function onActivate(BlockAPI $level, Item $item, Player $player){ - return false; - } -} \ No newline at end of file diff --git a/src/material/block/solid/Chest.php b/src/material/block/solid/Chest.php index c4dda231a..8e58ed45f 100644 --- a/src/material/block/solid/Chest.php +++ b/src/material/block/solid/Chest.php @@ -25,7 +25,7 @@ the Free Software Foundation, either version 3 of the License, or */ -class ChestBlock extends ContainerBlock{ +class ChestBlock extends SolidBlock{ public function __construct($meta = 0){ parent::__construct(CHEST, $meta, "Chest"); $this->isActivable = true; @@ -39,10 +39,87 @@ class ChestBlock extends ContainerBlock{ 3 => 3, ); $level->setBlock($block, $this->id, $faces[$player->entity->getDirection()]); + $server = ServerAPI::request(); + $server->api->tileentity->add(TILE_CHEST, $this->x, $this->y, $this->z, array( + "Items" => array(), + "id" => TILE_CHEST, + "x" => $this->x, + "y" => $this->y, + "z" => $this->z + )); return true; } return false; } + + public function onBreak(BlockAPI $level, Item $item, Player $player){ + if($this->inWorld === true){ + $server = ServerAPI::request(); + $t = $server->api->tileentity->get($this); + if($t !== false){ + if(is_array($t)){ + foreach($t as $ts){ + if($ts->class === TILE_CHEST){ + $server->api->tileentity->remove($ts->id); + } + } + }elseif($t->class === TILE_CHEST){ + $server->api->tileentity->remove($t->id); + } + } + $level->setBlock($this, 0, 0); + return true; + } + return false; + } + + public function onActivate(BlockAPI $level, Item $item, Player $player){ + $server = ServerAPI::request(); + $t = $server->api->tileentity->get($this); + $chest = false; + if($t !== false){ + if(is_array($t)){ + $chest = array_shift($t); + }else{ + $chest = $t; + } + }else{ + $chest = $server->api->tileentity->add(TILE_CHEST, $this->x, $this->y, $this->z, array( + "Items" => array(), + "id" => TILE_CHEST, + "x" => $this->x, + "y" => $this->y, + "z" => $this->z + )); + } + + if($chest->class !== TILE_CHEST){ + return false; + } + $id = $player->windowCnt = $player->windowCnt++ % 255; + $player->windows[$id] = $chest; + $player->dataPacket(MC_CONTAINER_OPEN, array( + "windowid" => $id, + "type" => WINDOW_CHEST, + "slots" => 27, + "title" => "Chest", + )); + foreach($chest->data["Items"] as $slot){ + if($slot["Slot"] < 0 or $slot["Slot"] >= 27){ + continue; + } + $player->dataPacket(MC_CONTAINER_SET_SLOT, array( + "windowid" => $id, + "slot" => $slot["Slot"], + "block" => $slot["id"], + "stack" => $slot["Count"], + "meta" => $slot["Damage"], + )); + } + + return true; + } + public function getDrops(Item $item, Player $player){ return array( array($this->id, 0, 1),