This commit is contained in:
GameHerobrine 2023-12-15 07:56:24 +03:00
commit 4cd25f02fb
4 changed files with 138 additions and 131 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"){
$cnt = 0;
foreach($this->entities as $e){
if(isset($e) && $e != null && !$e->isPlayer()){ //if player, not despawning
$this->remove($e->eid);
$cnt++;
}
}
}else{
$array = explode(",", strtolower($args[0]));
if(count($array) > 4){
$output .= "Many arguments!";
break;
}
//terrible code
$list = "";
$temp = ["mobs" => "2", "objects" => "3", "items" => "4", "fallings" => "5"];
foreach($array as $value){
$list .= $temp[$value]." or ";
}
$despawning = substr($list, 0, -4);
$l = $this->server->query("SELECT EID FROM entities WHERE class = ".$despawning.";");
if($l !== false and $l !== true){
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$e = $this->get($e["EID"]);
if($e instanceof Entity){
$this->remove($e->eid);
$cnt++;
}
}
}
}
} }
$output = "$cnt entities have been despawned!"; $despawnclass = 0;
$despawntype = 0;
switch($args[0]){
case "all":
foreach($this->entities as $entity){
if($entity instanceof Entity && !$entity->isPlayer()){
$entity->close();
++$cnt;
}
}
break; break;
case "minecarts":
$despawntype = OBJECT_MINECART;
break;
case "mobs":
$despawnclass = ENTITY_MOB;
break;
case "objects":
$despawnclass = ENTITY_OBJECT;
break;
case "items":
$despawnclass = ENTITY_ITEM;
break;
case "fallings":
$despawnclass = ENTITY_FALLING;
break;
}
if($despawnclass){
foreach($this->entities as $entity){
if($entity instanceof Entity && !$entity->isPlayer() && $entity->class === $despawnclass){
$entity->close();
++$cnt;
}
}
}
if($despawntype){
foreach($this->entities as $entity){
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);
for($y = (int) ceil($this->y) - 1; $y >= $lim; -- $y){
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(); $this->close();
return false; return;
} }
$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

@ -1,6 +1,14 @@
<?php <?php
class BedBlock extends TransparentBlock{ class BedBlock extends TransparentBlock{
public static $faces = [
0 => 3,
1 => 4,
2 => 2,
3 => 5,
];
public function __construct($type = 0){ public function __construct($type = 0){
parent::__construct(BED_BLOCK, $type, "Bed Block"); parent::__construct(BED_BLOCK, $type, "Bed Block");
$this->isActivable = true; $this->isActivable = true;
@ -50,15 +58,10 @@ class BedBlock extends TransparentBlock{
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0); $down = $this->getSide(0);
if($down->isTransparent === false){ if($down->isTransparent === false){
$faces = array(
0 => 3,
1 => 4,
2 => 2,
3 => 5,
);
$d = $player->entity->getDirection(); $d = $player->entity->getDirection();
$next = $this->getSide($faces[(($d + 3) % 4)]); $next = $this->getSide(self::$faces[(($d + 3) % 4)]);
$downNext = $this->getSide(0); $downNext = $next->getSide(0);
if($next->isReplaceable === true and $downNext->isTransparent === false){ if($next->isReplaceable === true and $downNext->isTransparent === false){
$meta = (($d + 3) % 4) & 0x03; $meta = (($d + 3) % 4) & 0x03;
$this->level->setBlock($block, BlockAPI::get($this->id, $meta), true, false, true); $this->level->setBlock($block, BlockAPI::get($this->id, $meta), true, false, true);
@ -76,24 +79,34 @@ class BedBlock extends TransparentBlock{
$blockWest = $this->getSide(4); $blockWest = $this->getSide(4);
if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed
if($blockNorth->getID() === $this->id and $blockNorth->meta !== 0x08){ //Checks if the block ID and meta are right switch($this->meta & 0x7){
$this->level->setBlock($blockNorth, new AirBlock(), true, false, true); case 0:
}elseif($blockSouth->getID() === $this->id and $blockSouth->meta !== 0x08){ if($blockNorth->id === $this->id) $this->level->setBlock($blockNorth, new AirBlock(), true, false, true);
$this->level->setBlock($blockSouth, new AirBlock(), true, false, true); break;
}elseif($blockEast->getID() === $this->id and $blockEast->meta !== 0x08){ case 1:
$this->level->setBlock($blockEast, new AirBlock(), true, false, true); if($blockEast->id === $this->id) $this->level->setBlock($blockEast, new AirBlock(), true, false, true);
}elseif($blockWest->getID() === $this->id and $blockWest->meta !== 0x08){ break;
$this->level->setBlock($blockWest, new AirBlock(), true, false, true); case 2:
if($blockSouth->id === $this->id) $this->level->setBlock($blockSouth, new AirBlock(), true, false, true);
break;
case 3:
if($blockWest->id === $this->id) $this->level->setBlock($blockWest, new AirBlock(), true, false, true);
break;
} }
}else{ //Bottom Part of Bed }else{ //Bottom Part of Bed
if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){ switch($this->meta & 0x7){
$this->level->setBlock($blockNorth, new AirBlock(), true, false, true); case 0:
}elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){ if($blockSouth->id === $this->id) $this->level->setBlock($blockSouth, new AirBlock(), true, false, true);
$this->level->setBlock($blockSouth, new AirBlock(), true, false, true); break;
}elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){ case 1:
$this->level->setBlock($blockEast, new AirBlock(), true, false, true); if($blockWest->id === $this->id) $this->level->setBlock($blockWest, new AirBlock(), true, false, true);
}elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){ break;
$this->level->setBlock($blockWest, new AirBlock(), true, false, true); case 2:
if($blockNorth->id === $this->id) $this->level->setBlock($blockNorth, new AirBlock(), true, false, true);
break;
case 3:
if($blockEast->id === $this->id) $this->level->setBlock($blockEast, new AirBlock(), true, false, true);
break;
} }
} }
$this->level->setBlock($this, new AirBlock(), true, false, true); $this->level->setBlock($this, new AirBlock(), true, false, true);

View file

@ -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){