This commit is contained in:
Michael Yoo 2013-02-07 16:12:24 +10:30
commit 318590e664
17 changed files with 105 additions and 43 deletions

View file

@ -49,6 +49,7 @@ class Player{
public $equipment;
var $armor = array(0, 0, 0, 0);
var $loggedIn = false;
public $gamemode;
private $chunksLoaded = array();
private $chunksOrder = array();
@ -61,7 +62,8 @@ class Player{
$this->port = $port;
$this->timeout = microtime(true) + 20;
$this->inventory = array_fill(0, 36, array(AIR, 0, 0));
if($this->server->gamemode === 0 or $this->server->gamemode === 2){
$this->gamemode = $this->server->gamemode;
if($this->gamemode === 0 or $this->gamemode === 2){
$this->equipment = BlockAPI::getItem(AIR);
}else{
$this->equipment = BlockAPI::getItem(STONE);
@ -272,14 +274,14 @@ class Player{
}
break;
case "player.block.place":
if($data["eid"] === $this->eid and ($this->server->gamemode === 0 or $this->server->gamemode === 2)){
if($data["eid"] === $this->eid and ($this->gamemode === 0 or $this->gamemode === 2)){
$this->removeItem($data["original"]->getID(), $data["original"]->getMetadata(), 1);
}
break;
case "player.pickup":
if($data["eid"] === $this->eid){
$data["eid"] = 0;
if(($this->server->gamemode === 0 or $this->server->gamemode === 2)){
if(($this->gamemode === 0 or $this->gamemode === 2)){
$this->addItem($data["entity"]->type, $data["entity"]->meta, $data["entity"]->stack);
}
}
@ -517,7 +519,7 @@ class Player{
}
$this->server->api->player->add($this->CID);
$this->auth = true;
if(!isset($this->data["inventory"]) or $this->server->gamemode === 1){
if(!isset($this->data["inventory"]) or $this->gamemode === 1){
$this->data["inventory"] = $this->inventory;
}
$this->inventory = &$this->data["inventory"];
@ -535,7 +537,7 @@ class Player{
"y" => $this->data["spawn"]["y"],
"z" => $this->data["spawn"]["z"],
"unknown1" => 0,
"gamemode" => $this->server->gamemode,
"gamemode" => $this->gamemode,
"eid" => 0,
));
break;
@ -600,7 +602,7 @@ class Player{
0x80 ?
*/
$flags = 0;
if($this->server->gamemode === 2){
if($this->gamemode === 2){
$flags |= 0x01; //Not allow placing/breaking blocks
}
$flags |= 0x20; //Nametags
@ -632,7 +634,7 @@ class Player{
$data["eid"] = $this->eid;
if(Utils::distance($this->entity->position, $data) > 10){
break;
}elseif(($this->server->gamemode === 0 or $this->server->gamemode === 2) and !$this->hasItem($data["block"], $data["meta"])){
}elseif(($this->gamemode === 0 or $this->gamemode === 2) and !$this->hasItem($data["block"], $data["meta"])){
console("[DEBUG] Player \"".$this->username."\" tried to place not got block (or crafted block)", true, true, 2);
//break;
}
@ -672,7 +674,7 @@ class Player{
$this->entity->updateMetadata();
break;
case MC_SET_HEALTH:
if($this->server->gamemode === 1){
if($this->gamemode === 1){
break;
}
//$this->entity->setHealth($data["health"], "client");

View file

@ -331,7 +331,7 @@ class PocketMinecraftServer{
"yaw" => $entity["Rotation"][0],
"pitch" => $entity["Rotation"][1],
));
}elseif($entity["id"] === 83){ //Painting
}elseif($entity["id"] === OBJECT_PAINTING){ //Painting
$e = $this->api->entity->add(ENTITY_OBJECT, $entity["id"], $entity);
$e->setPosition($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2], $entity["Rotation"][0], $entity["Rotation"][1]);
$e->setHealth($entity["Health"]);
@ -363,7 +363,7 @@ class PocketMinecraftServer{
if(count($this->entities) > 0){
$entities = array();
foreach($this->entities as $entity){
if($entity->class === ENTITY_MOB or $entity->class === ENTITY_OBJECT){
if($entity->class === ENTITY_MOB){
$entities[] = array(
"id" => $entity->type,
"Color" => @$entity->data["Color"],
@ -379,6 +379,24 @@ class PocketMinecraftServer{
1 => $entity->pitch,
),
);
}elseif($entity->class === ENTITY_OBJECT){
$entities[] = array(
"id" => $entity->type,
"TileX" => $entity->x,
"TileX" => $entity->y,
"TileX" => $entity->z,
"Health" => $entity->health,
"Motive" => $entity->data["Motive"],
"Pos" => array(
0 => $entity->x,
1 => $entity->y,
2 => $entity->z,
),
"Rotation" => array(
0 => $entity->yaw,
1 => $entity->pitch,
),
);
}elseif($entity->class === ENTITY_ITEM){
$entities[] = array(
"id" => 64,

View file

@ -138,7 +138,7 @@ abstract class Block{
protected $shortname = "";
protected $name = "";
public $isActivable = false;
public $isBreakable = true;
public $breakable = true;
public $isFlowable = false;
public $isTransparent = false;
public $isReplaceable = false;
@ -186,6 +186,8 @@ abstract class Block{
}
}
abstract function isBreakable(Item $item, Player $player);
abstract function onBreak(BlockAPI $level, Item $item, Player $player);
abstract function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz);

View file

@ -276,8 +276,3 @@ define("QUARTZ", 406);
define("NETHER_QUARTZ", 406);
define("CAMERA", 456);
/*
define("", );
*/

View file

@ -38,6 +38,10 @@ class GenericBlock extends Block{
return false;
}
public function isBreakable(Item $item, Player $player){
return $this->breakable;
}
public function onBreak(BlockAPI $level, Item $item, Player $player){
if($this->inWorld === true){
$level->setBlock($this, AIR, 0);

View file

@ -29,7 +29,7 @@ class LiquidBlock extends TransparentBlock{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
$this->isLiquid = true;
$this->isBreakable = false;
$this->breakable = false;
$this->isReplaceable = true;
}
}

View file

@ -29,7 +29,7 @@ class TransparentBlock extends GenericBlock{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
$this->isActivable = false;
$this->isBreakable = true;
$this->breakable = true;
$this->isFlowable = false;
$this->isTransparent = true;
$this->isReplaceable = false;

View file

@ -29,7 +29,7 @@ class AirBlock extends TransparentBlock{
public function __construct(){
parent::__construct(AIR, 0, "Air");
$this->isActivable = false;
$this->isBreakable = false;
$this->breakable = false;
$this->isFlowable = true;
$this->isTransparent = true;
$this->isReplaceable = true;

View file

@ -29,7 +29,7 @@ class FireBlock extends FlowableBlock{
public function __construct($meta = 0){
parent::__construct(FIRE, $meta, "Fire");
$this->isReplaceable = true;
$this->isBreakable = false;
$this->breakable = false;
}
}

View file

@ -28,7 +28,14 @@ the Free Software Foundation, either version 3 of the License, or
class BedrockBlock extends SolidBlock{
public function __construct(){
parent::__construct(BEDROCK, 0, "Bedrock");
$this->isBreakable = false;
$this->breakable = false;
}
public function isBreakable(Item $item, Player $player){
if($player->gamemode === 1){
return true;
}
return false;
}
}

View file

@ -71,6 +71,9 @@ class SlabBlock extends TransparentBlock{
}else{
return false;
}
if($block->getID() === SLAB and ($target->getMetadata() & 0x07) !== ($this->meta & 0x07)){
return false;
}
$level->setBlock($block, $this->id, $this->meta);
return true;
}

View file

@ -33,11 +33,29 @@ class PaintingItem extends Item{
public function onActivate(BlockAPI $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if($target->isTransparent === false and $face > 1){
$faces = array(
2 => 1,
3 => 3,
4 => 0,
5 => 2,
);
$motives = array(
"Kebab",
"Aztec",
"Alban",
"Aztec2",
"Bomb",
"Plant",
"Wasteland",
);
$data = array(
"x" => $target->x,
"y" => $target->y,
"z" => $target->z,
"yaw" => ($face % 4) * 90,
"yaw" => $faces[$face] * 90,
"Motive" => $motives[mt_rand(0, count($motives) - 1)],
);
$server = ServerAPI::request();
$e = $server->api->entity->add(ENTITY_OBJECT, OBJECT_PAINTING, $data);

View file

@ -97,7 +97,6 @@ class Entity extends stdClass{
$this->name = "";
$this->tickCounter = 0;
$this->server->query("INSERT OR REPLACE INTO entities (EID, type, class, health) VALUES (".$this->eid.", ".$this->type.", ".$this->class.", ".$this->health.");");
$this->server->schedule(5, array($this, "update"), array(), true);
$this->x = isset($this->data["x"]) ? $this->data["x"]:0;
$this->y = isset($this->data["y"]) ? $this->data["y"]:0;
$this->z = isset($this->data["z"]) ? $this->data["z"]:0;
@ -112,22 +111,25 @@ class Entity extends stdClass{
case ENTITY_PLAYER:
$this->player = $this->data["player"];
$this->setHealth($this->health, "generic");
$this->server->schedule(5, array($this, "update"), array(), true);
break;
case ENTITY_ITEM:
$this->meta = (int) $this->data["meta"];
$this->stack = (int) $this->data["stack"];
$this->setHealth(5, "generic");
$this->server->schedule(5, array($this, "update"), array(), true);
break;
case ENTITY_MOB:
$this->setHealth($this->data["Health"], "generic");
//$this->server->schedule(5, array($this, "update"), array(), true);
//$this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type));
break;
case ENTITY_OBJECT:
$this->x = isset($this->data["TileX"]) ? $this->data["TileX"]:$this->x;
$this->y = isset($this->data["TileY"]) ? $this->data["TileY"]:$this->y;
$this->z = isset($this->data["TileZ"]) ? $this->data["TileZ"]:$this->z;
$this->setHealth(1, "generic");
//$this->setName((isset($objects[$this->type]) ? $objects[$this->type]:$this->type));
break;
case ENTITY_PAINTING:
break;
}
}
@ -281,7 +283,9 @@ class Entity extends stdClass{
}
if($this->fallY !== false and ($this->fallStart + 8) < microtime(true)){ //Flying
$this->harm(1, "flying");
$this->fallY = $y;
if($y > $this->fallY){
$this->fallY = $y;
}
}
}elseif($this->fallY !== false){ //Fall damage!
if($y < $this->fallY){
@ -298,7 +302,7 @@ class Entity extends stdClass{
}
}
if($this->last[0] != $this->x or $this->last[1] != $this->y or $this->last[2] != $this->z or $this->last[3] != $this->yaw or $this->last[4] != $this->pitch){
if($this->class !== ENTITY_OBJECT and ($this->last[0] != $this->x or $this->last[1] != $this->y or $this->last[2] != $this->z or $this->last[3] != $this->yaw or $this->last[4] != $this->pitch)){
$this->server->api->dhandle("entity.move", $this);
if($this->class === ENTITY_PLAYER){
$this->calculateVelocity();
@ -400,7 +404,7 @@ class Entity extends stdClass{
"y" => (int) $this->y,
"z" => (int) $this->z,
"direction" => $this->getDirection(),
"title" => "Creepers",
"title" => $this->data["Motive"],
));
}
break;
@ -548,6 +552,8 @@ class Entity extends stdClass{
$this->air = 300;
$this->fire = 0;
$this->crouched = false;
$this->fallY = false;
$this->fallStart = false;
$this->updateMetadata();
$this->dead = true;
$this->server->api->dhandle("entity.event", array("entity" => $this, "event" => 3)); //Entity dead