Remove Chest TileEntities on break

This commit is contained in:
Shoghi Cervantes Pueyo 2013-02-27 19:32:59 +01:00
parent 69a1c97a36
commit ccd1231d42
5 changed files with 70 additions and 5 deletions

View File

@ -31,10 +31,16 @@ class TileEntityAPI{
$this->server = $server;
}
public function get($x, $y, $z){
$x = (int) $x;
$y = (int) $y;
$z = (int) $z;
public function get($x, $y = false, $z = false){
if(($x instanceof Vector3) or ($x instanceof Block)){
$z = (int) $x->z;
$y = (int) $x->y;
$x = (int) $x->x;
}else{
$x = (int) $x;
$y = (int) $y;
$z = (int) $z;
}
$tiles = $this->server->query("SELECT * FROM tileentities WHERE x = $x AND y = $y AND z = $z;");
$ret = array();
if($tiles !== false and $tiles !== true){

View File

@ -205,4 +205,5 @@ 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

@ -0,0 +1,57 @@
<?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 SolidBlock{
class ChestBlock extends ContainerBlock{
public function __construct($meta = 0){
parent::__construct(CHEST, $meta, "Chest");
$this->isActivable = true;

View File

@ -27,6 +27,7 @@ the Free Software Foundation, either version 3 of the License, or
define("TILE_SIGN", "Sign");
define("TILE_CHEST", "Chest");
class TileEntity extends stdClass{
public $name;