more stuff uses StaticBlock class now

This commit is contained in:
GameHerobrine 2023-07-08 20:54:03 +03:00
parent 9cb7fbafaa
commit e70c501df8
12 changed files with 49 additions and 86 deletions

View file

@ -42,12 +42,11 @@ class TileNavigator implements ITileNavigator
$current = $open->top();
$open->next();
if ($current == $to){
return $this->reconstructPath($path, $current);
}
foreach($this->neighborProvider->getNeighbors($current) as $neighbor)
{
if(!Utils::in_range(Utils::distance_noroot($neighbor->asArray(), $from->asArray()), -$maxDist, $maxDist)){
if(!Utils::in_range(($from->x - $neighbor->x)*($from->x - $neighbor->x) + ($from->y - $neighbor->y)*($from->y - $neighbor->y) + ($from->z - $neighbor->z)*($from->z - $neighbor->z), -$maxDist, $maxDist)){ //Utils::distance_noroot($neighbor->asArray(), $from->asArray())
continue;
}
if(isset($visited[(string)$neighbor])){

View file

@ -7,7 +7,7 @@ class Pythagoras3D implements IDistanceAlgorithm
public function calculate(PathTile $from, PathTile $to)
{
if($from instanceof PathTileXYZ && $to instanceof PathTileXYZ){
return Utils::distance_noroot($from->asArray(), $to->asArray());
return sqrt(($to->x - $from->x) * ($to->x - $from->x) + ($to->y - $from->y) * ($to->y - $from->y) + ($to->z - $from->z) * ($to->z - $from->z));
}
return INF;
}

View file

@ -5,11 +5,7 @@ class MCBlockedProvider implements IBlockedProvider
{
public function isBlocked(PathTile $tile)
{
if($tile instanceof PathTileXYZ){
$b = $tile->level->getBlockWithoutVector($tile->x, $tile->y, $tile->z);
return $b instanceof Block && $b->isSolid;
}
return false;
return $tile instanceof PathTileXYZ && StaticBlock::getIsSolid($tile->level->level->getBlockID($tile->x, $tile->y, $tile->z));
}
}

View file

@ -7,18 +7,17 @@ class MCDiagonalProvider implements INeighborProvider
private static $moveDownOffset = [0, -1, 0];
public function getNeighbors(PathTile $tile)
{
if($tile instanceof PathTileXYZ){
$pnts = [];
foreach(MCDiagonalProvider::$neighbors as $offset){
$pnt = $tile->addOffset($offset);
if(!$tile->level->getBlockWithoutVector($pnt->x, $pnt->y, $pnt->z, false)->isSolid){
if(!$tile->level->getBlockWithoutVector($pnt->x, $pnt->y - 1, $pnt->z, false)->isSolid){
if(!StaticBlock::getIsSolid($tile->level->level->getBlockID($pnt->x, $pnt->y, $pnt->z))){
if(!StaticBlock::getIsSolid($tile->level->level->getBlockID($pnt->x, $pnt->y - 1, $pnt->z, false))){
--$pnt->y;
}
$pnts[] = $pnt;
}else{
if(!$tile->level->getBlockWithoutVector($pnt->x, $pnt->y + 1, $pnt->z, false)->isSolid){
if(!StaticBlock::getIsSolid($tile->level->level->getBlockID($pnt->x, $pnt->y + 1, $pnt->z, false))){
++$pnt->y;
$pnts[] = $pnt;
}

View file

@ -522,46 +522,6 @@ class Entity extends Position
}
++$this->counter;
if($this->isStatic === false){
/*$startX = floor($this->x - 0.5 - $this->width - 1);
// prefix for flying when player on fence
$y = floor($this->y - 1);
$yC = ceil($this->y - 1);
$startZ = floor($this->z - 0.5 - $this->width - 1);
$endX = ceil($this->x - 0.5 + $this->width + 1);
$endZ = ceil($this->z - 0.5 + $this->width + 1);
$support = false;
$isFlying = true;
if($this->isPlayer()){
for($z = $startZ; $z <= $endZ; ++ $z){
for($x = $startX; $x <= $endX; ++ $x){
$v = new Vector3($x, $y, $z);
$v1 = new Vector3($x, $yC, $z);
if($this->isSupport($v, $this->width)){
$b = $this->level->level->getBlockID($x, $y, $z);
if(StaticBlock::getIsSolid($b) === true){
$support = true;
$isFlying = false;
break;
} elseif(StaticBlock::getIsLiquid($b) or $b === COBWEB or $b === LADDER or $b === FENCE or $b=== STONE_WALL or $b === IRON_BARS){
$isFlying = false;
}
} elseif($this->isSupport($v1, $this->width)){
$b = $this->level->getBlock($v1);
if($b->isSolid === true){
$support = true;
$isFlying = false;
break;
} elseif(($b instanceof LiquidBlock) or $b->getID() === COBWEB or $b->getID() === LADDER or $b->getID() === FENCE or $b->getID() === STONE_WALL or $b->getID() === IRON_BARS){
$isFlying = false;
}
}
}
if($support === true){
break;
}
}
}*/ //this one is not neccessary anymore?
if(!$this->isPlayer()){
$update = false;
if(Utils::in_range($this->speedX, -0.01, 0.01)){
@ -645,7 +605,7 @@ class Entity extends Position
$x = (int) ($this->x - 0.5);
$z = (int) ($this->z - 0.5);
$lim = (int) floor($ny);
for($y = (int) ceil($this->y) - 1; $y >= $lim; -- $y){
for($y = floor($this->y); $y >= $lim; --$y){
if(StaticBlock::getIsSolid($this->level->level->getBlockID($x, $y, $z))){
//$support = true;
$this->y = $ny;

View file

@ -89,12 +89,12 @@ class Arrow extends Projectile{
for($x = floor($rt->minX); $x < ceil($rt->maxX); ++$x){
for($z = floor($rt->minZ); $z < ceil($rt->maxZ); ++$z){
for($y = ceil($rt->minY); $y < ceil($rt->maxY); ++$y){
$pos = new Vector3($x, $y, $z);
$b = $this->level->getBlock($pos);
if($b != false && $b->isSolid){
$this->speedY = $b->boundingBox->calculateYOffset($this->boundingBox, $this->speedY);
$this->speedX = $b->boundingBox->calculateXOffset($this->boundingBox, $this->speedX);
$this->speedZ = $b->boundingBox->calculateZOffset($this->boundingBox, $this->speedZ);
$b = $this->level->level->getBlockID($x, $y, $z);
if(StaticBlock::getIsSolid($b)){
$bb = StaticBlock::getBoundingBoxForBlockCoords($b, $x, $y, $z);
$this->speedY = $bb->calculateYOffset($this->boundingBox, $this->speedY);
$this->speedX = $bb->calculateXOffset($this->boundingBox, $this->speedX);
$this->speedZ = $bb->calculateZOffset($this->boundingBox, $this->speedZ);
$this->inWall = true;
break;
}

View file

@ -61,8 +61,9 @@ class NetherReactorBlock extends SolidBlock{
for($a = $aOne; $a < $aTwo; $a += $aThree) { //wth those cycles are? TODO simplify if possible(makes server lag)
for($b = $bOne; $b < $bTwo; $b += $bThree) {
for($c = $cOne; $c < $cTwo; $c += $cThree) {
if ($this->level->getBlock(new Vector3($x+$a, $y+$b, $z+$c))->getID() === 87 && Utils::randomFloat() > 0.75){
$this->level->setBlock(new Vector3($x+$a, $y+$b, $z+$c), new AirBlock());
if ($this->level->level->getBlockID($x+$a, $y+$b, $z+$c) === NETHERRACK && Utils::randomFloat() > 0.75){
//$this->level->setBlock(new Vector3($x+$a, $y+$b, $z+$c), new AirBlock());
$this->level->fastSetBlockUpdate($x+$a, $y+$b, $z+$c, 0, 0); //TODO might be better to set not directly?
}
}
}
@ -188,7 +189,7 @@ class NetherReactorBlock extends SolidBlock{
foreach($this->core as $yOffset => $layer){
foreach($layer as $line){
foreach(str_split($line) as $char){
$b = $this->level->getBlock(new Vector3($x + $offsetX, $y + $yOffset, $z + $offsetZ))->getID();
$b = $this->level->level->getBlockID($x + $offsetX, $y + $yOffset, $z + $offsetZ);
switch($char){
case "G":
if($b === GOLD_BLOCK){ //TODO make it use structure class
@ -201,7 +202,7 @@ class NetherReactorBlock extends SolidBlock{
}
return false;
case "R":
if($b === NETHER_REACTOR and $this->level->getBlock(new Vector3($x + $offsetX, $y + $yOffset, $z + $offsetZ))->getMetadata() === 0){
if($b === NETHER_REACTOR and $this->level->level->getBlockDamage($x + $offsetX, $y + $yOffset, $z + $offsetZ) === 0){
break;
}
return false;
@ -210,8 +211,6 @@ class NetherReactorBlock extends SolidBlock{
break;
}
return false;
default:
break;
}
++$offsetX;
}

View file

@ -18,17 +18,17 @@ class FarmlandBlock extends TransparentBlock{
public static function onRandomTick(Level $level, $x, $y, $z){
$meta = $level->level->getBlockDamage($x, $y, $z);
$b = $level->getBlockWithoutVector($x, $y + 1, $z, $level, false);
$b = $level->level->getBlockID($x, $y + 1, $z);
if($meta === 0 && mt_rand(0, 5) === 0){
$water = self::checkWaterStatic($level, $x, $y, $z);
if($water){
$level->setBlock(new Position($x, $y, $z, $level), BlockAPI::get(FARMLAND, 1), true, false, true);
}elseif(!(($b instanceof Block) && $b->isTransparent && $b->id != 0)){
}elseif($b != 0 && StaticBlock::getIsTransparent($b)){
$level->setBlock(new Position($x, $y, $z, $level), BlockAPI::get(DIRT, 0), true, false, true);
}
}
if($b instanceof Block && !$b->isFlowable){
if(!StaticBlock::getIsFlowable($b)){
$level->setBlock(new Position($x, $y, $z, $level), BlockAPI::get(DIRT, 0), true, false, true);
}
}

View file

@ -47,7 +47,7 @@ class GrassBlock extends SolidBlock{
return;
}
public static function onRandomTick(Level $level, $x, $y, $z){
if(!$level->getBlockWithoutVector($x, $y + 1, $z, false)->isTransparent && mt_rand(0, 2) == 1){
if(!StaticBlock::getIsTransparent($level->level->getBlockID($x, $y + 1, $z)) && mt_rand(0, 2) == 1){
$level->fastSetBlockUpdate($x, $y, $z, DIRT, 0);
}else{
for($cnt = 0; $cnt < 4; ++$cnt){
@ -55,8 +55,8 @@ class GrassBlock extends SolidBlock{
$y = $y + mt_rand(0, 4) - 3;
$z = $z + mt_rand(0, 2) - 1;
$blockUp = $level->getBlockWithoutVector($x, $y + 1, $z, false);
if($blockUp->isTransparent && !$blockUp->isLiquid && !($blockUp->getID() === 60) && $level->level->getBlockID($x, $y, $z) === DIRT){
$blockUp = $level->level->getBlockID($x, $y + 1, $z);
if(StaticBlock::getIsTransparent($blockUp) && !StaticBlock::getIsLiquid($blockUp) && !($blockUp === 60) && $level->level->getBlockID($x, $y, $z) === DIRT){
$level->fastSetBlockUpdate($x, $y, $z, GRASS, 0);
}

View file

@ -25,8 +25,8 @@ class LeavesBlock extends TransparentBlock{
}
$visited[$index] = true;
$block = $level->getBlockWithoutVector($x, $y, $z, false);
if($block instanceof WoodBlock){ //type doesn't matter
$block = $level->level->getBlockID($x, $y, $z);
if($block === WOOD){ //type doesn't matter
return true;
}

View file

@ -184,9 +184,10 @@ class RailLogic
$meta = $this->level->level->getBlockDamage($this->x, $this->x, $this->z) & 8 | $state;
}
$b = $this->level->getBlockWithoutVector($this->x, $this->y, $this->z);
$b->setMetadata($meta);
$this->level->setBlock(new Vector3($this->x, $this->y, $this->z), $b, true, false, true);
//$b = $this->level->getBlockWithoutVector($this->x, $this->y, $this->z);
//$b->setMetadata($meta);
//$this->level->setBlock(new Vector3($this->x, $this->y, $this->z), $b, true, false, true);
$this->level->fastSetBlockUpdateMeta($this->x, $this->y, $this->z, $meta, true);
}
public function updateConnections($meta){

View file

@ -287,8 +287,21 @@ class Level{
}
return $ret;
}
public function fastSetBlockUpdateMeta($x, $y, $z, $meta, $updateBlock = false){
$this->level->setBlockDamage($x, $y, $z, $meta);
$pk = new UpdateBlockPacket;
$pk->x = $x;
$pk->y = $y;
$pk->z = $z;
$pk->block = $this->level->getBlockID($x, $y, $z);
$pk->meta = $meta;
$this->server->api->player->broadcastPacket($this->players, $pk);
if($updateBlock){
$this->server->api->block->blockUpdateAround(new Position($x, $y, $z, $this), BLOCK_UPDATE_NORMAL, 1);
}
}
public function fastSetBlockUpdate($x, $y, $z, $id, $meta){
public function fastSetBlockUpdate($x, $y, $z, $id, $meta, $updateBlock = false){
$this->level->setBlock($x, $y, $z, $id, $meta);
$pk = new UpdateBlockPacket;
$pk->x = $x;
@ -297,6 +310,9 @@ class Level{
$pk->block = $id;
$pk->meta = $meta;
$this->server->api->player->broadcastPacket($this->players, $pk);
if($updateBlock){
$this->server->api->block->blockUpdateAround(new Vector3($x, $y, $z), BLOCK_UPDATE_NORMAL, 1);
}
}
public function onTick(PocketMinecraftServer $server){
@ -305,22 +321,14 @@ class Level{
for($cX = 0; $cX < 16; ++$cX){
for($cZ = 0; $cZ < 16; ++$cZ){
for($c = 0; $c <= 20; ++$c){
//$this->randInt1 = ($this->randInt1 * 3 + $this->randInt2) & 0xffffffff;
$xyz = mt_rand(0, 0xffffffff) >> 2;//$this->randInt1 >> 2;
$xyz = mt_rand(0, 0xffffffff) >> 2;//TODO fix php5
$x = $xyz & 0xf;
$z = ($xyz >> 8) & 0xf; //TODO might be possible to make some micro optmizations
$y = ($xyz >> 16) & 0x7f;
$id = $this->level->getBlockID(($cX << 4) + $x, $y, $z + ($cZ << 4));
if(isset(self::$randomUpdateBlocks[$id])){
$cl = Block::$class[$id];
//if($cl !== false){
$cl::onRandomTick($this, ($cX << 4) + $x, $y, $z + ($cZ << 4));
//}
//$p->setXYZ(($cX << 4) + $x, $y, $z + ($cZ << 4));
//$b = BlockAPI::get($idmeta[0], $idmeta[1], $p); //$this->getBlockWithoutVector();
//if($b instanceof Block){
// $b->onUpdate(BLOCK_UPDATE_RANDOM);
//}
}
}
}
@ -329,6 +337,7 @@ class Level{
foreach($this->entityList as $k => $e){
if(!($e instanceof Entity)){
unset($this->entityList[$k]);
unset($this->server->entities[$k]);
continue;
}