From 3d6c4feb0f463447e1183148a9d1f8b0abd635f0 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Thu, 23 May 2024 06:38:20 +0300 Subject: [PATCH] some tweaks --- src/material/Block.php | 2 +- src/material/block/LiquidBlock.php | 9 ++-- src/material/block/liquid/LavaBlock.php | 1 + .../block/liquid/LiquidBlockDynamic.php | 51 +++++++++---------- src/material/block/liquid/WaterBlock.php | 3 ++ src/pmf/PMFLevel.php | 9 +--- src/world/Level.php | 6 --- 7 files changed, 37 insertions(+), 44 deletions(-) diff --git a/src/material/Block.php b/src/material/Block.php index 650a47a8..8b49559c 100755 --- a/src/material/Block.php +++ b/src/material/Block.php @@ -219,7 +219,7 @@ abstract class Block extends Position{ return MovingObjectPosition::fromBlock($x, $y, $z, $v14, $v13->add($x, $y, $z)); } - + public static function onPlace(Level $level, $x, $y, $z){} public static function addVelocityToEntity(Level $level, $x, $y, $z, Entity $entity, Vector3 $velocityVector){} public static function onRandomTick(Level $level, $x, $y, $z){} public static function onUpdate(Level $level, $x, $y, $z, $type){} diff --git a/src/material/block/LiquidBlock.php b/src/material/block/LiquidBlock.php index aaa89868..88f7c078 100644 --- a/src/material/block/LiquidBlock.php +++ b/src/material/block/LiquidBlock.php @@ -16,14 +16,17 @@ class LiquidBlock extends TransparentBlock{ $this->hardness = 500; } public static $blockID = 0; - public static function getDepth(Level $level, $x, $y, $z){ [$id, $meta] = $level->level->getBlock($x, $y, $z); if($id == static::$blockID) return $meta; - return -1; - + return -1; } + + public static function onPlace(Level $level, $x, $y, $z){ + static::updateLiquid($level, $x, $y, $z); + } + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ static::updateLiquid($level, $x, $y, $z); } diff --git a/src/material/block/liquid/LavaBlock.php b/src/material/block/liquid/LavaBlock.php index ba02516b..21249474 100644 --- a/src/material/block/liquid/LavaBlock.php +++ b/src/material/block/liquid/LavaBlock.php @@ -2,6 +2,7 @@ require_once("LiquidBlockDynamic.php"); //TODO class loader? class LavaBlock extends LiquidBlockDynamic implements LightingBlock{ + public static $blockID = LAVA; public function __construct($meta = 0){ parent::__construct(LAVA, $meta, "Lava"); $this->hardness = 500; diff --git a/src/material/block/liquid/LiquidBlockDynamic.php b/src/material/block/liquid/LiquidBlockDynamic.php index e1b617d1..df4ae3b0 100644 --- a/src/material/block/liquid/LiquidBlockDynamic.php +++ b/src/material/block/liquid/LiquidBlockDynamic.php @@ -10,24 +10,18 @@ class LiquidBlockDynamic extends LiquidBlock{ public static $spread = [0, 0, 0, 0]; public static function getHighest(Level $level, $x, $y, $z, $highest){ - $depth = self::getDepth($level, $x, $y, $z); + $depth = static::getDepth($level, $x, $y, $z); + if($depth < 0) return $highest; + if($depth == 0) ++static::$f_d8; + if($depth >= 8) $depth = 0; - if($depth >= 0){ - if($depth > 7) $depth = 0; - }else{ - ++self::$f_d8; - } - - if($highest < 0) return $depth; - else if($highest >= $depth) return $depth; - - return $highest; + 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, self::$blockID + 1, $meta); + $level->fastSetBlockUpdate($x, $y, $z, static::$blockID + 1, $meta); } public static function isWaterBlocking(Level $level, $x, $y, $z){ @@ -53,7 +47,6 @@ class LiquidBlockDynamic extends LiquidBlock{ } public static function getSpread(Level $level, $x, $y, $z){ - //TODO get rid of gotos for($i = 0; $i < 4; ++$i){ static::$spread[$i] = 1000; $xs = $x; @@ -78,11 +71,7 @@ class LiquidBlockDynamic extends LiquidBlock{ if(static::isWaterBlocking($level, $xs, $ys, $zs)) continue; [$id, $meta] = $level->level->getBlock($xs, $ys, $zs); - if( - (((static::$blockID == WATER || static::$blockID == STILL_WATER) && ($id == WATER || $id == STILL_WATER)) || - ((static::$blockID == LAVA || static::$blockID == STILL_LAVA) && ($id == LAVA || $id == STILL_LAVA))) && - $meta == 0 - ){ + if(((static::$blockID == WATER && ($id == WATER || $id == STILL_WATER)) || (static::$blockID == LAVA && ($id == LAVA || $id == STILL_LAVA))) && $meta == 0){ continue; } @@ -147,18 +136,24 @@ class LiquidBlockDynamic extends LiquidBlock{ $id = $level->level->getBlockID($x, $y, $z); if($id > 0){ - if(($id == LAVA || $id == STILL_LAVA) && (self::$id == LAVA || self::$id == STILL_LAVA)); //fizz + if(($id == LAVA || $id == STILL_LAVA) && (static::$blockID == LAVA || static::$blockID == STILL_LAVA)); //fizz else{ //TODO spawnResources } } - $level->fastSetBlockUpdate($x, $y, $z, self::$blockID, $meta, true); + $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){ - static::$blockID = $id = $level->level->getBlockID($x, $y, $z); + $id = $level->level->getBlockID($x, $y, $z); $depth = static::getDepth($level, $x, $y, $z); if($id == LAVA || $id == STILL_LAVA){ $spreadAdder = 2; //XXX nether has 1 @@ -169,7 +164,7 @@ class LiquidBlockDynamic extends LiquidBlock{ $tickDelay = static::getTickDelay(); if($depth > 0){ - self::$f_d8 = 0; + static::$f_d8 = 0; $highest = static::getHighest($level, $x - 1, $y, $z, -100); $highest = static::getHighest($level, $x + 1, $y, $z, $highest); @@ -187,15 +182,16 @@ class LiquidBlockDynamic extends LiquidBlock{ else $v16 = $dpth + 8; } - if(static::$f_d8 && (static::$blockID == WATER || static::$blockID == STILL_WATER)){ + if(static::$f_d8 && (static::$blockID == WATER)){ //XXX Level::isSolidBlockingTile - [$id, $meta] = $level->level->getBlock($x, $y, $z); - if(StaticBlock::getIsFlowable($id) || ($id == WATER || $id == STILL_WATER) && $meta != 0){ - $v16 = 0; + $idb = $level->level->getBlockID($x, $y - 1, $z); + $metab = $level->level->getBlockDamage($x, $y, $z); + if(StaticBlock::getIsFlowable($idb) || (($idb == WATER || $idb == STILL_WATER) && $metab != 0)){ + //$v16 = 0; } } - if((static::$blockID == LAVA || static::$blockID == STILL_LAVA) && $depth <= 7){ + if(static::$blockID == LAVA && $depth <= 7){ if($v16 > 7) goto LABEL_32; //TODO remove gotos if($v16 > $depth){ @@ -209,6 +205,7 @@ class LiquidBlockDynamic extends LiquidBlock{ goto LABEL_35; } LABEL_32: + ConsoleAPI::debug("v16 is $v16"); $level->fastSetBlockUpdateMeta($x, $y, $z, $v16, false); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($x, $y, $z, $level), $tickDelay); //TODO get rid of new Position $level->updateNeighborsAt($x, $y, $z, static::$blockID); diff --git a/src/material/block/liquid/WaterBlock.php b/src/material/block/liquid/WaterBlock.php index 28ebc131..f0506a23 100644 --- a/src/material/block/liquid/WaterBlock.php +++ b/src/material/block/liquid/WaterBlock.php @@ -2,6 +2,9 @@ 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; diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index 0eb99304..5856dea0 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -500,13 +500,8 @@ class PMFLevel extends PMF{ ++$this->chunkChange[$index][$Y]; } $this->chunkChange[$index][-1] = true; - if($old_b instanceof LiquidBlock){ - $pos = new Position($x, $y, $z, $this->level); - for($side = 0; $side <= 5; ++$side){ - $b = $pos->getSide($side); - ServerAPI::request()->api->block->scheduleBlockUpdate($b, ($b instanceof LavaBlock ? 40: 10), BLOCK_UPDATE_NORMAL); - } - } + + if($block > 0) StaticBlock::getBlock($block)::onPlace($this->level, $x, $y, $z); return true; } return false; diff --git a/src/world/Level.php b/src/world/Level.php index 3e2a461e..8b02b4d4 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -468,24 +468,18 @@ class Level{ public function updateNeighborsAt($x, $y, $z, $oldID){ $block = $this->level->getBlockID($x - 1, $y, $z); - ConsoleAPI::debug(StaticBlock::getBlock($block)); if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x - 1, $y, $z, $x, $y, $z, $oldID); $block = $this->level->getBlockID($x + 1, $y, $z); - ConsoleAPI::debug(StaticBlock::getBlock($block)); if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x + 1, $y, $z, $x, $y, $z, $oldID); $block = $this->level->getBlockID($x, $y - 1, $z); - ConsoleAPI::debug(StaticBlock::getBlock($block)); if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y - 1, $z, $x, $y, $z, $oldID); $block = $this->level->getBlockID($x, $y + 1, $z); - ConsoleAPI::debug(StaticBlock::getBlock($block)); if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y + 1, $z, $x, $y, $z, $oldID); $block = $this->level->getBlockID($x, $y, $z - 1); - ConsoleAPI::debug(StaticBlock::getBlock($block)); if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y, $z - 1, $x, $y, $z, $oldID); $block = $this->level->getBlockID($x, $y, $z + 1); - ConsoleAPI::debug(StaticBlock::getBlock($block)); if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y, $z + 1, $x, $y, $z, $oldID); }