Functional Chests

This commit is contained in:
Shoghi Cervantes Pueyo 2013-03-05 20:09:53 +01:00
parent 68d71b367d
commit 4db8c0e68d
4 changed files with 118 additions and 60 deletions

View File

@ -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);

View File

@ -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***/

View File

@ -1,57 +0,0 @@
<?php
/*
-
/ \
/ \
/ PocketMine \
/ MP \
|\ @shoghicp /|
|. \ / .|
| .. \ / .. |
| .. | .. |
| .. | .. |
\ | /
\ | /
\ | /
\ | /
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.
*/
class ContainerBlock extends SolidBlock{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
}
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){
return false;
}
}

View File

@ -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),