code style fix

This commit is contained in:
Sunch 2025-04-27 20:36:24 +08:00
parent fc5c5625cb
commit 5e8e9330e2
361 changed files with 4766 additions and 4650 deletions

View file

@ -1,4 +1,5 @@
<?php
require_once("LiquidBlockDynamic.php"); //TODO class loader?
class LavaBlock extends LiquidBlockDynamic implements LightingBlock{
@ -7,16 +8,16 @@ class LavaBlock extends LiquidBlockDynamic implements LightingBlock{
parent::__construct(LAVA, $meta, "Lava");
$this->hardness = 500;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$ret = $this->level->setBlock($this, $this, true, false, true);
return $ret;
}
public static function getTickDelay(){
return 30;
}
public function getMaxLightValue(){
return 15;
}

View file

@ -4,55 +4,55 @@ class LiquidBlockDynamic extends LiquidBlock{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
}
public static $blockID = 0;
public static $sourcesAround = 0;
public static $spread = [0, 0, 0, 0];
public static function getHighest(Level $level, $x, $y, $z, $highest){
$depth = static::getDepth($level, $x, $y, $z);
if($depth < 0) return $highest;
if($depth == 0) ++static::$sourcesAround;
if($depth >= 8) $depth = 0;
return $highest >= 0 && $depth >= $highest ? $highest : $depth;
}
public static function setStatic(Level $level, $x, $y, $z){
$meta = $level->level->getBlockDamage($x, $y, $z);
$level->fastSetBlockUpdate($x, $y, $z, static::$blockID + 1, $meta);
}
public static function isWaterBlocking(Level $level, $x, $y, $z){
$id = $level->level->getBlockID($x, $y, $z);
if($id == AIR) return false;
if($id == DOOR_BLOCK || $id == SIGN_POST || $id == WALL_SIGN || $id == LADDER || $id == SUGARCANE_BLOCK) return true;
if($id == CARPET || $id == SNOW_LAYER || $id == RAIL || $id == POWERED_RAIL) return false; //TODO Tile::getThickness() > 0
//TODO materials
//if(!StaticBlock::getIsFlowable($id)) return true;
return StaticBlock::getIsSolid($id);
}
public static function canSpreadTo(Level $level, $x, $y, $z){
$id = $level->level->getBlockID($x, $y, $z);
if($id == LAVA || $id == STILL_LAVA) return false;
if((static::$blockID == WATER) && ($id == WATER || $id == STILL_WATER)) return false;
return static::isWaterBlocking($level, $x, $y, $z) ^ 1;
}
public static function getSpread(Level $level, $x, $y, $z){
for($i = 0; $i < 4; ++$i){
static::$spread[$i] = 1000;
$xs = $x;
$ys = $y;
$zs = $z;
switch($i){
case 0:
--$xs;
@ -67,13 +67,13 @@ class LiquidBlockDynamic extends LiquidBlock{
++$zs;
break;
}
if(static::isWaterBlocking($level, $xs, $ys, $zs)) continue;
[$id, $meta] = $level->level->getBlock($xs, $ys, $zs);
if(((static::$blockID == WATER && ($id == WATER || $id == STILL_WATER)) || (static::$blockID == LAVA && ($id == LAVA || $id == STILL_LAVA))) && $meta == 0){
continue;
}
if(!static::isWaterBlocking($level, $xs, $ys - 1, $zs)) static::$spread[$i] = 0;
else static::$spread[$i] = static::getSlopeDistance($level, $xs, $ys, $zs, 1, $i);
}
@ -85,18 +85,18 @@ class LiquidBlockDynamic extends LiquidBlock{
for($i = 0; $i < 4; ++$i) $ba[$i] = ($i1 == static::$spread[$i]);
return $ba;
}
public static function getSlopeDistance(Level $level, $x, $y, $z, $l, $i1){
$j1 = 1000;
for($k1 = 0; $k1 < 4; ++$k1){
if($k1 == 0 && $i1 == 1 || $k1 == 1 && $i1 == 0 || $k1 == 2 && $i1 == 3 || $k1 == 3 && $i1 == 2){
if($k1 == 0 && $i1 == 1 || $k1 == 1 && $i1 == 0 || $k1 == 2 && $i1 == 3 || $k1 == 3 && $i1 == 2){
continue;
}
$xs = $x;
$ys = $y;
$zs = $z;
switch($k1){
case 0:
--$xs;
@ -111,10 +111,10 @@ class LiquidBlockDynamic extends LiquidBlock{
++$zs;
break;
}
if(static::isWaterBlocking($level, $xs, $ys, $zs)) continue;
[$id, $meta] = $level->level->getBlock($xs, $ys, $zs);
if(
((static::$blockID == WATER && ($id == WATER || $id == STILL_WATER)) ||
(static::$blockID == LAVA && ($id == LAVA || $id == STILL_LAVA))) &&
@ -122,20 +122,20 @@ class LiquidBlockDynamic extends LiquidBlock{
){
continue;
}
if(!static::isWaterBlocking($level, $xs, $ys - 1, $zs)) return $l;
if($l >= 4) continue;
$k2 = static::getSlopeDistance($level, $xs, $ys, $zs, $l + 1, $k1);
if($k2 < $j1) $j1 = $k2;
}
return $j1;
}
public static function trySpreadTo(Level $level, $x, $y, $z, $meta){
if(static::canSpreadTo($level, $x, $y, $z)){
[$id, $meta2] = $level->level->getBlock($x, $y, $z);
if($id > 0){
if(($id == LAVA || $id == STILL_LAVA) && (static::$blockID == LAVA || static::$blockID == STILL_LAVA)); //fizz
else{
@ -147,23 +147,23 @@ class LiquidBlockDynamic extends LiquidBlock{
}
}
}
$level->fastSetBlockUpdate($x, $y, $z, static::$blockID, $meta, true);
}
}
public static function onPlace(Level $level, $x, $y, $z){
static::updateLiquid($level, $x, $y, $z);
$id = $level->level->getBlockID($x, $y, $z);
if($id == static::$blockID) ServerAPI::request()->api->block->scheduleBlockUpdateXYZ($level, $x, $y, $z, BLOCK_UPDATE_SCHEDULED, static::getTickDelay());
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
$id = $level->level->getBlockID($x, $y, $z);
$depth = static::getDepth($level, $x, $y, $z);
$flowAdd = (static::$blockID == LAVA) ? 2 : 1;
$flag = true;
if($depth > 0){
static::$sourcesAround = 0;
$highest = static::getHighest($level, $x - 1, $y, $z, -100);
@ -174,19 +174,19 @@ class LiquidBlockDynamic extends LiquidBlock{
if($j1 >= 8 || $highest < 0) $j1 = -1;
$l1 = static::getDepth($level, $x, $y + 1, $z);
if($l1 >= 0) $j1 = ($l1 >= 8 ? $l1 : $l1 + 8);
if(static::$sourcesAround >= 2 && static::$blockID == WATER){
$idBot = $level->level->getBlockID($x, $y - 1, $z);
if($idBot > 0){
if(StaticBlock::getIsSolid($idBot) || (($idBot == WATER || $idBot == STILL_WATER) && $level->level->getBlockDamage($x, $y, $z) == 0)) $j1 = 0;
}
}
//if(static::$blockID == LAVA && $depth < 8 && $j1 < 8 && $j1 > $depth && mt_rand(0, 4) != 0){ TODO fix later
// $j1 = $depth;
// $flag = false;
//}
if($j1 != $depth){
$depth = $j1;
if($depth < 0) $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
@ -195,16 +195,16 @@ class LiquidBlockDynamic extends LiquidBlock{
ServerAPI::request()->api->block->scheduleBlockUpdateXYZ($level, $x, $y, $z, BLOCK_UPDATE_SCHEDULED, static::getTickDelay());
$level->updateNeighborsAt($x, $y, $z, static::$blockID); //TODO check is needed
}
}else if($flag){
}elseif($flag){
static::setStatic($level, $x, $y, $z);
}
}else{
static::setStatic($level, $x, $y, $z);
}
if(static::canSpreadTo($level, $x, $y - 1, $z)){
$level->fastSetBlockUpdate($x, $y - 1, $z, static::$blockID, ($depth >= 8 ? $depth : $depth + 8) & 0xf, true);
}else if($depth >= 0 && ($depth == 0 || static::isWaterBlocking($level, $x, $y - 1, $z))){
}elseif($depth >= 0 && ($depth == 0 || static::isWaterBlocking($level, $x, $y - 1, $z))){
$flags = static::getSpread($level, $x, $y, $z);
$k1 = $depth >= 8 ? 1 : ($depth + $flowAdd);
if($k1 >= 8) return;

View file

@ -6,13 +6,13 @@ class LiquidBlockStatic extends LiquidBlock{
}
public static $blockID = 0;
//TODO: tick: try spread fire if lava
public static function setDynamic(Level $level, $x, $y, $z){
[$id, $meta] = $level->level->getBlock($x, $y, $z);
$dynamicID = $id - 1; //very unsafe
$level->fastSetBlockUpdate($x, $y, $z, $dynamicID, $meta);
$level->fastSetBlockUpdate($x, $y, $z, $dynamicID, $meta);
}
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
$oldID = $level->level->getBlockID($x, $y, $z);
static::updateLiquid($level, $x, $y, $z);
@ -21,6 +21,5 @@ class LiquidBlockStatic extends LiquidBlock{
static::setDynamic($level, $x, $y, $z);
}
}
}
}

View file

@ -1,4 +1,5 @@
<?php
require_once("LiquidBlockStatic.php"); //TODO class loader?
class StillLavaBlock extends LiquidBlockStatic{
@ -7,9 +8,9 @@ class StillLavaBlock extends LiquidBlockStatic{
parent::__construct(STILL_LAVA, $meta, "Still Lava");
$this->hardness = 500;
}
public static function getTickDelay(){
return 30;
}
}

View file

@ -1,6 +1,5 @@
<?php
/***REM_START***/
require_once("WaterBlock.php"); //TODO class loader?
require_once("LiquidBlockStatic.php"); //TODO class loader?
@ -13,7 +12,7 @@ class StillWaterBlock extends LiquidBlockStatic{
LiquidBlock::__construct(STILL_WATER, $meta, "Still Water");
$this->hardness = 500;
}
public static function getTickDelay(){
return 5;
}

View file

@ -1,19 +1,20 @@
<?php
require_once("LiquidBlockDynamic.php"); //TODO class loader?
class WaterBlock extends LiquidBlockDynamic{
public static $blockID = WATER;
public function __construct($meta = 0){
parent::__construct(WATER, $meta, "Water");
$this->hardness = 500;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$ret = $this->level->setBlock($this, $this, true, false, true);
return $ret;
}
public static function getTickDelay(){
return 5;
}