Double chest checks, chest opening broadcast

This commit is contained in:
Shoghi Cervantes 2013-08-19 21:05:09 +02:00
parent 68e78ba40b
commit 8d408996f4
3 changed files with 67 additions and 24 deletions

View File

@ -31,30 +31,51 @@ class ChestBlock extends TransparentBlock{
$this->isActivable = true;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$block0 = $this->getSide(2);
$block1 = $this->getSide(3);
$block2 = $this->getSide(4);
$block3 = $this->getSide(5);
if($block0->getID() !== CHEST and $block1->getID() !== CHEST and $block2->getID() !== CHEST and $block3->getID() !== CHEST){
$faces = array(
0 => 4,
1 => 2,
2 => 5,
3 => 3,
);
$this->meta = $faces[$player->entity->getDirection()];
$this->level->setBlock($block, $this);
$server = ServerAPI::request();
$server->api->tile->add($this->level, 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;
$faces = array(
0 => 4,
1 => 2,
2 => 5,
3 => 3,
);
$facesc = array(
2 => 4,
3 => 2,
4 => 5,
5 => 3,
);
$chest = false;
for($side = 2; $side <= 5; ++$side){
$c = $this->getSide($side);
if($c instanceof ChestBlock){
/*if($chest !== false){ //No chests in the middle
return false;
}*/
$chest = array($side, $c);
break;
}
return false;
}
if($chest !== false and ($chest[1]->getSide($chest[0]) instanceof ChestBlock)){ //Already double chest
return false;
}
if($chest !== false){
$this->meta = $facesc[$chest[0]];
$this->level->setBlock($chest[1], new ChestBlock($this->meta));
}else{
$this->meta = $faces[$player->entity->getDirection()];
}
$this->level->setBlock($block, $this);
$server = ServerAPI::request();
$server->api->tile->add($this->level, 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;
}
public function onBreak(Item $item, Player $player){
@ -95,6 +116,13 @@ class ChestBlock extends TransparentBlock{
"slots" => CHEST_SLOTS,
"title" => "Chest",
));
$server->api->player->broadcastPacket($server->api->player->getAll($this->level), MC_TILE_EVENT, array(
"x" => $this->x,
"y" => $this->y,
"z" => $this->z,
"case1" => 1,
"case2" => 2,
));
$slots = array();
for($s = 0; $s < CHEST_SLOTS; ++$s){
$slot = $chest->getSlot($s);

View File

@ -492,6 +492,21 @@ class CustomPacketHandler{
$this->raw .= Utils::writeInt($this->data["unknown5"]);
}
break;
case MC_TILE_EVENT:
if($this->c === false){
$this->data["x"] = Utils::readInt($this->get(4));
$this->data["y"] = Utils::readInt($this->get(4));
$this->data["z"] = Utils::readInt($this->get(4));
$this->data["case1"] = Utils::readInt($this->get(4));
$this->data["case2"] = Utils::readInt($this->get(4));
}else{
$this->raw .= Utils::writeInt($this->data["x"]);
$this->raw .= Utils::writeInt($this->data["y"]);
$this->raw .= Utils::writeInt($this->data["z"]);
$this->raw .= Utils::writeInt($this->data["case1"]);
$this->raw .= Utils::writeInt($this->data["case2"]);
}
break;
case MC_ENTITY_EVENT:
if($this->c === false){
$this->data["eid"] = Utils::readInt($this->get(4));

View File

@ -71,7 +71,7 @@ define("MC_UPDATE_BLOCK", 0x97);
define("MC_ADD_PAINTING", 0x98);
define("MC_EXPLOSION", 0x99);
define("MC_LEVEL_EVENT", 0x9a);
//define("MC_TILE_EVENT", 0x9b);
define("MC_TILE_EVENT", 0x9b);
define("MC_ENTITY_EVENT", 0x9c);
define("MC_REQUEST_CHUNK", 0x9d);
define("MC_CHUNK_DATA", 0x9e);