From 5938747083edf74be10b836f9752431f2bcea42b Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Tue, 14 May 2013 19:25:55 +0200 Subject: [PATCH] PMF & Multiworld [part 2] --- src/API/BlockAPI.php | 2 +- src/API/LevelAPI.php | 2 +- src/API/PlayerAPI.php | 21 +++++++-- src/API/TileEntityAPI.php | 4 +- src/PocketMinecraftServer.php | 8 ++-- src/dependencies.php | 2 +- src/functions.php | 7 ++- src/material/Item.php | 2 +- src/material/block/DoorBlock.php | 38 ++++++++-------- src/material/block/StairBlock.php | 27 +++++------- src/material/block/attachable/Ladder.php | 11 +++-- src/material/block/attachable/SignPost.php | 42 ++++++++---------- src/material/block/attachable/Torch.php | 41 ++++++++--------- src/material/block/attachable/Trapdoor.php | 11 ++--- src/material/block/attachable/WallSign.php | 41 +++-------------- src/material/block/misc/Bed.php | 44 +++++++++---------- src/material/block/ore/GlowingRedstoneOre.php | 4 +- src/material/block/ore/RedstoneOre.php | 6 +-- src/material/block/plant/BrownMushroom.php | 6 +-- src/material/block/plant/Cactus.php | 16 +++---- src/material/block/plant/CyanFlower.php | 8 ++-- src/material/block/plant/Dandelion.php | 8 ++-- src/material/block/plant/MelonStem.php | 13 +++--- src/material/block/plant/RedMushroom.php | 8 ++-- src/material/block/plant/Sapling.php | 9 ++-- src/material/block/plant/Sugarcane.php | 28 ++++-------- src/material/block/plant/Wheat.php | 17 ++++--- src/material/block/solid/BurningFurnace.php | 20 ++++----- src/material/block/solid/Chest.php | 33 ++++++-------- src/material/block/solid/Dirt.php | 4 +- src/material/block/solid/FenceGate.php | 8 ++-- src/material/block/solid/Grass.php | 10 ++--- src/material/block/solid/Slab.php | 15 +++---- src/material/item/generic/Bucket.php | 4 +- src/material/item/generic/LavaBucket.php | 4 +- src/material/item/generic/Painting.php | 7 ++- src/material/item/generic/WaterBucket.php | 4 +- src/world/Entity.php | 4 +- src/world/TileEntity.php | 1 + 39 files changed, 239 insertions(+), 301 deletions(-) diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index 24b211908..493c222c9 100644 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -345,7 +345,7 @@ class BlockAPI{ return false; } - if($item->isActivable === true and $item->onActivate($this, $player, $block, $target, $face, $fx, $fy, $fz)){ + if($item->isActivable === true and $item->onActivate($player, $block, $target, $face, $fx, $fy, $fz)){ return $this->cancelAction($block, $player); } diff --git a/src/API/LevelAPI.php b/src/API/LevelAPI.php index 2be425878..f6a075816 100644 --- a/src/API/LevelAPI.php +++ b/src/API/LevelAPI.php @@ -52,7 +52,7 @@ class LevelAPI{ $gen->init(); $gen->generate(); $gen->save($path, $this->default); - $this->loadLevel($this->default) + $this->loadLevel($this->default); } } diff --git a/src/API/PlayerAPI.php b/src/API/PlayerAPI.php index e5cf3da70..8c2dd4fb0 100644 --- a/src/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -243,21 +243,34 @@ class PlayerAPI{ return false; } $CID = $this->server->query("SELECT ip,port FROM players WHERE name ".($alike === true ? "LIKE '%".$name."%'":"= '".$name."'").";", true); - $CID = $this->server->clientID($CID["ip"], $CID["port"]); + $CID = PocketMinecraftServer::clientID($CID["ip"], $CID["port"]); if(isset($this->server->clients[$CID])){ return $this->server->clients[$CID]; } return false; } - public function getAll(){ + public function getAll($level = null){ + if($level instanceof Level){ + $clients = array(); + $l = $this->server->query("SELECT EID FROM entities WHERE level = '".$this->level->getName()."' AND class = '".ENTITY_PLAYER."';"); + if($l !== false and $l !== true){ + while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){ + $e = $this->getByEID($e["EID"]); + if($e instanceof Player){ + $clients[$e->clientID] = $e->player; + } + } + } + return $clients; + } return $this->server->clients; } public function getByEID($eid){ $eid = (int) $eid; $CID = $this->server->query("SELECT ip,port FROM players WHERE EID = '".$eid."';", true); - $CID = $this->server->clientID($CID["ip"], $CID["port"]); + $CID = PocketMinecraftServer::clientID($CID["ip"], $CID["port"]); if(isset($this->server->clients[$CID])){ return $this->server->clients[$CID]; } @@ -267,7 +280,7 @@ class PlayerAPI{ public function getByClientID($clientID){ $clientID = (int) $clientID; $CID = $this->server->query("SELECT ip,port FROM players WHERE clientID = '".$clientID."';", true); - $CID = $this->server->clientID($CID["ip"], $CID["port"]); + $CID = PocketMinecraftServer::clientID($CID["ip"], $CID["port"]); if(isset($this->server->clients[$CID])){ return $this->server->clients[$CID]; } diff --git a/src/API/TileEntityAPI.php b/src/API/TileEntityAPI.php index 33320f54f..182451907 100644 --- a/src/API/TileEntityAPI.php +++ b/src/API/TileEntityAPI.php @@ -90,7 +90,7 @@ class TileEntityAPI{ } public function addSign(Level $level, $x, $y, $z, $lines = array("", "", "", "")){ - return $this->add(TILE_SIGN, $x, $y, $z, $data = array( + return $this->add($level, TILE_SIGN, $x, $y, $z, $data = array( "id" => "Sign", "x" => $x, "y" => $y, @@ -110,7 +110,7 @@ class TileEntityAPI{ $t->spawn($player, $queue); } - public function spawnToAll($id){ + public function spawnToAll(Level $level, $id){ $t = $this->getByID($id); if($t === false){ return false; diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index 3aae2d393..6faa58680 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -40,6 +40,7 @@ class PocketMinecraftServer{ if($this->port < 19132 or $this->port > 19135){ //Mojang =( console("[WARNING] You've selected a not-standard port. Normal port range is from 19132 to 19135 included"); } + define("BOOTUP_RANDOM", Utils::getRandomBytes(16)); $this->serverID = $this->serverID === false ? Utils::readLong(Utils::getRandomBytes(8, false)):$this->serverID; $this->seed = $this->seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)):$this->seed; $this->startDatabase(); @@ -333,13 +334,14 @@ class PocketMinecraftServer{ } } - public function clientID($ip, $port){ - return md5($ip . $port, true) ^ sha1($port . $ip, true); + public static function clientID($ip, $port){ + //faster than string indexes in PHP + return crc32($ip . $port) ^ crc32($port . $ip . BOOTUP_RANDOM); } public function packetHandler($packet){ $data =& $packet["data"]; - $CID = $this->clientID($packet["ip"], $packet["port"]); + $CID = PocketMinecraftServer::clientID($packet["ip"], $packet["port"]); if(isset($this->clients[$CID])){ $this->clients[$CID]->handle($packet["pid"], $data); }else{ diff --git a/src/dependencies.php b/src/dependencies.php index b2cfbd096..61840056e 100644 --- a/src/dependencies.php +++ b/src/dependencies.php @@ -37,7 +37,7 @@ if(arg("enable-ansi", strpos(strtoupper(php_uname("s")), "WIN") === false ? true define("ENABLE_ANSI", false); } -set_error_handler("fatal_handler", E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_RECOVERABLE_ERROR | E_DEPRECATED); +set_error_handler("error_handler", E_ALL); $errors = 0; diff --git a/src/functions.php b/src/functions.php index b5b5b991e..2e545ba05 100644 --- a/src/functions.php +++ b/src/functions.php @@ -216,9 +216,12 @@ function console($message, $EOL = true, $log = true, $level = 1){ } } -function fatal_handler($errno, $errstr, $errfile, $errline){ +function error_handler($errno, $errstr, $errfile, $errline){ + if(error_reporting() === 0){ //@ error-control + return false; + } console("[ERROR] A level ".$errno." error happened: \"$errstr\" in \"$errfile\" at line $errline", true, true, 0); - return false; + return true; } function logg($message, $name, $EOL = true, $level = 2, $close = false){ diff --git a/src/material/Item.php b/src/material/Item.php index 72ab0b810..99b588d0e 100644 --- a/src/material/Item.php +++ b/src/material/Item.php @@ -143,7 +143,7 @@ class Item{ return 1; } - public function onActivate(BlockAPI $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ return false; } diff --git a/src/material/block/DoorBlock.php b/src/material/block/DoorBlock.php index 3f588604c..c98a9f354 100644 --- a/src/material/block/DoorBlock.php +++ b/src/material/block/DoorBlock.php @@ -30,10 +30,10 @@ class DoorBlock extends TransparentBlock{ parent::__construct($id, $meta, $name); } - public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - if($block->inWorld === true and $face === 1){ - $blockUp = $level->getBlockFace($block, 1); - $blockDown = $level->getBlockFace($block, 0); + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + if($face === 1){ + $blockUp = $this->getSide(1); + $blockDown = $this->getSide(0); if($blockUp->isReplaceable === false or $blockDown->isTransparent === true){ return false; } @@ -44,52 +44,50 @@ class DoorBlock extends TransparentBlock{ 2 => 2, 3 => 5, ); - $next = $level->getBlockFace($block, $face[(($direction + 2) % 4)]); - $next2 = $level->getBlockFace($block, $face[$direction]); + $next = $this->getSide($face[(($direction + 2) % 4)]); + $next2 = $this->getSide($face[$direction]); $metaUp = 0x08; if($next->getID() === $this->id or ($next2->isTransparent === false and $next->isTransparent === true)){ //Door hinge $metaUp |= 0x01; } - $level->setBlock($blockUp, $this->id, $metaUp); //Top + $this->level->setBlock($blockUp, BlockAPI::get($this->id, $metaUp)); //Top $this->meta = $direction & 0x03; - $level->setBlock($block, $this->id, $this->meta); //Bottom + $this->level->setBlock($block, $this); //Bottom return true; } return false; } - public function onBreak(BlockAPI $level, Item $item, Player $player){ - if($this->inWorld === true){ + public function onBreak(Item $item, Player $player){ if(($this->meta & 0x08) === 0x08){ - $down = $level->getBlockFace($this, 0); + $down = $this->getSide(0); if($down->getID() === $this->id){ - $level->setBlock($down, 0, 0); + $this->level->setBlock($down, new AirBlock()); } }else{ - $up = $level->getBlockFace($this, 1); + $up = $this->getSide(1); if($up->getID() === $this->id){ - $level->setBlock($up, 0, 0); + $this->level->setBlock($up, new AirBlock()); } } - $level->setBlock($this, 0, 0); + $this->level->setBlock($this, new AirBlock()); return true; - } return false; } - public function onActivate(BlockAPI $level, Item $item, Player $player){ + public function onActivate(Item $item, Player $player){ if(($this->meta & 0x08) === 0x08){ //Top - $down = $level->getBlockFace($this, 0); + $down = $this->getSide(0); if($down->getID() === $this->id){ $meta = $down->getMetadata() ^ 0x04; - $level->setBlock($down, $this->id, $meta); + $this->level->setBlock($down, BlockAPI::get($this->id, $meta)); return true; } return false; }else{ $this->meta ^= 0x04; - $level->setBlock($this, $this->id, $this->meta); + $this->level->setBlock($this, $this); } return true; } diff --git a/src/material/block/StairBlock.php b/src/material/block/StairBlock.php index 7aca67aca..b4bb4c10b 100644 --- a/src/material/block/StairBlock.php +++ b/src/material/block/StairBlock.php @@ -30,22 +30,19 @@ class StairBlock extends TransparentBlock{ parent::__construct($id, $meta, $name); } - public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - if($block->inWorld === true){ - $faces = array( - 0 => 0, - 1 => 2, - 2 => 1, - 3 => 3, - ); - $this->meta = $faces[$player->entity->getDirection()] & 0x03; - if(($fy > 0.5 and $face !== 1) or $face === 0){ - $this->meta |= 0x04; //Upside-down stairs - } - $level->setBlock($block, $this->id, $this->meta); - return true; + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + $faces = array( + 0 => 0, + 1 => 2, + 2 => 1, + 3 => 3, + ); + $this->meta = $faces[$player->entity->getDirection()] & 0x03; + if(($fy > 0.5 and $face !== 1) or $face === 0){ + $this->meta |= 0x04; //Upside-down stairs } - return false; + $this->level->setBlock($block, $this); + return true; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/attachable/Ladder.php b/src/material/block/attachable/Ladder.php index 8d2dc3cb9..e380037c9 100644 --- a/src/material/block/attachable/Ladder.php +++ b/src/material/block/attachable/Ladder.php @@ -29,18 +29,17 @@ class LadderBlock extends TransparentBlock{ public function __construct($meta = 0){ parent::__construct(LADDER, $meta, "Ladder"); } - public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - if($block->inWorld === true){ - if($target->isTransparent === false){ + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + if($target->isTransparent === false){ $faces = array( 2 => 2, 3 => 3, 4 => 4, 5 => 5, ); - $level->setBlock($block, $this->id, $faces[$face]); - return true; - } + $this->meta = $faces[$face]; + $this->level->setBlock($block, $this); + return true; } return false; } diff --git a/src/material/block/attachable/SignPost.php b/src/material/block/attachable/SignPost.php index 969d61573..353a5e702 100644 --- a/src/material/block/attachable/SignPost.php +++ b/src/material/block/attachable/SignPost.php @@ -30,34 +30,30 @@ class SignPostBlock extends TransparentBlock{ parent::__construct(SIGN_POST, $meta, "Sign Post"); } - public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - if($block->inWorld === true and $face !== 0){ - if($face !== 0){ - $faces = array( - 2 => 2, - 3 => 3, - 4 => 4, - 5 => 5, - ); - if(!isset($faces[$face])){ - $b = floor((($player->entity->yaw + 180) * 16 / 360) + 0.5) & 0x0F; - $level->setBlock($block, SIGN_POST, $b); - return true; - }else{ - $level->setBlock($block, WALL_SIGN, $faces[$face]); - return true; - } + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + if($face !== 0){ + $faces = array( + 2 => 2, + 3 => 3, + 4 => 4, + 5 => 5, + ); + if(!isset($faces[$face])){ + $this->meta = floor((($player->entity->yaw + 180) * 16 / 360) + 0.5) & 0x0F; + $this->level->setBlock($block, BlockAPI::get(SIGN_POST, $this->meta)); + return true; + }else{ + $this->meta = $faces[$face]; + $this->level->setBlock($block, BlockAPI::get(WALL_SIGN, $this->meta)); + return true; } } return false; } - public function onBreak(BlockAPI $level, Item $item, Player $player){ - if($this->inWorld === true){ - $level->setBlock($this, 0, 0, true, true); - return true; - } - return false; + public function onBreak(Item $item, Player $player){ + $this->level->setBlock($this, new AirBlock(), true, true); + return true; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/attachable/Torch.php b/src/material/block/attachable/Torch.php index b2a1d8f7c..11b8aa11b 100644 --- a/src/material/block/attachable/Torch.php +++ b/src/material/block/attachable/Torch.php @@ -30,7 +30,7 @@ class TorchBlock extends FlowableBlock{ parent::__construct(TORCH, $meta, "Torch"); } - public function onUpdate(BlockAPI $level, $type){ + public function onUpdate($type){ if($type === BLOCK_UPDATE_NORMAL){ $side = $this->getMetadata(); $faces = array( @@ -42,31 +42,32 @@ class TorchBlock extends FlowableBlock{ 6 => 0, 0 => 0, ); - if($level->getBlockFace($this, $faces[$side])->isTransparent === true){ - $level->drop($this, BlockAPI::getItem($this->id)); - $level->setBlock($this, AIR, 0, false); + + if($this->getSide($faces[$side])->isTransparent === true){ //Replace wit hcommon break method + ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id)); + $this->level->setBlock($this, new AirBlock(), false); return BLOCK_UPDATE_NORMAL; } } return false; } - public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - if($block->inWorld === true){ - if($target->isTransparent === false and $face !== 0){ - $faces = array( - 1 => 5, - 2 => 4, - 3 => 3, - 4 => 2, - 5 => 1, - ); - $level->setBlock($block, $this->id, $faces[$face]); - return true; - }elseif($level->getBlockFace($block, 0)->isTransparent === false){ - $level->setBlock($block, $this->id, 5); - return true; - } + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + if($target->isTransparent === false and $face !== 0){ + $faces = array( + 1 => 5, + 2 => 4, + 3 => 3, + 4 => 2, + 5 => 1, + ); + $this->meta = $faces[$face]; + $this->level->setBlock($block, $this); + return true; + }elseif($this->getSide(0)->isTransparent === false){ + $this->meta = 0; + $this->level->setBlock($block, $this); + return true; } return false; } diff --git a/src/material/block/attachable/Trapdoor.php b/src/material/block/attachable/Trapdoor.php index d89dc1862..86663434a 100644 --- a/src/material/block/attachable/Trapdoor.php +++ b/src/material/block/attachable/Trapdoor.php @@ -30,8 +30,7 @@ class TrapdoorBlock extends TransparentBlock{ parent::__construct(TRAPDOOR, $meta, "Trapdoor"); $this->isActivable = true; } - public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - if($block->inWorld === true){ + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ if($target->isTransparent === false and $face !== 0 and $face !== 1){ $faces = array( 2 => 0, @@ -43,20 +42,18 @@ class TrapdoorBlock extends TransparentBlock{ if($fy > 0.5){ $this->meta |= 0x08; } - $level->setBlock($block, $this->id, $this->meta); + $this->level->setBlock($block, $this); return true; } - } - return false; } public function getDrops(Item $item, Player $player){ return array( array($this->id, 0, 1), ); } - public function onActivate(BlockAPI $level, Item $item, Player $player){ + public function onActivate(Item $item, Player $player){ $this->meta ^= 0x04; - $level->setBlock($this, $this->id, $this->meta); + $this->level->setBlock($this, $this); return true; } } \ No newline at end of file diff --git a/src/material/block/attachable/WallSign.php b/src/material/block/attachable/WallSign.php index d68397054..5218851eb 100644 --- a/src/material/block/attachable/WallSign.php +++ b/src/material/block/attachable/WallSign.php @@ -25,44 +25,13 @@ the Free Software Foundation, either version 3 of the License, or */ -class WallSignBlock extends TransparentBlock{ +/***REM_START***/ +require_once("SignPost.php"); +/***REM_END***/ + +class WallSignBlock extends SignPostBlock{ public function __construct($meta = 0){ parent::__construct(WALL_SIGN, $meta, "Wall Sign"); } - public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - if($block->inWorld === true and $face !== 0){ - if($face !== 0){ - $faces = array( - 2 => 2, - 3 => 3, - 4 => 4, - 5 => 5, - ); - if(!isset($faces[$face])){ - $level->setBlock($block, SIGN_POST, 0); - return true; - }else{ - $level->setBlock($block, WALL_SIGN, $faces[$face]); - return true; - } - } - } - return false; - } - - public function onBreak(BlockAPI $level, Item $item, Player $player){ - if($this->inWorld === true){ - $level->setBlock($this, AIR, 0, true, true); - return true; - } - return false; - } - - public function getDrops(Item $item, Player $player){ - return array( - array(SIGN, 0, 1), - ); - } - } \ No newline at end of file diff --git a/src/material/block/misc/Bed.php b/src/material/block/misc/Bed.php index 07916510d..c6d7f6a39 100644 --- a/src/material/block/misc/Bed.php +++ b/src/material/block/misc/Bed.php @@ -31,9 +31,8 @@ class BedBlock extends TransparentBlock{ $this->isActivable = true; } - public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - if($block->inWorld === true){ - $down = $level->getBlockFace($block, 0); + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + $down = $this->getSide(0); if($down->isTransparent === false){ $faces = array( 0 => 3, @@ -42,50 +41,47 @@ class BedBlock extends TransparentBlock{ 3 => 5, ); $d = $player->entity->getDirection(); - $next = $level->getBlockFace($block, $faces[(($d + 3) % 4)]); - $downNext = $level->getBlockFace($next, 0); + $next = $this->level->getBlockFace($block, $faces[(($d + 3) % 4)]); + $downNext = $this->level->getBlockFace($next, 0); if($next->isReplaceable === true and $downNext->isTransparent === false){ $meta = (($d + 3) % 4) & 0x03; - $level->setBlock($block, $this->id, $meta); - $level->setBlock($next, $this->id, $meta | 0x08); + $this->level->setBlock($block, BlockAPI::get($this->id, $meta)); + $this->level->setBlock($next, BlockAPI::get($this->id, $meta | 0x08)); return true; } } - } return false; } - public function onBreak(BlockAPI $level, Item $item, Player $player){ - if($this->inWorld === true){//Checks if the block was in the world or not. Just in case - $blockNorth = $level->getBlockFace($this, 2); //Gets the blocks around them - $blockSouth = $level->getBlockFace($this, 3); - $blockEast = $level->getBlockFace($this, 5); - $blockWest = $level->getBlockFace($this, 4); + public function onBreak(Item $item, Player $player){ + $blockNorth = $this->getSide(2); //Gets the blocks around them + $blockSouth = $this->getSide(3); + $blockEast = $this->getSide(5); + $blockWest = $this->getSide(4); if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed if($blockNorth->getID() === $this->id and $blockNorth->meta !== 0x08){ //Checks if the block ID and meta are right - $level->setBlock($blockNorth, AIR, 0); + $this->level->setBlock($blockNorth, new AirBlock()); }elseif($blockSouth->getID() === $this->id and $blockSouth->meta !== 0x08){ - $level->setBlock($blockSouth, AIR, 0); + $this->level->setBlock($blockSouth, new AirBlock()); }elseif($blockEast->getID() === $this->id and $blockEast->meta !== 0x08){ - $level->setBlock($blockEast, AIR, 0); + $this->level->setBlock($blockEast, new AirBlock()); }elseif($blockWest->getID() === $this->id and $blockWest->meta !== 0x08){ - $level->setBlock($blockWest, AIR, 0); + $this->level->setBlock($blockWest, new AirBlock()); } }else{ //Bottom Part of Bed if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){ - $level->setBlock($blockNorth, AIR, 0); + $this->level->setBlock($blockNorth, new AirBlock()); }elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){ - $level->setBlock($blockSouth, AIR, 0); + $this->level->setBlock($blockSouth, new AirBlock()); }elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){ - $level->setBlock($blockEast, AIR, 0); + $this->level->setBlock($blockEast, new AirBlock()); }elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){ - $level->setBlock($blockWest, AIR, 0); + $this->level->setBlock($blockWest, new AirBlock()); } } - $level->setBlock($this, AIR, 0); + $this->level->setBlock($this, new AirBlock()); return true; - } } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/ore/GlowingRedstoneOre.php b/src/material/block/ore/GlowingRedstoneOre.php index ff925e3c5..b46ed78d0 100644 --- a/src/material/block/ore/GlowingRedstoneOre.php +++ b/src/material/block/ore/GlowingRedstoneOre.php @@ -30,9 +30,9 @@ class GlowingRedstoneOreBlock extends SolidBlock{ parent::__construct(GLOWING_REDSTONE_ORE, 0, "Glowing Redstone Ore"); } - public function onUpdate(BlockAPI $level, $type){ + public function onUpdate($type){ if($type === BLOCK_UPDATE_SCHEDULED or $type === BLOCK_UPDATE_RANDOM){ - $level->setBlock($this, REDSTONE_ORE, $this->getMetadata(), false); + $this->level->setBlock($this, BlockAPI::get(REDSTONE_ORE, $this->meta), false); return BLOCK_UPDATE_WEAK; }else{ $level->scheduleBlockUpdate($this, mt_rand(45, 100)); diff --git a/src/material/block/ore/RedstoneOre.php b/src/material/block/ore/RedstoneOre.php index 8effc8805..6231eac79 100644 --- a/src/material/block/ore/RedstoneOre.php +++ b/src/material/block/ore/RedstoneOre.php @@ -30,10 +30,10 @@ class RedstoneOreBlock extends SolidBlock{ parent::__construct(REDSTONE_ORE, 0, "Redstone Ore"); } - public function onUpdate(BlockAPI $level, $type){ + public function onUpdate($type){ if($type === BLOCK_UPDATE_NORMAL or $type === BLOCK_UPDATE_TOUCH){ - $level->setBlock($this, GLOWING_REDSTONE_ORE, $this->getMetadata(), false); - $level->scheduleBlockUpdate($this, mt_rand(45, 100)); + $this->level->setBlock($this, GLOWING_REDSTONE_ORE, $this->getMetadata(), false); + $this->level->scheduleBlockUpdate($this, mt_rand(45, 100)); return BLOCK_UPDATE_WEAK; } return false; diff --git a/src/material/block/plant/BrownMushroom.php b/src/material/block/plant/BrownMushroom.php index ae6236f5a..8340f5964 100644 --- a/src/material/block/plant/BrownMushroom.php +++ b/src/material/block/plant/BrownMushroom.php @@ -31,14 +31,12 @@ class BrownMushroomBlock extends FlowableBlock{ $this->isFlowable = true; } - public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - if($block->inWorld === true){ - $down = $level->getBlockFace($block, 0); + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + $down = $this->getSide(0); if($down->isTransparent === false){ $level->setBlock($block, $this->id, $this->getMetadata()); return true; } - } return false; } } \ No newline at end of file diff --git a/src/material/block/plant/Cactus.php b/src/material/block/plant/Cactus.php index 16f7498d3..c161051c1 100644 --- a/src/material/block/plant/Cactus.php +++ b/src/material/block/plant/Cactus.php @@ -30,20 +30,18 @@ class CactusBlock extends TransparentBlock{ parent::__construct(CACTUS, 0, "Cactus"); } - public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - if($block->inWorld === true){ - $down = $level->getBlockFace($block, 0); + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + $down = $this->getSide(0); if($down->getID() === SAND or $down->getID() === CACTUS){ - $block0 = $level->getBlockFace($block, 2); - $block1 = $level->getBlockFace($block, 3); - $block2 = $level->getBlockFace($block, 4); - $block3 = $level->getBlockFace($block, 5); + $block0 = $this->getSide(2); + $block1 = $this->getSide(3); + $block2 = $this->getSide(4); + $block3 = $this->getSide(5); if($block0->isFlowable === true and $block1->isFlowable === true and $block2->isFlowable === true and $block3->isFlowable === true){ - $level->setBlock($block, $this->id, 0); + $this->level->setBlock($block, $this); return true; } } - } return false; } diff --git a/src/material/block/plant/CyanFlower.php b/src/material/block/plant/CyanFlower.php index 1359809d3..2614dce7e 100644 --- a/src/material/block/plant/CyanFlower.php +++ b/src/material/block/plant/CyanFlower.php @@ -30,14 +30,12 @@ class CyanFlowerBlock extends FlowableBlock{ parent::__construct(CYAN_FLOWER, 0, "Cyan Flower"); $this->isFlowable = true; } - public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - if($block->inWorld === true){ - $down = $level->getBlockFace($block, 0); + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + $down = $this->getSide(0); if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){ - $level->setBlock($block, $this->id, $this->getMetadata()); + $this->level->setBlock($block, $this); return true; } - } return false; } } \ No newline at end of file diff --git a/src/material/block/plant/Dandelion.php b/src/material/block/plant/Dandelion.php index 74b125757..10c255d53 100644 --- a/src/material/block/plant/Dandelion.php +++ b/src/material/block/plant/Dandelion.php @@ -30,14 +30,12 @@ class DandelionBlock extends FlowableBlock{ parent::__construct(DANDELION, 0, "Dandelion"); $this->isFlowable = true; } - public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - if($block->inWorld === true){ - $down = $level->getBlockFace($block, 0); + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + $down = $this->getSide(0); if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){ - $level->setBlock($block, $this->id, $this->getMetadata()); + $this->level->setBlock($block, $this); return true; } - } return false; } } \ No newline at end of file diff --git a/src/material/block/plant/MelonStem.php b/src/material/block/plant/MelonStem.php index cd8be5de6..0cdfa1bcc 100644 --- a/src/material/block/plant/MelonStem.php +++ b/src/material/block/plant/MelonStem.php @@ -30,20 +30,19 @@ class MelonStemBlock extends TransparentBlock{ parent::__construct(MELON_STEM, $meta, "Melon Stem"); $this->isActivable = true; } - public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - if($block->inWorld === true){ - $down = $level->getBlockFace($block, 0); + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + $down = $this->getSide(0); if($down->getID() === FARMLAND){ - $level->setBlock($block, $this->id, $this->getMetadata()); + $this->level->setBlock($block, $this); return true; } - } return false; } - public function onActivate(BlockAPI $level, Item $item, Player $player){ + public function onActivate(Item $item, Player $player){ if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal - $level->setBlock($this, $this->id, 0x07); + $this->meta = 0x07; + $this->level->setBlock($this, $this); return true; } return false; diff --git a/src/material/block/plant/RedMushroom.php b/src/material/block/plant/RedMushroom.php index 9c45b618a..37960799e 100644 --- a/src/material/block/plant/RedMushroom.php +++ b/src/material/block/plant/RedMushroom.php @@ -31,14 +31,12 @@ class RedMushroomBlock extends FlowableBlock{ $this->isFlowable = true; } - public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - if($block->inWorld === true){ - $down = $level->getBlockFace($block, 0); + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + $down = $this->getSide(0); if($down->isTransparent === false){ - $level->setBlock($block, $this->id, $this->getMetadata()); + $this->level->setBlock($block, $this); return true; } - } return false; } } \ No newline at end of file diff --git a/src/material/block/plant/Sapling.php b/src/material/block/plant/Sapling.php index 7a36526dd..917db46ab 100644 --- a/src/material/block/plant/Sapling.php +++ b/src/material/block/plant/Sapling.php @@ -43,7 +43,8 @@ class SaplingBlock extends TransparentBlock{ $this->name = $names[$this->meta & 0x03]; } - public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + console("SAPLING SAPLING SAPLING");return false; //Placeholder if($block->inWorld === true){ $down = $level->getBlockFace($block, 0); if($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === FARMLAND){ @@ -54,7 +55,8 @@ class SaplingBlock extends TransparentBlock{ return false; } - public function onActivate(BlockAPI $level, Item $item, Player $player){ + public function onActivate(Item $item, Player $player){ + console("SAPLING SAPLING SAPLING");return false; //Placeholder if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal TreeObject::growTree($level, $this); return true; @@ -62,7 +64,8 @@ class SaplingBlock extends TransparentBlock{ return false; } - public function onUpdate(BlockAPI $level, $type){ + public function onUpdate($type){ + console("SAPLING SAPLING SAPLING");return false; //Placeholder if($this->inWorld !== true){ return false; } diff --git a/src/material/block/plant/Sugarcane.php b/src/material/block/plant/Sugarcane.php index e40e19fb9..f1e0cb86f 100644 --- a/src/material/block/plant/Sugarcane.php +++ b/src/material/block/plant/Sugarcane.php @@ -36,34 +36,24 @@ class SugarcaneBlock extends TransparentBlock{ ); } - public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - if($block->inWorld === true){ - $down = $level->getBlockFace($block, 0); + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + $down = $this->getSide(0); if($down->getID() === SUGARCANE_BLOCK){ - $level->setBlock($block, $this->id, 0); + $this->level->setBlock($block, new SugarcaneBlock()); return true; }elseif($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === SAND){ - $block0 = $level->getBlockFace($down, 2); - $block1 = $level->getBlockFace($down, 3); - $block2 = $level->getBlockFace($down, 4); - $block3 = $level->getBlockFace($down, 5); - /*$block4 = $level->getBlockFace($block, 2); - $block5 = $level->getBlockFace($block, 3); - $block6 = $level->getBlockFace($block, 4); - $block7 = $level->getBlockFace($block, 5);*/ + $block0 = $this->getSide(2); + $block1 = $this->getSide(3); + $block2 = $this->getSide(4); + $block3 = $this->getSide(5); if($block0->getID() === WATER or $block0->getID() === STILL_WATER or $block1->getID() === WATER or $block1->getID() === STILL_WATER or $block2->getID() === WATER or $block2->getID() === STILL_WATER - or $block3->getID() === WATER or $block3->getID() === STILL_WATER - /*or $block4->getID() === WATER or $block4->getID() === STILL_WATER - or $block5->getID() === WATER or $block5->getID() === STILL_WATER - or $block6->getID() === WATER or $block6->getID() === STILL_WATER - or $block7->getID() === WATER or $block7->getID() === STILL_WATER*/){ - $level->setBlock($block, $this->id, 0); + or $block3->getID() === WATER or $block3->getID() === STILL_WATER){ + $this->level->setBlock($block, new SugarcaneBlock()); return true; } } - } return false; } diff --git a/src/material/block/plant/Wheat.php b/src/material/block/plant/Wheat.php index 2bb0236a8..6a3ecaec6 100644 --- a/src/material/block/plant/Wheat.php +++ b/src/material/block/plant/Wheat.php @@ -31,20 +31,19 @@ class WheatBlock extends FlowableBlock{ $this->isActivable = true; } - public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - if($block->inWorld === true){ - $down = $level->getBlockFace($block, 0); - if($down->getID() === FARMLAND){ - $level->setBlock($block, $this->id, $this->getMetadata()); - return true; - } + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + $down = $this->getSide(0); + if($down->getID() === FARMLAND){ + $this->level->setBlock($block, $this); + return true; } return false; } - public function onActivate(BlockAPI $level, Item $item, Player $player){ + public function onActivate(Item $item, Player $player){ if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal - $level->setBlock($this, $this->id, 0x07); + $this->meta = 0x07; + $this->level->setBlock($this, $this); return true; } return false; diff --git a/src/material/block/solid/BurningFurnace.php b/src/material/block/solid/BurningFurnace.php index e844da2cc..a322dcd8f 100644 --- a/src/material/block/solid/BurningFurnace.php +++ b/src/material/block/solid/BurningFurnace.php @@ -32,7 +32,7 @@ class BurningFurnaceBlock extends SolidBlock{ $this->isActivable = true; } - public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ if($block->inWorld === true){ $faces = array( 0 => 4, @@ -40,14 +40,14 @@ class BurningFurnaceBlock extends SolidBlock{ 2 => 5, 3 => 3, ); - $level->setBlock($block, $this->id, $faces[$player->entity->getDirection()]); + $this->meta = $faces[$player->entity->getDirection()]; + $this->level->setBlock($block, $this); return true; } return false; } - public function onBreak(BlockAPI $level, Item $item, Player $player){ - if($this->inWorld === true){ + public function onBreak(Item $item, Player $player){ $server = ServerAPI::request(); $t = $server->api->tileentity->get($this); if($t !== false){ @@ -61,16 +61,12 @@ class BurningFurnaceBlock extends SolidBlock{ $server->api->tileentity->remove($t->id); } } - $level->setBlock($this, 0, 0); + $this->level->setBlock($this, new AirBlock()); return true; - } - return false; } - public function onActivate(BlockAPI $level, Item $item, Player $player){ - if($this->inWorld !== true){ - return false; - } + public function onActivate(Item $item, Player $player){ + $server = ServerAPI::request(); $t = $server->api->tileentity->get($this); $furnace = false; @@ -81,7 +77,7 @@ class BurningFurnaceBlock extends SolidBlock{ $furnace = $t; } }else{ - $furnace = $server->api->tileentity->add(TILE_FURNACE, $this->x, $this->y, $this->z, array( + $furnace = $server->api->tileentity->add($this->level, TILE_FURNACE, $this->x, $this->y, $this->z, array( "Items" => array(), "id" => TILE_FURNACE, "x" => $this->x, diff --git a/src/material/block/solid/Chest.php b/src/material/block/solid/Chest.php index 9e060e12f..df034d32c 100644 --- a/src/material/block/solid/Chest.php +++ b/src/material/block/solid/Chest.php @@ -30,12 +30,11 @@ class ChestBlock extends TransparentBlock{ parent::__construct(CHEST, $meta, "Chest"); $this->isActivable = true; } - public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - if($block->inWorld === true){ - $block0 = $level->getBlockFace($block, 2); - $block1 = $level->getBlockFace($block, 3); - $block2 = $level->getBlockFace($block, 4); - $block3 = $level->getBlockFace($block, 5); + 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, @@ -43,9 +42,10 @@ class ChestBlock extends TransparentBlock{ 2 => 5, 3 => 3, ); - $level->setBlock($block, $this->id, $faces[$player->entity->getDirection()]); + $this->meta = $faces[$player->entity->getDirection()]; + $this->level->setBlock($block, $this); $server = ServerAPI::request(); - $server->api->tileentity->add(TILE_CHEST, $this->x, $this->y, $this->z, array( + $server->api->tileentity->add($this->level, TILE_CHEST, $this->x, $this->y, $this->z, array( "Items" => array(), "id" => TILE_CHEST, "x" => $this->x, @@ -54,12 +54,10 @@ class ChestBlock extends TransparentBlock{ )); return true; } - } return false; } - public function onBreak(BlockAPI $level, Item $item, Player $player){ - if($this->inWorld === true){ + public function onBreak(Item $item, Player $player){ $server = ServerAPI::request(); $t = $server->api->tileentity->get($this); if($t !== false){ @@ -73,17 +71,12 @@ class ChestBlock extends TransparentBlock{ $server->api->tileentity->remove($t->id); } } - $level->setBlock($this, 0, 0); + $this->level->setBlock($this, new AirBlock()); return true; - } - return false; } - public function onActivate(BlockAPI $level, Item $item, Player $player){ - if($this->inWorld !== true){ - return false; - } - $top = $level->getBlockFace($this, 1); + public function onActivate(Item $item, Player $player){ + $top = $this->getSide(1); if($top->isTransparent !== true){ return true; } @@ -98,7 +91,7 @@ class ChestBlock extends TransparentBlock{ $chest = $t; } }else{ - $chest = $server->api->tileentity->add(TILE_CHEST, $this->x, $this->y, $this->z, array( + $chest = $server->api->tileentity->add($this->level, TILE_CHEST, $this->x, $this->y, $this->z, array( "Items" => array(), "id" => TILE_CHEST, "x" => $this->x, diff --git a/src/material/block/solid/Dirt.php b/src/material/block/solid/Dirt.php index 9d8b0662c..5b744d72e 100644 --- a/src/material/block/solid/Dirt.php +++ b/src/material/block/solid/Dirt.php @@ -31,9 +31,9 @@ class DirtBlock extends SolidBlock{ $this->isActivable = true; } - public function onActivate(BlockAPI $level, Item $item, Player $player){ + public function onActivate(Item $item, Player $player){ if($item->isHoe()){ - $level->setBlock($this, FARMLAND, 0); + $this->level->setBlock($this, BlockAPI::get(FARMLAND, 0)); return true; } return false; diff --git a/src/material/block/solid/FenceGate.php b/src/material/block/solid/FenceGate.php index 1c6ad0a25..96d68581f 100644 --- a/src/material/block/solid/FenceGate.php +++ b/src/material/block/solid/FenceGate.php @@ -30,7 +30,7 @@ class FenceGateBlock extends TransparentBlock{ parent::__construct(FENCE_GATE, $meta, "Fence Gate"); $this->isActivable = true; } - public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ if($block->inWorld === true){ $faces = array( 0 => 3, @@ -39,7 +39,7 @@ class FenceGateBlock extends TransparentBlock{ 3 => 2, ); $this->meta = $faces[$player->entity->getDirection()] & 0x03; - $level->setBlock($block, $this->id, $this->meta); + $this->level->setBlock($block, $this); return true; } return false; @@ -49,7 +49,7 @@ class FenceGateBlock extends TransparentBlock{ array($this->id, 0, 1), ); } - public function onActivate(BlockAPI $level, Item $item, Player $player){ + public function onActivate(Item $item, Player $player){ $faces = array( 0 => 3, 1 => 0, @@ -57,7 +57,7 @@ class FenceGateBlock extends TransparentBlock{ 3 => 2, ); $this->meta = ($faces[$player->entity->getDirection()] & 0x03) | ((~$this->meta) & 0x04); - $level->setBlock($this, $this->id, $this->meta); + $this->level->setBlock($this, $this); return true; } } \ No newline at end of file diff --git a/src/material/block/solid/Grass.php b/src/material/block/solid/Grass.php index 9c8f8a5ef..d2add1087 100644 --- a/src/material/block/solid/Grass.php +++ b/src/material/block/solid/Grass.php @@ -36,13 +36,13 @@ class GrassBlock extends SolidBlock{ ); } - public function onActivate(BlockAPI $level, Item $item, Player $player){ + public function onActivate(Item $item, Player $player){ if($item->getID() === DYE and $item->getMetadata() === 0x0F){ for($c = 0; $c < 15; ++$c){ $x = mt_rand($this->x - 2, $this->x + 2); $z = mt_rand($this->z - 2, $this->z + 2); - $b = $level->getBlock(new Vector3($x, $this->y + 1, $z)); - $d = $level->getBlock(new Vector3($x, $this->y, $z)); + $b = $this->level->getBlock(new Vector3($x, $this->y + 1, $z)); + $d = $this->level->getBlock(new Vector3($x, $this->y, $z)); if($b->getID() === AIR and $d->getID() === GRASS){ $arr = array( array(DANDELION, 0), @@ -54,12 +54,12 @@ class GrassBlock extends SolidBlock{ array(AIR, 0), ); $t = $arr[mt_rand(0, count($arr) - 1)]; - $level->setBlock($b, $t[0], $t[1]); + $this->level->setBlock($b, BlockAPI::get($t[0], $t[1])); } } return true; }elseif($item->isHoe()){ - $level->setBlock($this, FARMLAND, 0); + $this->level->setBlock($this, new FarmlandBlock()); return true; } return false; diff --git a/src/material/block/solid/Slab.php b/src/material/block/solid/Slab.php index ed5347170..4a6410e9b 100644 --- a/src/material/block/solid/Slab.php +++ b/src/material/block/solid/Slab.php @@ -41,25 +41,24 @@ class SlabBlock extends TransparentBlock{ $this->name = (($this->meta & 0x08) === 0x08 ? "Upper ":"") . $names[$this->meta & 0x07] . " Slab"; } - public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - if($block->inWorld === true){ - $this->meta = $this->meta & 0x07; + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + $this->meta &= 0x07; if($face === 0){ if($target->getID() === SLAB and ($target->getMetadata() & 0x08) === 0x08 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){ - $level->setBlock($target, DOUBLE_SLAB, $this->meta & 0x07); + $this->level->setBlock($target, BlockAPI::get(DOUBLE_SLAB, $this->meta)); return true; }else{ $this->meta |= 0x08; } }elseif($face === 1){ if($target->getID() === SLAB and ($target->getMetadata() & 0x08) === 0 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){ - $level->setBlock($target, DOUBLE_SLAB, $this->meta & 0x07); + $this->level->setBlock($target, BlockAPI::get(DOUBLE_SLAB, $this->meta)); return true; } }elseif(!$player->entity->inBlock($block->x, $block->y, $block->z)){ if($block->getID() === SLAB){ if(($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ - $level->setBlock($block, DOUBLE_SLAB, $this->meta & 0x07); + $this->level->setBlock($block, BlockAPI::get(DOUBLE_SLAB, $this->meta)); return true; } return false; @@ -74,10 +73,8 @@ class SlabBlock extends TransparentBlock{ if($block->getID() === SLAB and ($target->getMetadata() & 0x07) !== ($this->meta & 0x07)){ return false; } - $level->setBlock($block, $this->id, $this->meta); + $this->level->setBlock($block, $this); return true; - } - return false; } public function getDrops(Item $item, Player $player){ return array( diff --git a/src/material/item/generic/Bucket.php b/src/material/item/generic/Bucket.php index 4fa13485f..79f518227 100644 --- a/src/material/item/generic/Bucket.php +++ b/src/material/item/generic/Bucket.php @@ -32,9 +32,9 @@ class BucketItem extends Item{ $this->maxStackSize = 1; } - public function onActivate(BlockAPI $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ if($target->getID() === STILL_WATER or $target->getID() === STILL_LAVA){ - $level->setBlock($target, AIR, 0); + $level->setBlock($target, new AirBlock()); $player->removeItem($this->getID(), $this->getMetadata(), $this->count); $player->addItem(($target->getID() === STILL_LAVA ? LAVA_BUCKET:WATER_BUCKET), 0, 1); return true; diff --git a/src/material/item/generic/LavaBucket.php b/src/material/item/generic/LavaBucket.php index 52894cada..64be8f63a 100644 --- a/src/material/item/generic/LavaBucket.php +++ b/src/material/item/generic/LavaBucket.php @@ -32,9 +32,9 @@ class LavaBucketItem extends Item{ $this->maxStackSize = 1; } - public function onActivate(BlockAPI $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ if($target->getID() === AIR){ - $level->setBlock($target, STILL_LAVA, 0); + $level->setBlock($target, new StillLavaBlock()); $player->removeItem($this->getID(), $this->getMetadata(), $this->count); $player->addItem(BUCKET, 0, 1); return true; diff --git a/src/material/item/generic/Painting.php b/src/material/item/generic/Painting.php index d7da93888..3b00813e1 100644 --- a/src/material/item/generic/Painting.php +++ b/src/material/item/generic/Painting.php @@ -31,7 +31,7 @@ class PaintingItem extends Item{ $this->isActivable = true; } - public function onActivate(BlockAPI $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ if($target->isTransparent === false and $face > 1 and $block->isFlowable === true){ $server = ServerAPI::request(); $faces = array( @@ -78,9 +78,8 @@ class PaintingItem extends Item{ "yaw" => $faces[$face] * 90, "Motive" => $motive[0], ); - $server = ServerAPI::request(); - $e = $server->api->entity->add(ENTITY_OBJECT, OBJECT_PAINTING, $data); - $server->api->entity->spawnToAll($e->eid); + $e = $server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PAINTING, $data); + $server->api->entity->spawnToAll($this->level, $e->eid); if(($player->gamemode & 0x01) === 0x00){ $player->removeItem($this->getID(), $this->getMetadata(), 1); } diff --git a/src/material/item/generic/WaterBucket.php b/src/material/item/generic/WaterBucket.php index 199e92d15..1c999da46 100644 --- a/src/material/item/generic/WaterBucket.php +++ b/src/material/item/generic/WaterBucket.php @@ -32,9 +32,9 @@ class WaterBucketItem extends Item{ $this->maxStackSize = 1; } - public function onActivate(BlockAPI $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ if($target->getID() === AIR){ - $level->setBlock($target, STILL_WATER, 0); + $level->setBlock($target, new StillWaterBLock()); $player->removeItem($this->getID(), $this->getMetadata(), $this->count); $player->addItem(BUCKET, 0, 1); return true; diff --git a/src/world/Entity.php b/src/world/Entity.php index b89434bd6..6c045bfb7 100644 --- a/src/world/Entity.php +++ b/src/world/Entity.php @@ -244,7 +244,7 @@ class Entity extends Position{ for($y = $startY; $y <= $endY; ++$y){ for($x = $startX; $x <= $endX; ++$x){ for($z = $startZ; $z <= $endZ; ++$z){ - $b = $this->server->api->block->getBlock(new Vector3($x, $y, $z)); + $b = $this->level->getBlock(new Vector3($x, $y, $z)); switch($b->getID()){ case WATER: case STILL_WATER: //Drowing @@ -316,7 +316,7 @@ class Entity extends Position{ for($x = $startX; $x <= $endX; ++$x){ $v = new Vector3($x, $y, $z); if($this->isSupport($v)){ - $b = $this->server->api->block->getBlock($v); + $b = $this->level->getBlock($v); if($b->isFlowable !== true){ $support = true; break; diff --git a/src/world/TileEntity.php b/src/world/TileEntity.php index a4491dca9..ae6dea22a 100644 --- a/src/world/TileEntity.php +++ b/src/world/TileEntity.php @@ -134,6 +134,7 @@ class TileEntity extends Position{ switch($this->class){ case TILE_SIGN: $player->dataPacket(MC_SIGN_UPDATE, array( + "level" => $this->level, "x" => $this->x, "y" => $this->y, "z" => $this->z,