mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
no more mob pushing as it was causing a lot of memery waste, added 0.9 branch fix
This commit is contained in:
parent
a3711cfded
commit
a3fda45979
4 changed files with 3 additions and 59 deletions
|
|
@ -86,10 +86,8 @@ class PocketMinecraftServer{
|
|||
"discord-bot-name" => "NostalgiaCore Logger",
|
||||
"despawn-mobs" => true,
|
||||
"mob-despawn-ticks" => 18000,
|
||||
"entity-pushing" => false
|
||||
|
||||
]);
|
||||
Living::$entityPushing = $this->extraprops->get("entity-pushing");
|
||||
Living::$despawnMobs = $this->extraprops->get("despawn-mobs");
|
||||
Living::$despawnTimer = $this->extraprops->get("mob-despawn-ticks");
|
||||
Entity::$allowedAI = $this->extraprops->get("enable-mob-ai");
|
||||
|
|
|
|||
|
|
@ -65,9 +65,9 @@ abstract class Living extends Entity implements Damageable, Pathfindable{
|
|||
}
|
||||
$this->ai->mobController->rotateTick();
|
||||
$this->ai->mobController->movementTick();
|
||||
if(self::$entityPushing){
|
||||
/*if(self::$entityPushing){
|
||||
$this->collideHandler();
|
||||
}
|
||||
}*/
|
||||
if($this->onGround){
|
||||
//if(!$this->hasPath() && $this->pathFinder instanceof ITileNavigator){
|
||||
// $this->path = $this->pathFinder->navigate(new PathTileXYZ($this->x, $this->y, $this->z, $this->level), new PathTileXYZ($this->x + mt_rand(-10, 10), $this->y + mt_rand(-1, 1), $this->z + mt_rand(-10, 10), $this->level), 10);
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ class EntityAI
|
|||
}
|
||||
|
||||
public function updateTasks(){
|
||||
if(!($this->entity instanceof Entity)) return;
|
||||
if(!isset($this->entity) || !($this->entity instanceof Entity)) return;
|
||||
foreach($this->tasks as $t){
|
||||
if(!$t->isStarted && $t->canBeExecuted($this)){
|
||||
$t->isStarted = true;
|
||||
|
|
|
|||
|
|
@ -10,11 +10,6 @@ class Level{
|
|||
* @var Entity[]
|
||||
*/
|
||||
public $entityList;
|
||||
/**
|
||||
* Entity list based on their chunk positions
|
||||
* @var array()
|
||||
*/
|
||||
public $entityChunked;
|
||||
|
||||
public $tiles, $blockUpdates, $nextSave, $players = [], $level, $mobSpawner;
|
||||
private $time, $startCheck, $startTime, $server, $name, $usedChunks, $changedBlocks, $changedCount, $stopTime;
|
||||
|
|
@ -280,63 +275,14 @@ class Level{
|
|||
unset($this->entityList[$k]);
|
||||
continue;
|
||||
}
|
||||
$prevIndex = (((int)$e->x) >> 4).":".(((int)$e->y) >> 4).":".(((int)$e->z) >> 4);
|
||||
if(!(nullsafe($this->entityChunked[$prevIndex][$k], false) instanceof Entity)){
|
||||
$this->entityChunked[$prevIndex][$k] = &$this->entityList[$k];
|
||||
}
|
||||
if($e->needsUpdate){
|
||||
$e->update();
|
||||
}
|
||||
$newIndex = (((int)$e->x) >> 4).":".(((int)$e->y) >> 4).":".(((int)$e->z) >> 4);
|
||||
if($newIndex != $prevIndex){
|
||||
unset($this->entityChunked[$prevIndex][$k]);
|
||||
$this->entityChunked[$newIndex][$k] = &$this->entityList[$k];
|
||||
}
|
||||
}
|
||||
if(Entity::$updateOnTick && $server->ticks % 40 === 0){ //40 ticks delay
|
||||
$this->mobSpawner->handle();
|
||||
}
|
||||
}
|
||||
public function applyCallbackToNearbyEntities(Entity $e, callable $c, $radius = 5){
|
||||
$minChunkX = ((int)($e->x - $radius)) >> 4;
|
||||
$minChunkY = ((int)($e->y - $radius)) >> 4;
|
||||
$minChunkZ = ((int)($e->z - $radius)) >> 4;
|
||||
$maxChunkX = ((int)($e->x + $radius)) >> 4;
|
||||
$maxChunkY = ((int)($e->y + $radius)) >> 4;
|
||||
$maxChunkZ = ((int)($e->z + $radius)) >> 4;
|
||||
$ents = [];
|
||||
for($chunkX = $minChunkX; $chunkX <= $maxChunkX; ++$chunkX){
|
||||
for($chunkY = $minChunkY; $chunkY <= $maxChunkY; ++$chunkY){
|
||||
for($chunkZ = $minChunkZ; $chunkZ <= $maxChunkZ; ++$chunkZ){
|
||||
$ind = (((int)$e->x) >> 4).":".(((int)$e->y) >> 4).":".(((int)$e->z) >> 4);
|
||||
foreach(nullsafe($this->entityChunked[$ind], []) as $e){
|
||||
$c($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//unset($ents[$e->eid]);
|
||||
}
|
||||
public function getEntitiesNearby(Entity $e, $radius = 5){
|
||||
$minChunkX = ((int)($e->x - $radius)) >> 4;
|
||||
$minChunkY = ((int)($e->y - $radius)) >> 4;
|
||||
$minChunkZ = ((int)($e->z - $radius)) >> 4;
|
||||
$maxChunkX = ((int)($e->x + $radius)) >> 4;
|
||||
$maxChunkY = ((int)($e->y + $radius)) >> 4;
|
||||
$maxChunkZ = ((int)($e->z + $radius)) >> 4;
|
||||
$ents = [];
|
||||
for($chunkX = $minChunkX; $chunkX <= $maxChunkX; ++$chunkX){
|
||||
for($chunkY = $minChunkY; $chunkY <= $maxChunkY; ++$chunkY){
|
||||
for($chunkZ = $minChunkZ; $chunkZ <= $maxChunkZ; ++$chunkZ){
|
||||
$ind = (((int)$e->x) >> 4).":".(((int)$e->y) >> 4).":".(((int)$e->z) >> 4);
|
||||
$ents += $this->entityChunked[$ind];
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($ents[$e->eid]);
|
||||
//if(count($ents) > 0) console(count($ents));
|
||||
|
||||
}
|
||||
|
||||
public function setBlock(Vector3 $pos, Block $block, $update = true, $tiles = false, $direct = false){
|
||||
if(!isset($this->level) or (($pos instanceof Position) and $pos->level !== $this) or $pos->x < 0 or $pos->y < 0 or $pos->z < 0){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue