mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
onTick update is toggleable in extra.props.
This commit is contained in:
parent
1448fd21b9
commit
08f9193191
5 changed files with 29 additions and 12 deletions
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
class LevelAPI{
|
||||
|
||||
private $server, $levels, $default;
|
||||
public $levels;
|
||||
private $server, $default;
|
||||
|
||||
public function __construct(){
|
||||
$this->server = ServerAPI::request();
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ class PocketMinecraftServer{
|
|||
console("[INFO] Loading extra.properties...");
|
||||
$this->extraprops = new Config(DATA_PATH . "extra.properties", CONFIG_PROPERTIES, [
|
||||
"version" => "5",
|
||||
"update-mobs-on-every-tick" => false,
|
||||
"enable-nether-reactor" => true,
|
||||
"enable-explosions" => true,
|
||||
"enable-rail-connection" => false,
|
||||
|
|
@ -82,6 +83,10 @@ class PocketMinecraftServer{
|
|||
"discord-webhook-url" => "none",
|
||||
"discord-bot-name" => "NostalgiaCore Logger"
|
||||
]);
|
||||
Entity::$updateOnTick = $this->extraprops->get("update-mobs-on-every-tick");
|
||||
if(Entity::$updateOnTick){
|
||||
console("[WARNING] Mobs will update every tick. Might cause lags with a huge amount of entities.");
|
||||
}
|
||||
Explosion::$enableExplosions = $this->extraprops->get("enable-explosions");
|
||||
RailBlock::$shouldconnectrails = $this->extraprops->get("enable-rail-connection"); //Rail connection in config
|
||||
NetherReactorBlock::$enableReactor = $this->extraprops->get("enable-nether-reactor");
|
||||
|
|
@ -469,6 +474,9 @@ class PocketMinecraftServer{
|
|||
}
|
||||
}
|
||||
$this->tick();
|
||||
foreach($this->api->level->levels as $l){
|
||||
$l->onTick($this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,11 @@
|
|||
class Entity extends Position{
|
||||
const TYPE = -1;
|
||||
const CLASS_TYPE = -1;
|
||||
|
||||
public static $updateOnTick;
|
||||
public $isCollidable;
|
||||
public $canBeAttacked;
|
||||
|
||||
public $needsUpdate;
|
||||
/**
|
||||
* @var AxisAlignedBB
|
||||
*/
|
||||
|
|
@ -434,10 +436,9 @@ class Entity extends Position{
|
|||
}
|
||||
if($this->class !== ENTITY_PLAYER){
|
||||
$update = false;
|
||||
if(($this->class !== ENTITY_OBJECT and $this->type !== OBJECT_PRIMEDTNT) or $support === false){
|
||||
if((($this->class !== ENTITY_OBJECT and $this->type !== OBJECT_PRIMEDTNT) or $support === false)){
|
||||
$drag = 0.2;
|
||||
$blocks = $this->level->getCubes($this->boundingBox->getOffsetBoundingBox($this->speedX, $this->speedY, $this->speedZ));
|
||||
|
||||
foreach($blocks as $b){
|
||||
$this->speedX = $b->calculateXOffset($this->boundingBox, $this->speedX);
|
||||
$this->speedY = $b->calculateYOffset($this->boundingBox, $this->speedY);
|
||||
|
|
@ -549,10 +550,11 @@ class Entity extends Position{
|
|||
|
||||
if($this->class !== ENTITY_PLAYER){
|
||||
$this->updateMovement();
|
||||
if($hasUpdate === true){
|
||||
$this->server->schedule(1, array($this, "update"));
|
||||
}
|
||||
}
|
||||
if(self::$updateOnTick && $this->class === ENTITY_MOB){
|
||||
$this->needsUpdate = $hasUpdate;
|
||||
}
|
||||
|
||||
$this->lastUpdate = $now;
|
||||
}
|
||||
|
||||
|
|
@ -803,7 +805,7 @@ class Entity extends Position{
|
|||
}
|
||||
|
||||
public function updateAABB(){
|
||||
$this->boundingBox = new AxisAlignedBB($this->x - $this->radius, $this->y, $this->z - $this->radius, $this->x + $this->radius, $this->y + $this->height, $this->z + $this->radius);
|
||||
$this->boundingBox->setBounds($this->x - $this->radius, $this->y, $this->z - $this->radius, $this->x + $this->radius, $this->y + $this->height, $this->z + $this->radius);
|
||||
}
|
||||
|
||||
public function updatePosition(){
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ define("CONFIG_LIST", 5); // .txt, .list
|
|||
|
||||
/**
|
||||
* Class Config
|
||||
*
|
||||
* Config Class for simple config manipulation of multiple formats.
|
||||
*/
|
||||
class Config{
|
||||
|
|
@ -124,7 +123,6 @@ class Config{
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -329,7 +329,16 @@ class Level{
|
|||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
public function onTick(PocketMinecraftServer $server){
|
||||
$ents = $server->api->entity->getAll($this);
|
||||
foreach($ents as $e){
|
||||
if($e->needsUpdate){
|
||||
$e->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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){
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue