Fixed items getting corrupted pickup delay, not being able to be killed by other damage sources

This commit is contained in:
Shoghi Cervantes 2015-05-28 22:17:12 +02:00
parent ce59703dd0
commit 03f178379e
No known key found for this signature in database
GPG Key ID: 78464DB0A7837F89
10 changed files with 38 additions and 37 deletions

View File

@ -2281,7 +2281,7 @@ class Server{
$this->nextTick = microtime(true); $this->nextTick = microtime(true);
while($this->isRunning){ while($this->isRunning){
$this->tick(); $this->tick();
$next = $this->nextTick - 0.001; $next = $this->nextTick - 0.0001;
if($next > microtime(true)){ if($next > microtime(true)){
try{ try{
time_sleep_until($next); time_sleep_until($next);
@ -2547,8 +2547,9 @@ class Server{
if(($this->nextTick - $tickTime) < -1){ if(($this->nextTick - $tickTime) < -1){
$this->nextTick = $tickTime; $this->nextTick = $tickTime;
} }else{
$this->nextTick += 0.05; $this->nextTick += 0.05;
}
return true; return true;
} }

View File

@ -57,9 +57,7 @@ class CommandReader extends Thread{
*/ */
public function getLine(){ public function getLine(){
if($this->buffer->count() !== 0){ if($this->buffer->count() !== 0){
return $this->buffer->synchronized(function (){
return $this->buffer->shift(); return $this->buffer->shift();
});
} }
return null; return null;
@ -76,9 +74,7 @@ class CommandReader extends Thread{
$lastLine = microtime(true); $lastLine = microtime(true);
while(true){ while(true){
if(($line = $this->readLine()) !== ""){ if(($line = $this->readLine()) !== ""){
$this->buffer->synchronized(function (\Threaded $buffer, $line){ $this->buffer[] = preg_replace("#\\x1b\\x5b([^\\x1b]*\\x7e|[\\x40-\\x50])#", "", $line);
$buffer[] = preg_replace("#\\x1b\\x5b([^\\x1b]*\\x7e|[\\x40-\\x50])#", "", $line);
}, $this->buffer, $line);
}elseif((microtime(true) - $lastLine) <= 0.1){ //Non blocking! Sleep to save CPU }elseif((microtime(true) - $lastLine) <= 0.1){ //Non blocking! Sleep to save CPU
usleep(40000); usleep(40000);
} }

View File

@ -136,6 +136,8 @@ abstract class Entity extends Location implements Metadatable{
public $motionX; public $motionX;
public $motionY; public $motionY;
public $motionZ; public $motionZ;
/** @var Vector3 */
public $temporalVector;
public $lastMotionX; public $lastMotionX;
public $lastMotionY; public $lastMotionY;
public $lastMotionZ; public $lastMotionZ;
@ -205,6 +207,8 @@ abstract class Entity extends Location implements Metadatable{
$this->timings = Timings::getEntityTimings($this); $this->timings = Timings::getEntityTimings($this);
$this->temporalVector = new Vector3();
if($this->eyeHeight === null){ if($this->eyeHeight === null){
$this->eyeHeight = $this->height / 2 + 0.1; $this->eyeHeight = $this->height / 2 + 0.1;
} }

View File

@ -135,7 +135,7 @@ class FallingSand extends Entity{
$this->updateMovement(); $this->updateMovement();
} }
return $hasUpdate or !$this->onGround or $this->motionX != 0 or $this->motionY != 0 or $this->motionZ != 0; return $hasUpdate or !$this->onGround or abs($this->motionX) > 0.00001 or abs($this->motionY) > 0.00001 or abs($this->motionZ) > 0.00001;
} }
public function getBlock(){ public function getBlock(){

View File

@ -75,19 +75,16 @@ class Item extends Entity{
$this->server->getPluginManager()->callEvent(new ItemSpawnEvent($this)); $this->server->getPluginManager()->callEvent(new ItemSpawnEvent($this));
} }
public function attack($damage, EntityDamageEvent $source){
if($source->getCause() === EntityDamageEvent::CAUSE_FIRE_TICK){
parent::attack($damage, $source);
}
}
public function onUpdate($currentTick){ public function onUpdate($currentTick){
if($this->closed){ if($this->closed){
return false; return false;
} }
$tickDiff = max(1, $currentTick - $this->lastUpdate); $tickDiff = $currentTick - $this->lastUpdate;
if($tickDiff <= 0){
return false;
}
$this->lastUpdate = $currentTick; $this->lastUpdate = $currentTick;
$this->timings->startTiming(); $this->timings->startTiming();
@ -98,6 +95,9 @@ class Item extends Entity{
if($this->pickupDelay > 0 and $this->pickupDelay < 32767){ //Infinite delay if($this->pickupDelay > 0 and $this->pickupDelay < 32767){ //Infinite delay
$this->pickupDelay -= $tickDiff; $this->pickupDelay -= $tickDiff;
if($this->pickupDelay < 0){
$this->pickupDelay = 0;
}
} }
$this->motionY -= $this->gravity; $this->motionY -= $this->gravity;
@ -108,8 +108,8 @@ class Item extends Entity{
$friction = 1 - $this->drag; $friction = 1 - $this->drag;
if($this->onGround and ($this->motionX != 0 or $this->motionZ != 0)){ if($this->onGround and (abs($this->motionX) > 0.00001 or abs($this->motionZ) > 0.00001)){
$friction = $this->getLevel()->getBlock(new Vector3($this->getFloorX(), $this->getFloorY() - 1, $this->getFloorZ()))->getFrictionFactor() * $friction; $friction = $this->getLevel()->getBlock($this->temporalVector->setComponents((int) floor($this->x), (int) floor($this->y - 1), (int) floor($this->z) - 1))->getFrictionFactor() * $friction;
} }
$this->motionX *= $friction; $this->motionX *= $friction;
@ -136,7 +136,7 @@ class Item extends Entity{
$this->timings->stopTiming(); $this->timings->stopTiming();
return $hasUpdate or !$this->onGround or $this->motionX != 0 or $this->motionY != 0 or $this->motionZ != 0; return $hasUpdate or !$this->onGround or abs($this->motionX) > 0.00001 or abs($this->motionY) > 0.00001 or abs($this->motionZ) > 0.00001;
} }
public function saveNBT(){ public function saveNBT(){

View File

@ -113,7 +113,7 @@ class PrimedTNT extends Entity implements Explosive{
} }
return $hasUpdate or $this->fuse >= 0 or $this->motionX != 0 or $this->motionY != 0 or $this->motionZ != 0; return $hasUpdate or $this->fuse >= 0 or abs($this->motionX) > 0.00001 or abs($this->motionY) > 0.00001 or abs($this->motionZ) > 0.00001;
} }
public function explode(){ public function explode(){

View File

@ -178,7 +178,7 @@ abstract class Projectile extends Entity{
$this->hadCollision = false; $this->hadCollision = false;
} }
if(!$this->onGround or $this->motionX != 0 or $this->motionY != 0 or $this->motionZ != 0){ if(!$this->onGround or abs($this->motionX) > 0.00001 or abs($this->motionY) > 0.00001 or abs($this->motionZ) > 0.00001){
$f = sqrt(($this->motionX ** 2) + ($this->motionZ ** 2)); $f = sqrt(($this->motionX ** 2) + ($this->motionZ ** 2));
$this->yaw = (atan2($this->motionX, $this->motionZ) * 180 / M_PI); $this->yaw = (atan2($this->motionX, $this->motionZ) * 180 / M_PI);
$this->pitch = (atan2($this->motionY, $f) * 180 / M_PI); $this->pitch = (atan2($this->motionY, $f) * 180 / M_PI);

View File

@ -143,7 +143,7 @@ class Squid extends WaterAnimal implements Ageable{
$this->timings->stopTiming(); $this->timings->stopTiming();
return $hasUpdate or !$this->onGround or $this->motionX != 0 or $this->motionY != 0 or $this->motionZ != 0; return $hasUpdate or !$this->onGround or abs($this->motionX) > 0.00001 or abs($this->motionY) > 0.00001 or abs($this->motionZ) > 0.00001;
} }

View File

@ -53,15 +53,15 @@ class Vector3{
} }
public function getFloorX(){ public function getFloorX(){
return (int) $this->x; return (int) floor($this->x);
} }
public function getFloorY(){ public function getFloorY(){
return (int) $this->y; return (int) floor($this->y);
} }
public function getFloorZ(){ public function getFloorZ(){
return (int) $this->z; return (int) floor($this->z);
} }
public function getRight(){ public function getRight(){

View File

@ -46,7 +46,7 @@ class MainLogger extends \AttachableThreadedLogger{
touch($logFile); touch($logFile);
$this->logFile = $logFile; $this->logFile = $logFile;
$this->logDebug = (bool) $logDebug; $this->logDebug = (bool) $logDebug;
$this->logStream = ""; $this->logStream = \ThreadedFactory::create();
$this->start(); $this->start();
} }
@ -190,11 +190,12 @@ class MainLogger extends \AttachableThreadedLogger{
$this->attachment->call($level, $message); $this->attachment->call($level, $message);
} }
$str = date("Y-m-d", $now) . " " . $cleanMessage . "\n"; $this->logStream[] = date("Y-m-d", $now) . " " . $cleanMessage . "\n";
$this->synchronized(function($str){ if($this->logStream->count() === 1){
$this->logStream .= $str; $this->synchronized(function(){
$this->notify(); $this->notify();
}, $str); });
}
} }
public function run(){ public function run(){
@ -206,13 +207,12 @@ class MainLogger extends \AttachableThreadedLogger{
while($this->shutdown === false){ while($this->shutdown === false){
$this->synchronized(function(){ $this->synchronized(function(){
if(strlen($this->logStream) > 0){ while($this->logStream->count() > 0){
$chunk = $this->logStream; $chunk = $this->logStream->shift();
$this->logStream = "";
fwrite($this->logResource, $chunk); fwrite($this->logResource, $chunk);
}else{
$this->wait(250000);
} }
$this->wait(25000);
}); });
} }