mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
time always updates, test entity optimizations
This commit is contained in:
parent
026daf485b
commit
fc2fa6d2f8
5 changed files with 47 additions and 42 deletions
|
|
@ -549,7 +549,7 @@ class Entity extends Position
|
|||
if(Utils::in_range($this->speedZ, - 0.01, 0.01)){
|
||||
$this->speedZ = 0;
|
||||
}
|
||||
if(Utils::in_range($this->speedY, - 0.001, 0.001)){
|
||||
if(Utils::in_range($this->speedY, - 0.0007, 0.007)){
|
||||
$this->speedY = 0;
|
||||
}
|
||||
|
||||
|
|
@ -636,35 +636,37 @@ class Entity extends Position
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
for($z = $startZ; $z <= $endZ; ++ $z){
|
||||
for($x = $startX; $x <= $endX; ++ $x){
|
||||
$v = new Vector3($x, $y, $z);
|
||||
$v1 = new Vector3($x, $yC, $z);
|
||||
if($this->isSupport($v, $this->width)){
|
||||
$b = $this->level->getBlock($v);
|
||||
if($b->isSolid === true){
|
||||
$support = true;
|
||||
$isFlying = false;
|
||||
break;
|
||||
} elseif(($b instanceof LiquidBlock) or $b->getID() === COBWEB or $b->getID() === LADDER or $b->getID() === FENCE or $b->getID() === STONE_WALL or $b->getID() === IRON_BARS){
|
||||
$isFlying = false;
|
||||
}
|
||||
} elseif($this->isSupport($v1, $this->width)){
|
||||
$b = $this->level->getBlock($v1);
|
||||
if($b->isSolid === true){
|
||||
$support = true;
|
||||
$isFlying = false;
|
||||
break;
|
||||
} elseif(($b instanceof LiquidBlock) or $b->getID() === COBWEB or $b->getID() === LADDER or $b->getID() === FENCE or $b->getID() === STONE_WALL or $b->getID() === IRON_BARS){
|
||||
$isFlying = false;
|
||||
if(!$support){
|
||||
for($z = $startZ; $z <= $endZ; ++ $z){
|
||||
for($x = $startX; $x <= $endX; ++ $x){
|
||||
$v = new Vector3($x, $y, $z);
|
||||
$v1 = new Vector3($x, $yC, $z);
|
||||
if($this->isSupport($v, $this->width)){
|
||||
$b = $this->level->getBlock($v);
|
||||
if($b->isSolid === true){
|
||||
$support = true;
|
||||
$isFlying = false;
|
||||
break;
|
||||
} elseif(($b instanceof LiquidBlock) or $b->getID() === COBWEB or $b->getID() === LADDER or $b->getID() === FENCE or $b->getID() === STONE_WALL or $b->getID() === IRON_BARS){
|
||||
$isFlying = false;
|
||||
}
|
||||
} elseif($this->isSupport($v1, $this->width)){
|
||||
$b = $this->level->getBlock($v1);
|
||||
if($b->isSolid === true){
|
||||
$support = true;
|
||||
$isFlying = false;
|
||||
break;
|
||||
} elseif(($b instanceof LiquidBlock) or $b->getID() === COBWEB or $b->getID() === LADDER or $b->getID() === FENCE or $b->getID() === STONE_WALL or $b->getID() === IRON_BARS){
|
||||
$isFlying = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if($support === true){
|
||||
break;
|
||||
if($support === true){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if($this->speedX != 0){
|
||||
$this->x += $this->speedX;
|
||||
|
|
@ -711,17 +713,20 @@ class Entity extends Position
|
|||
if($this->hasGravity && $support === false){
|
||||
$this->speedY -= ($this->class === ENTITY_FALLING) ? 0.04 : ($this->class === ENTITY_ITEM ? 0.06 : 0.08); // TODO: replace with $gravity
|
||||
$update = true;
|
||||
} else{
|
||||
} elseif($this->lastX != $this->x && $this->lastZ != $this->z & $this->lastY != $this->z){
|
||||
// $this->speedX = 0;
|
||||
// $this->speedY = 0;
|
||||
// $this->speedZ = 0;
|
||||
$this->server->api->handle("entity.move", $this);
|
||||
$update = true;
|
||||
|
||||
}
|
||||
|
||||
if($update === true){
|
||||
$hasUpdate = true;
|
||||
$this->server->api->handle("entity.motion", $this);
|
||||
if(($this->server->ticks % 4 === 0 && $this->class === ENTITY_ITEM) || $this->class != ENTITY_ITEM){ //update item speed every 4 ticks
|
||||
$this->server->api->handle("entity.motion", $this);
|
||||
}
|
||||
}
|
||||
} elseif($this->player instanceof Player){
|
||||
if($isFlying === true and ($this->player->gamemode & 0x01) === 0x00){
|
||||
|
|
@ -1523,7 +1528,7 @@ class Entity extends Position
|
|||
* Debug
|
||||
*/
|
||||
public function printSpeed(){
|
||||
console("{$this->speedX}:{$this->speedY}:{$this->speedZ}");
|
||||
ConsoleAPI::debug("{$this->speedX}:{$this->speedY}:{$this->speedZ}");
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class NetherReactorBlock extends SolidBlock{
|
|||
}
|
||||
}
|
||||
|
||||
private function decay($x,$y,$z,$aOne,$aTwo,$aThree,$bOne,$bTwo,$bThree,$cOne,$cTwo,$cThree) {
|
||||
private function decay($x, $y, $z, $aOne, $aTwo, $aThree, $bOne, $bTwo, $bThree, $cOne, $cTwo, $cThree) {
|
||||
for($a = $aOne; $a < $aTwo; $a += $aThree) { //wth those cycles are?
|
||||
for($b = $bOne; $b < $bTwo; $b += $bThree) {
|
||||
for($c = $cOne; $c < $cTwo; $c += $cThree) {
|
||||
|
|
@ -101,7 +101,7 @@ class NetherReactorBlock extends SolidBlock{
|
|||
$shiftZ = sin(floor(Utils::randomFloat()*360)*(pi()/180));
|
||||
if(Utils::chance(5)) $randomID = $this->rarePossibleLoot[array_rand($this->rarePossibleLoot)];
|
||||
else $randomID = $this->possibleLoot[array_rand($this->possibleLoot)];
|
||||
$server->api->entity->drop(new Position($x+($shiftX*$randomRange)+0.5, $y-1, $z+($shiftZ*$randomRange)+0.5, $this->level), BlockAPI::getItem($randomID, 0, 1));
|
||||
$server->api->entity->drop(new Position($x+($shiftX*$randomRange)+0.5, $y, $z+($shiftZ*$randomRange)+0.5, $this->level), BlockAPI::getItem($randomID, 0, 1));
|
||||
}
|
||||
for($i = 0; $i < $pigmen; $i++) {
|
||||
$randomRange = floor(Utils::randomFloat()*5+3);
|
||||
|
|
@ -109,7 +109,7 @@ class NetherReactorBlock extends SolidBlock{
|
|||
$shiftZ = sin(floor(Utils::randomFloat()*360)*(pi()/180));
|
||||
$data = array(
|
||||
"x" => $x+($shiftX*$randomRange)+0.5,
|
||||
"y" => $y-1,
|
||||
"y" => $y,
|
||||
"z" => $z+($shiftZ*$randomRange)+0.5,
|
||||
);
|
||||
$e = $server->api->entity->add($this->level, ENTITY_MOB, MOB_PIGMAN, $data);
|
||||
|
|
|
|||
|
|
@ -489,9 +489,7 @@ class PMFLevel extends PMF{
|
|||
$pos = new Position($x, $y, $z, $this->level);
|
||||
for($side = 0; $side <= 5; ++$side){
|
||||
$b = $pos->getSide($side);
|
||||
if($b instanceof LavaBlock)
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
|
||||
else ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate($b, ($b instanceof LavaBlock ? 40: 10), BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ class Explosion{
|
|||
}
|
||||
|
||||
public function explode(){
|
||||
console("a");
|
||||
if(!Explosion::$enableExplosions){ /*Disable Explosions*/
|
||||
return;
|
||||
}
|
||||
|
|
@ -40,7 +41,7 @@ class Explosion{
|
|||
]) === false){
|
||||
return false;
|
||||
}
|
||||
|
||||
console("b");
|
||||
$mRays = $this->rays - 1;
|
||||
for($i = 0; $i < $this->rays; ++$i){
|
||||
for($j = 0; $j < $this->rays; ++$j){
|
||||
|
|
@ -59,6 +60,7 @@ class Explosion{
|
|||
$block->x = $vBlock->x;
|
||||
$block->y = $vBlock->y;
|
||||
$block->z = $vBlock->z;
|
||||
$block->level = $this->level;
|
||||
$blastForce -= ($block->getHardness() / 5 + 0.3) * $this->stepLen;
|
||||
if($blastForce > 0){
|
||||
$index = ($block->x << 15) + ($block->z << 7) + $block->y;
|
||||
|
|
@ -84,7 +86,6 @@ class Explosion{
|
|||
}
|
||||
|
||||
foreach($this->affectedBlocks as $block){
|
||||
|
||||
if($block instanceof TNTBlock){
|
||||
$data = [
|
||||
"x" => $block->x + 0.5,
|
||||
|
|
@ -100,7 +101,7 @@ class Explosion{
|
|||
$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem($drop[0], $drop[1], $drop[2])); //id, meta, count
|
||||
}
|
||||
}
|
||||
$this->level->setBlock($block, new AirBlock(), true, false, true);
|
||||
$this->level->setBlock($block, new AirBlock(), true);
|
||||
$send[] = $block->subtract($source);
|
||||
}
|
||||
$pk = new ExplodePacket;
|
||||
|
|
|
|||
|
|
@ -261,6 +261,8 @@ class Level{
|
|||
|
||||
public function onTick(PocketMinecraftServer $server){
|
||||
//$ents = $server->api->entity->getAll($this);
|
||||
if(!$this->stopTime) ++$this->time;
|
||||
ConsoleAPI::debug($this->getTime());
|
||||
foreach($this->entityList as $k => $e){
|
||||
if(!($e instanceof Entity)){
|
||||
unset($this->entityList[$k]);
|
||||
|
|
@ -280,14 +282,12 @@ class Level{
|
|||
if(!isset($this->level) or (($pos instanceof Position) and $pos->level !== $this) or $pos->x < 0 or $pos->y < 0 or $pos->z < 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
$ret = $this->level->setBlock($pos->x, $pos->y, $pos->z, $block->getID(), $block->getMetadata());
|
||||
if($ret === true){
|
||||
if(!($pos instanceof Position)){
|
||||
$pos = new Position($pos->x, $pos->y, $pos->z, $this);
|
||||
}
|
||||
$block->position($pos);
|
||||
|
||||
if($direct === true){
|
||||
$pk = new UpdateBlockPacket;
|
||||
$pk->x = $pos->x;
|
||||
|
|
@ -500,13 +500,14 @@ class Level{
|
|||
}else{
|
||||
$time = $this->startTime + ($now - $this->startCheck) * 20;
|
||||
}
|
||||
if($this->server->api->dhandle("time.change", ["level" => $this, "time" => $time]) !== false){
|
||||
if($this->server->api->dhandle("time.change", ["level" => $this, "time" => $time]) !== false){ //send time to player every 5 ticks
|
||||
$this->time = $time;
|
||||
|
||||
$pk = new SetTimePacket;
|
||||
$pk->time = (int) $this->time;
|
||||
$pk->started = $this->stopTime == false;
|
||||
$this->server->api->player->broadcastPacket($this->players, $pk);
|
||||
}else{
|
||||
$this->time -= 20 * 13;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue