Some changes.

This commit is contained in:
kotyaralih 2021-12-04 12:45:34 -08:00
parent 20c16068ec
commit d6cc8415dc
30 changed files with 359 additions and 106 deletions

View file

@ -80,15 +80,15 @@ class Entity extends Position{
$this->name = "";
$this->tickCounter = 0;
$this->server->query("INSERT OR REPLACE INTO entities (EID, level, type, class, health, hasUpdate) VALUES (".$this->eid.", '".$this->level->getName()."', ".$this->type.", ".$this->class.", ".$this->health.", 0);");
$this->x = isset($this->data["x"]) ? $this->data["x"]:0;
$this->y = isset($this->data["y"]) ? $this->data["y"]:0;
$this->z = isset($this->data["z"]) ? $this->data["z"]:0;
$this->speedX = isset($this->data["speedX"]) ? $this->data["speedX"]:0;
$this->speedY = isset($this->data["speedY"]) ? $this->data["speedY"]:0;
$this->speedZ = isset($this->data["speedZ"]) ? $this->data["speedZ"]:0;
$this->x = isset($this->data["x"]) ? (float) $this->data["x"]:0;
$this->y = isset($this->data["y"]) ? (float) $this->data["y"]:0;
$this->z = isset($this->data["z"]) ? (float) $this->data["z"]:0;
$this->speedX = isset($this->data["speedX"]) ? (float) $this->data["speedX"]:0;
$this->speedY = isset($this->data["speedY"]) ? (float) $this->data["speedY"]:0;
$this->speedZ = isset($this->data["speedZ"]) ? (float) $this->data["speedZ"]:0;
$this->speed = 0;
$this->yaw = isset($this->data["yaw"]) ? $this->data["yaw"]:0;
$this->pitch = isset($this->data["pitch"]) ? $this->data["pitch"]:0;
$this->yaw = isset($this->data["yaw"]) ? (float) $this->data["yaw"]:0;
$this->pitch = isset($this->data["pitch"]) ? (float) $this->data["pitch"]:0;
$this->position = array("level" => $this->level, "x" => &$this->x, "y" => &$this->y, "z" => &$this->z, "yaw" => &$this->yaw, "pitch" => &$this->pitch);
switch($this->class){
case ENTITY_PLAYER:
@ -130,6 +130,9 @@ class Entity extends Position{
if($this->type === OBJECT_PAINTING){
$this->isStatic = true;
}elseif($this->type === OBJECT_PRIMEDTNT){
if(!isset($this->data["fuse"])){
$this->data["fuse"] = 0;
}
$this->setHealth(10000000, "generic");
$this->server->schedule(5, array($this, "updateFuse"), array(), true);
$this->update();
@ -141,6 +144,9 @@ class Entity extends Position{
}
$this->updateLast();
$this->updatePosition();
if($this->y < 0 and $this->class !== ENTITY_PLAYER){
$this->close();
}
}
public function updateFuse(){
@ -239,7 +245,7 @@ class Entity extends Position{
$time = microtime(true);
if($this->class === ENTITY_PLAYER and ($this->player instanceof Player) and $this->player->spawned === true and $this->player->blocked !== true){
foreach($this->server->api->entity->getRadius($this, 1.5, ENTITY_ITEM) as $item){
if($item->spawntime > 0 and ($time - $item->spawntime) >= 0.6){
if($item->closed === false and $item->spawntime > 0 and ($time - $item->spawntime) >= 0.6){
if((($this->player->gamemode & 0x01) === 1 or $this->player->hasSpace($item->type, $item->meta, $item->stack) === true) and $this->server->api->dhandle("player.pickup", array(
"eid" => $this->player->eid,
"player" => $this->player,
@ -817,7 +823,7 @@ class Entity extends Position{
}
public function setPosition(Vector3 $pos, $yaw = false, $pitch = false){
if($pos instanceof Position and $this->level !== $pos->level){
if($pos instanceof Position and $pos->level instanceof Level and $this->level !== $pos->level){
$this->level = $pos->level;
$this->server->preparedSQL->entity->setLevel->reset();
$this->server->preparedSQL->entity->setLevel->clear();
@ -965,7 +971,7 @@ class Entity extends Position{
}else{
return false; //Entity inmunity
}
}elseif($health === $this->health){
}elseif($health === $this->health and !$this->dead){
return false;
}
if($this->server->api->dhandle("entity.health.change", array("entity" => $this, "eid" => $this->eid, "health" => $health, "cause" => $cause)) !== false or $force === true){

View file

@ -299,6 +299,9 @@ class Level{
}
$block->position($pos);
$i = ($pos->x >> 4).":".($pos->y >> 4).":".($pos->z >> 4);
if(ADVANCED_CACHE == true){
Cache::remove("world:{$this->name}:".($pos->x >> 4).":".($pos->z >> 4));
}
if(!isset($this->changedBlocks[$i])){
$this->changedBlocks[$i] = array();
$this->changedCount[$i] = 0;
@ -336,6 +339,9 @@ class Level{
$this->changedBlocks[$i] = array();
$this->changedCount[$i] = 0;
}
if(ADVANCED_CACHE == true){
Cache::remove("world:{$this->name}:".($pos->x >> 4).":".($pos->z >> 4));
}
$this->changedBlocks[$i][] = clone $block;
++$this->changedCount[$i];
}
@ -365,6 +371,9 @@ class Level{
return false;
}
$this->changedCount[$X.":".$Y.":".$Z] = 4096;
if(ADVANCED_CACHE == true){
Cache::remove("world:{$this->name}:$X:$Z");
}
return $this->level->setMiniChunk($X, $Z, $Y, $data);
}
@ -379,6 +388,7 @@ class Level{
if(!isset($this->level)){
return false;
}
Cache::remove("world:{$this->name}:$X:$Z");
return $this->level->unloadChunk($X, $Z);
}
@ -386,6 +396,15 @@ class Level{
if(!isset($this->level)){
return false;
}
if(ADVANCED_CACHE == true and $Yndex == 0xff){
$identifier = "world:{$this->name}:$X:$Z";
if(($cache = Cache::get($identifier)) !== false){
return $cache;
}
}
$raw = array();
for($Y = 0; $Y < 8; ++$Y){
if(($Yndex & (1 << $Y)) > 0){
@ -401,6 +420,9 @@ class Level{
$ordered .= substr($mini, $j << 5, 24); //16 + 8
}
}
if(ADVANCED_CACHE == true and $Yndex == 0xff){
Cache::add($identifier, $ordered, 60);
}
return $ordered;
}
@ -434,7 +456,10 @@ class Level{
$z = (int) round($spawn->z);
for(; $y > 0; --$y){
$v = new Vector3($x, $y, $z);
if(!($this->getBlock($v->getSide(0)) instanceof AirBlock)){
$b = $this->getBlock($v->getSide(0));
if($b === false){
return $spawn;
}elseif(!($b instanceof AirBlock)){
break;
}
}

View file

@ -234,7 +234,7 @@ class Tile extends Position{
$raw = $this->getSlot(0);
$product = $this->getSlot(2);
$smelt = $raw->getSmeltItem();
$canSmelt = $smelt !== false and $raw->count > 0 and (($product->getID() === $smelt->getID() and $product->getMetadata() === $smelt->getMetadata() and $product->count < $product->getMaxStackSize()) or $product->getID() === AIR);
$canSmelt = ($smelt !== false and $raw->count > 0 and (($product->getID() === $smelt->getID() and $product->getMetadata() === $smelt->getMetadata() and $product->count < $product->getMaxStackSize()) or $product->getID() === AIR));
if($this->data["BurnTime"] <= 0 and $canSmelt and $fuel->getFuelTime() !== false and $fuel->count > 0){
$this->lastUpdate = microtime(true);
$this->data["MaxTime"] = $this->data["BurnTime"] = floor($fuel->getFuelTime() * 20);