Possible fix for #391

This commit is contained in:
Shoghi Cervantes 2013-06-15 21:24:06 +02:00
parent 204a4ce831
commit 02721c09a4
5 changed files with 89 additions and 9 deletions

View File

@ -28,6 +28,7 @@ the Free Software Foundation, either version 3 of the License, or
class BlockAPI{ class BlockAPI{
private $server; private $server;
private $scheduledUpdates = array(); private $scheduledUpdates = array();
private $randomUpdates = array();
public static $creative = array( public static $creative = array(
array(COBBLESTONE, 0), array(COBBLESTONE, 0),
array(STONE_BRICKS, 0), array(STONE_BRICKS, 0),
@ -753,7 +754,7 @@ class BlockAPI{
$this->blockUpdateAround($block, $level); $this->blockUpdateAround($block, $level);
$this->server->api->entity->updateRadius($pos, 3); $this->server->api->entity->updateRadius($pos, 3);
}elseif($level === BLOCK_UPDATE_RANDOM){ }elseif($level === BLOCK_UPDATE_RANDOM){
$this->scheduleBlockUpdate($pos, Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); $this->nextRandomUpdate($pos);
} }
return $level; return $level;
} }
@ -774,6 +775,31 @@ class BlockAPI{
return false; return false;
} }
public function nextRandomUpdate(Position $pos){
if(!isset($this->scheduledUpdates[$pos->x.".".$pos->y.".".$pos->z.".".$pos->level->getName().".".BLOCK_UPDATE_RANDOM])){
$X = (($pos->x >> 4) << 4);
$Y = (($pos->y >> 4) << 4);
$Z = (($pos->z >> 4) << 4);
$time = microtime(true);
$i = 0;
$offset = 0;
while(true){
$t = $offset + Utils::getRandomUpdateTicks() * 0.05;
$update = $this->server->query("SELECT COUNT(*) FROM blockUpdates WHERE level = '".$pos->level->getName()."' AND type = ".BLOCK_UPDATE_RANDOM." AND delay >= ".($time + $t - 1.5)." AND delay <= ".($time + $t + 1.5).";");
if($update instanceof SQLite3Result){
$update = $update->fetchArray(SQLITE3_NUM);
if($update[0] == 0){
break;
}
}else{
break;
}
$offset += 10;
}
$this->scheduleBlockUpdate($pos, $t / 0.05, BLOCK_UPDATE_RANDOM);
}
}
public function blockUpdateTick(){ public function blockUpdateTick(){
$time = microtime(true); $time = microtime(true);
if(count($this->scheduledUpdates) > 0){ if(count($this->scheduledUpdates) > 0){

View File

@ -47,9 +47,13 @@ class LeavesBlock extends TransparentBlock{
} }
if($pos->getID() === WOOD){ if($pos->getID() === WOOD){
return true; return true;
}elseif($pos->getID() === LEAVES and $distance < 4){ }elseif($pos->getID() === LEAVES and $distance < 5){
$visited[$index] = true; $visited[$index] = true;
for($side = 0; $side <= 5; ++$side){ $down = $pos->getSide(0)->getID();
if($down === WOOD or $down == LEAVES){
return true;
}
for($side = 2; $side <= 5; ++$side){
if($this->findLog($pos->getSide($side), $visited, $distance + 1) === true){ if($this->findLog($pos->getSide($side), $visited, $distance + 1) === true){
return true; return true;
} }
@ -69,16 +73,18 @@ class LeavesBlock extends TransparentBlock{
}elseif($type === BLOCK_UPDATE_RANDOM){ }elseif($type === BLOCK_UPDATE_RANDOM){
if(($this->meta & 0b00001100) === 0x08){ if(($this->meta & 0b00001100) === 0x08){
$this->meta &= 0x03; $this->meta &= 0x03;
if($this->findLog($this, array(), 0) === true){ $visited = array();
if($this->findLog($this, $visited, 0) === true){
$this->level->setBlock($this, $this, false); $this->level->setBlock($this, $this, false);
}else{ }else{
$this->level->setBlock($this, new AirBlock()); $this->level->setBlock($this, new AirBlock(), false);
if(mt_rand(1,20) === 1){ //Saplings if(mt_rand(1,20) === 1){ //Saplings
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SAPLING, $this->meta & 0x03, 1)); ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SAPLING, $this->meta & 0x03, 1));
} }
if(($this->meta & 0x03) === LeavesBlock::OAK and mt_rand(1,200) === 1){ //Apples if(($this->meta & 0x03) === LeavesBlock::OAK and mt_rand(1,200) === 1){ //Apples
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(APPLE, 0, 1)); ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(APPLE, 0, 1));
} }
return BLOCK_UPDATE_NORMAL;
} }
} }
} }

View File

@ -110,6 +110,26 @@ class Vector2{
return pow($this->x - $x, 2) + pow($this->y - $y, 2); return pow($this->x - $x, 2) + pow($this->y - $y, 2);
} }
} }
public function length(){
return sqrt($this->lengthSquared());
}
public function lengthSquared(){
return $this->x * $this->x + $this->y * $this->y;
}
public function normalize(){
$len = $this->length();
if($len != 0){
return $this->divide($len);
}
return new Vector2(0, 0);
}
public function dot(Vector2 $v){
return $this->x * $v->x + $this->y * $v->y;
}
public function __toString(){ public function __toString(){
return "Vector2(x=".$this->x.",y=".$this->y.")"; return "Vector2(x=".$this->x.",y=".$this->y.")";

View File

@ -164,6 +164,34 @@ class Vector3{
return max(abs($this->x - $x), abs($this->z - $z)); return max(abs($this->x - $x), abs($this->z - $z));
} }
} }
public function length(){
return sqrt($this->lengthSquared());
}
public function lengthSquared(){
return $this->x * $this->x + $this->y * $this->y + $this->z * $this->z;
}
public function normalize(){
$len = $this->length();
if($len != 0){
return $this->divide($len);
}
return new Vector3(0, 0, 0);
}
public function dot(Vector3 $v){
return $this->x * $v->x + $this->y * $v->y + $this->z * $v->z;
}
public function cross(Vector3 $v){
return new Vector3(
$this->y * $v->z - $this->z * $v->y,
$this->z * $v->x - $this->x * $v->z,
$this->x * $v->y - $this->y * $v->x
);
}
public function __toString(){ public function __toString(){
return "Vector3(x=".$this->x.",y=".$this->y.",z=".$this->z.")"; return "Vector3(x=".$this->x.",y=".$this->y.",z=".$this->z.")";

View File

@ -159,14 +159,14 @@ class CustomPacketHandler{
$this->data["username"] = $this->get(Utils::readShort($this->get(2), false)); $this->data["username"] = $this->get(Utils::readShort($this->get(2), false));
$this->data["protocol1"] = Utils::readInt($this->get(4)); $this->data["protocol1"] = Utils::readInt($this->get(4));
$this->data["protocol2"] = Utils::readInt($this->get(4)); $this->data["protocol2"] = Utils::readInt($this->get(4));
$this->data["unknown1"] = Utils::readInt($this->get(4)); $this->data["clientId"] = Utils::readInt($this->get(4));
$this->data["unknown2"] = $this->get(Utils::readShort($this->get(2), false)); $this->data["realms_data"] = $this->get(Utils::readShort($this->get(2), false));
}else{ }else{
$this->raw .= Utils::writeShort(strlen($this->data["username"])).$this->data["username"]; $this->raw .= Utils::writeShort(strlen($this->data["username"])).$this->data["username"];
$this->raw .= Utils::writeInt(CURRENT_PROTOCOL). $this->raw .= Utils::writeInt(CURRENT_PROTOCOL).
Utils::writeInt(CURRENT_PROTOCOL). Utils::writeInt(CURRENT_PROTOCOL).
Utils::writeInt($this->data["unknown1"]); Utils::writeInt($this->data["clientId"]);
$this->raw .= Utils::writeShort(strlen($this->data["unknown2"])).$this->data["unknown2"]; $this->raw .= Utils::writeShort(strlen($this->data["realms_data"])).$this->data["realms_data"];
} }
break; break;
case MC_LOGIN_STATUS: case MC_LOGIN_STATUS: