PMF & Multiworld [part 2]

This commit is contained in:
Shoghi Cervantes Pueyo 2013-05-14 19:25:55 +02:00
parent 9b212ae034
commit 5938747083
39 changed files with 239 additions and 301 deletions

View File

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

View File

@ -52,7 +52,7 @@ class LevelAPI{
$gen->init();
$gen->generate();
$gen->save($path, $this->default);
$this->loadLevel($this->default)
$this->loadLevel($this->default);
}
}

View File

@ -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];
}

View File

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

View File

@ -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{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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(

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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