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

View File

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

View File

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

View File

@ -135,7 +135,7 @@ class FallingSand extends Entity{
$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(){

View File

@ -75,19 +75,16 @@ class Item extends Entity{
$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){
if($this->closed){
return false;
}
$tickDiff = max(1, $currentTick - $this->lastUpdate);
$tickDiff = $currentTick - $this->lastUpdate;
if($tickDiff <= 0){
return false;
}
$this->lastUpdate = $currentTick;
$this->timings->startTiming();
@ -98,6 +95,9 @@ class Item extends Entity{
if($this->pickupDelay > 0 and $this->pickupDelay < 32767){ //Infinite delay
$this->pickupDelay -= $tickDiff;
if($this->pickupDelay < 0){
$this->pickupDelay = 0;
}
}
$this->motionY -= $this->gravity;
@ -108,8 +108,8 @@ class Item extends Entity{
$friction = 1 - $this->drag;
if($this->onGround and ($this->motionX != 0 or $this->motionZ != 0)){
$friction = $this->getLevel()->getBlock(new Vector3($this->getFloorX(), $this->getFloorY() - 1, $this->getFloorZ()))->getFrictionFactor() * $friction;
if($this->onGround and (abs($this->motionX) > 0.00001 or abs($this->motionZ) > 0.00001)){
$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;
@ -136,7 +136,7 @@ class Item extends Entity{
$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(){

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

View File

@ -178,7 +178,7 @@ abstract class Projectile extends Entity{
$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));
$this->yaw = (atan2($this->motionX, $this->motionZ) * 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();
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(){
return (int) $this->x;
return (int) floor($this->x);
}
public function getFloorY(){
return (int) $this->y;
return (int) floor($this->y);
}
public function getFloorZ(){
return (int) $this->z;
return (int) floor($this->z);
}
public function getRight(){

View File

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