new 0.9 commits

This commit is contained in:
GameHerobrine 2023-12-15 07:23:20 +03:00 • committed by GitHub
commit 297d2d1bd8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 66 deletions

View file

@ -100,45 +100,53 @@ class EntityAPI{
case "despawn": case "despawn":
$cnt = 0; $cnt = 0;
if(!isset($args[0])){ if(!isset($args[0])){
$output .= "/despawn <all or (mobs,objects,items,fallings)>"; return "/despawn <all|mobs|objects|items|fallings|minecarts>";
break; }
}else{
if($args[0] === "all"){ $despawnclass = 0;
$cnt = 0; $despawntype = 0;
foreach($this->entities as $e){ switch($args[0]){
if(isset($e) && $e != null && !$e->isPlayer()){ //if player, not despawning case "all":
$this->remove($e->eid); foreach($this->entities as $entity){
$cnt++; if($entity instanceof Entity && !$entity->isPlayer()){
$entity->close();
++$cnt;
} }
} }
}else{ break;
$array = explode(",", strtolower($args[0])); case "minecarts":
if(count($array) > 4){ $despawntype = OBJECT_MINECART;
$output .= "Many arguments!"; break;
break; case "mobs":
} $despawnclass = ENTITY_MOB;
//terrible code break;
$list = ""; case "objects":
$temp = ["mobs" => "2", "objects" => "3", "items" => "4", "fallings" => "5"]; $despawnclass = ENTITY_OBJECT;
foreach($array as $value){ break;
$list .= $temp[$value]." or "; case "items":
} $despawnclass = ENTITY_ITEM;
$despawning = substr($list, 0, -4); break;
$l = $this->server->query("SELECT EID FROM entities WHERE class = ".$despawning.";"); case "fallings":
if($l !== false and $l !== true){ $despawnclass = ENTITY_FALLING;
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){ break;
$e = $this->get($e["EID"]); }
if($e instanceof Entity){ if($despawnclass){
$this->remove($e->eid); foreach($this->entities as $entity){
$cnt++; if($entity instanceof Entity && !$entity->isPlayer() && $entity->class === $despawnclass){
} $entity->close();
} ++$cnt;
} }
} }
} }
if($despawntype){
$output = "$cnt entities have been despawned!"; foreach($this->entities as $entity){
break; if($entity instanceof Entity && !$entity->isPlayer() && $entity->type === $despawntype){
$entity->close();
++$cnt;
}
}
}
return "$cnt entities have been despawned!";
} }
return $output; return $output;
} }

View file

@ -601,7 +601,7 @@ class Entity extends Position
} }
$savedSpeedY = $this->speedY; $savedSpeedY = $this->speedY;
if($this->class === ENTITY_MOB || $this->class === ENTITY_ITEM || ($this->class === ENTITY_OBJECT && $this->type === OBJECT_PRIMEDTNT)){ if($this->class === ENTITY_MOB || $this->class === ENTITY_ITEM || ($this->class === ENTITY_OBJECT && $this->type === OBJECT_PRIMEDTNT) || $this->class === ENTITY_FALLING){
$water = false; $water = false;
$aABB = $this->boundingBox->addCoord($this->speedX, $this->speedY, $this->speedZ); $aABB = $this->boundingBox->addCoord($this->speedX, $this->speedY, $this->speedZ);
$x0 = floor($aABB->minX); $x0 = floor($aABB->minX);
@ -645,26 +645,19 @@ class Entity extends Position
} }
if($this->speedY != 0){ if($this->speedY != 0){
$ny = $this->y + $this->speedY; $ny = $this->y + $this->speedY;
if($this->class === ENTITY_FALLING && $ny <= $this->y){ if($this->class === ENTITY_FALLING){
$x = (int) ($this->x - 0.5); if($support){
$z = (int) ($this->z - 0.5); $this->level->fastSetBlockUpdate($this->x, $this->y, $this->z, $this->data["Tile"], 0);
$lim = (int) floor($ny); $this->close();
for($y = (int) ceil($this->y) - 1; $y >= $lim; -- $y){ return;
if($this->level->getBlockWithoutVector($x, $y, $z)->isSolid === true){
//$support = true;
$this->y = $ny;
$fall = $this->level->getBlock(new Vector3(intval($this->x - 0.5), intval(ceil($this->y)), intval($this->z - 0.5)));
$down = $this->level->getBlock(new Vector3(intval($this->x - 0.5), intval(ceil($this->y) - 1), intval($this->z - 0.5)));
if($fall->isFullBlock === false or $down->isFullBlock === false){
$this->server->api->entity->drop($this, BlockAPI::getItem($this->data["Tile"] & 0xFFFF, $this->data["Metadata"], 1), true);
} else{
$this->level->setBlock($fall, BlockAPI::get($this->data["Tile"], $this->data["Metadata"]), true, false, true);
}
$this->server->api->handle("entity.motion", $this);
$this->close();
return false;
}
} }
$id = $this->level->level->getBlockID($this->x, $this->y, $this->z);
if($id > 0 && !StaticBlock::getIsSolid($id) && !StaticBlock::getIsLiquid($id)){
$this->server->api->entity->drop($this, BlockAPI::getItem($this->data["Tile"], 0, 1));
$this->close();
return;
}
} }
$this->y = $ny; $this->y = $ny;

View file

@ -189,7 +189,7 @@ class Level{
} }
$nbt = new NBT_new(NBT_new::LITTLE_ENDIAN); $nbt = new NBT_new(NBT_new::LITTLE_ENDIAN);
foreach($chunkTiles as $tile){ //TODO rewrite TileEntity system foreach($chunkTiles as $tile){ //TODO rewrite TileEntity system
switch($tile->class){ switch($tile->class){
case TILE_SIGN: case TILE_SIGN:
$text = $tile->getText(); $text = $tile->getText();
@ -380,17 +380,6 @@ class Level{
} }
if($this->nextSave < $now){ if($this->nextSave < $now){
foreach($this->usedChunks as $i => $c){
if(count($c) === 0){
unset($this->usedChunks[$i]);
$X = explode(".", $i);
$Z = array_pop($X);
$X = array_pop($X);
if(!$this->isSpawnChunk($X, $Z)){
$this->level->unloadChunk((int) $X, (int) $Z, $this->server->saveEnabled);
}
}
}
$this->save(false, false); $this->save(false, false);
} }
} }
@ -464,6 +453,10 @@ class Level{
$this->freeChunk($xz[0], $xz[1], $p); $this->freeChunk($xz[0], $xz[1], $p);
$p->stopUsingChunk($xz[0], $xz[1]); $p->stopUsingChunk($xz[0], $xz[1]);
} }
}else{
unset($eids[$cid]);
unset($this->usedChunks[$c][$cid]);
ConsoleAPI::debug("Unloaded $c because $cid is not Player");
} }
} }
if(count($eids) <= 0){ if(count($eids) <= 0){