From ccd1231d42b4c1bdb22001c6e91c25d984c64b53 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Wed, 27 Feb 2013 19:32:59 +0100 Subject: [PATCH] Remove Chest TileEntities on break --- src/API/TileEntityAPI.php | 14 +++++-- src/material/Block.php | 1 + src/material/block/ContainerBlock.php | 57 +++++++++++++++++++++++++++ src/material/block/solid/Chest.php | 2 +- src/world/TileEntity.php | 1 + 5 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 src/material/block/ContainerBlock.php diff --git a/src/API/TileEntityAPI.php b/src/API/TileEntityAPI.php index a2777e130..9ad983f0d 100644 --- a/src/API/TileEntityAPI.php +++ b/src/API/TileEntityAPI.php @@ -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){ diff --git a/src/material/Block.php b/src/material/Block.php index 189396e52..c51f66980 100644 --- a/src/material/Block.php +++ b/src/material/Block.php @@ -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***/ diff --git a/src/material/block/ContainerBlock.php b/src/material/block/ContainerBlock.php new file mode 100644 index 000000000..a8fb6dfc2 --- /dev/null +++ b/src/material/block/ContainerBlock.php @@ -0,0 +1,57 @@ +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 17693060f..c4dda231a 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 SolidBlock{ +class ChestBlock extends ContainerBlock{ public function __construct($meta = 0){ parent::__construct(CHEST, $meta, "Chest"); $this->isActivable = true; diff --git a/src/world/TileEntity.php b/src/world/TileEntity.php index db81a02fd..50da034c1 100644 --- a/src/world/TileEntity.php +++ b/src/world/TileEntity.php @@ -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;