diff --git a/src/material/block/LiquidBlock.php b/src/material/block/LiquidBlock.php index 2cfa7f72..8aeb010f 100644 --- a/src/material/block/LiquidBlock.php +++ b/src/material/block/LiquidBlock.php @@ -24,6 +24,39 @@ class LiquidBlock extends TransparentBlock{ return $f; } + public static function getTickDelay(){ + throw new RuntimeException("If you see this, something bad happened"); + } + + public static function updateLiquid(Level $level, $x, $y, $z){ + [$id, $meta] = $level->level->getBlock($x, $y, $z); + if($id != LAVA && $id != STILL_LAVA) continue; + + $zNeg = $level->level->getBlockID($x, $y, $z - 1); + $zPos = $level->level->getBlockID($x, $y, $z + 1); + $xNeg = $level->level->getBlockID($x - 1, $y, $z); + $xPos = $level->level->getBlockID($x + 1, $y, $z); + $yPos = $level->level->getBlockID($x, $y + 1, $z); + + if( + $zNeg == WATER || $zNeg == STILL_WATER + || $zPos == WATER || $zPos == STILL_WATER + || $xNeg == WATER || $xNeg == STILL_WATER + || $xPos == WATER || $xPos == STILL_WATER + || $yPos == WATER || $yPos == STILL_WATER + ) { + if($meta){ + //if($meta > 4) -> fizz & ret + $replacement = COBBLESTONE; + }else{ + $replacement = OBSIDIAN; + } + + $level->fastSetBlockUpdate($x, $y, $z, $replacement, true); + } + } + + public function getDrops(Item $item, Player $player){ return array(); } diff --git a/src/material/block/liquid/LavaBlock.php b/src/material/block/liquid/LavaBlock.php index 9e2506c2..7a6b7cdd 100644 --- a/src/material/block/liquid/LavaBlock.php +++ b/src/material/block/liquid/LavaBlock.php @@ -1,6 +1,6 @@ hardness = 500; @@ -8,123 +8,15 @@ class LavaBlock extends LiquidBlock implements LightingBlock{ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $ret = $this->level->setBlock($this, $this, true, false, true); - ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 40, BLOCK_UPDATE_NORMAL); + //TODO place ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 40, BLOCK_UPDATE_NORMAL); return $ret; } + public static function getTickDelay(){ + return 30; + } + public function getMaxLightValue(){ return 15; } - - public function getSourceCount(){ - $count = 0; - for($side = 2; $side <= 5; ++$side){ - if($this->getSide($side) instanceof LavaBlock ){ - $b = $this->getSide($side); - $level = $b->meta & 0x06; - if($level == 0x00){ - $count++; - } - } - } - return $count; - } - - public function checkWater(){ - for($side = 0; $side <= 5; ++$side){ - $b = $this->getSide($side); - if($b instanceof WaterBlock){ - $level = $this->meta & 0x07; - if($level == 0x00){ - $this->level->setBlock($b, new ObsidianBlock(), false, false, true); - }else{ - $this->level->setBlock($b, new CobblestoneBlock(), false, false, true); - } - } - } - } - - public function getFrom(){ - for($side = 0; $side <= 5; ++$side){ - $b = $this->getSide($side); - if($b instanceof LavaBlock){ - $tlevel = $b->meta & 0x06; - $level = $this->meta & 0x06; - if( ($tlevel + 2) == $level || ($side == 0x01 && $level == 0x01 ) || ($tlevel == 6 && $level == 6 )){ - return $b; - } - } - } - return null; - } - - public static function onUpdate(Level $level, $x, $y, $z, $type){ - //TODO rewrite - return false; - //return false; -// $newId = $this->id; -// $level = $this->meta & 0x06; -// if($type !== BLOCK_UPDATE_NORMAL){ -// return false; -// } - -// /*if($this->checkWater()){ -// return; -// }*/ -// $falling = $this->meta >> 3; -// $down = $this->getSide(0); -// if($down instanceof WaterBlock) { -// $this->level->fastSetBlockUpdate($down->x, $down->y, $down->z, STONE, 0, true); -// return; -// } - -// $from = $this->getFrom(); -// if($from !== null || $level == 0x00){ -// if($down instanceof AirBlock || $down instanceof LavaBlock){ -// $this->level->setBlock($down, new LavaBlock(0x01), false, false, true); -// ServerAPI::request()->api->block->scheduleBlockUpdate($down, 40, BLOCK_UPDATE_NORMAL); -// }elseif($level !== 0x06){ -// for($side = 2; $side <= 5; ++$side){ -// $b = $this->getSide($side); -// if($b instanceof LavaBlock){ - -// }elseif($b->isFlowable === true){ -// $this->level->setBlock($b, new LavaBlock( min($level + 2,6) ), false, false, true); -// ServerAPI::request()->api->block->scheduleBlockUpdate($b, 40, BLOCK_UPDATE_NORMAL); -// } -// } -// } -// }else{ -// //Extend Remove for Left Lavas -// for($side = 2; $side <= 5; ++$side){ -// $sb = $this->getSide($side); -// if($sb instanceof LavaBlock){ -// $tlevel = $sb->meta & 0x06; -// if($tlevel != 0x00){ -// for ($s = 0; $s <= 5; $s++) { -// $ssb = $sb->getSide($s); -// ServerAPI::request()->api->block->scheduleBlockUpdate($ssb, 40, BLOCK_UPDATE_NORMAL); -// } -// $this->level->setBlock($sb, new AirBlock(), false, false, true); -// } -// } -// $b = $this->getSide(0)->getSide($side); -// if($b instanceof LavaBlock){ -// $tlevel = $b->meta & 0x06; -// if($tlevel != 0x00){ -// for ($s = 0; $s <= 5; $s++) { -// $ssb = $sb->getSide($s); -// ServerAPI::request()->api->block->scheduleBlockUpdate($ssb, 40, BLOCK_UPDATE_NORMAL); -// } -// $this->level->setBlock($b, new AirBlock(), false, false, true); -// } -// } -// //ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); -// } - -// $this->level->setBlock($this, new AirBlock(), false, false, true); -// } -// return false; - } - } diff --git a/src/material/block/liquid/LiquidBlockDynamic.php b/src/material/block/liquid/LiquidBlockDynamic.php new file mode 100644 index 00000000..085e6ccb --- /dev/null +++ b/src/material/block/liquid/LiquidBlockDynamic.php @@ -0,0 +1,7 @@ +level->getBlock($x, $y, $z); + $dynamicID =$id - 1; //very unsafe + $level->fastSetBlockUpdate($x, $y, $z, $dynamicID, $meta); + $delay = static::getTickDelay(); + ServerAPI::request()->api->block->blockUpdateAroundXYZ($x, $y, $z, BLOCK_UPDATE_SCHEDULED, $delay); + } + + 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); + $newID = $level->level->getBlockID($x, $y, $z); + if($oldID == $newID){ + static::setDynamic($level, $x, $y, $z); + } + } + + +} \ No newline at end of file diff --git a/src/material/block/liquid/StillLavaBlock.php b/src/material/block/liquid/StillLavaBlock.php index ea82e135..a0388e82 100644 --- a/src/material/block/liquid/StillLavaBlock.php +++ b/src/material/block/liquid/StillLavaBlock.php @@ -1,9 +1,13 @@ hardness = 500; } + public static function getTickDelay(){ + return 30; + } + } \ No newline at end of file diff --git a/src/material/block/liquid/StillWaterBlock.php b/src/material/block/liquid/StillWaterBlock.php index 67ae7ab1..d6fd7f64 100644 --- a/src/material/block/liquid/StillWaterBlock.php +++ b/src/material/block/liquid/StillWaterBlock.php @@ -5,10 +5,13 @@ require_once("WaterBlock.php"); //TODO class loader? /***REM_END***/ -class StillWaterBlock extends WaterBlock{ +class StillWaterBlock extends LiquidBlockStatic{ public function __construct($meta = 0){ LiquidBlock::__construct(STILL_WATER, $meta, "Still Water"); $this->hardness = 500; } + public static function getTickDelay(){ + return 5; + } } \ No newline at end of file diff --git a/src/material/block/liquid/WaterBlock.php b/src/material/block/liquid/WaterBlock.php index 201ad48f..555b783c 100644 --- a/src/material/block/liquid/WaterBlock.php +++ b/src/material/block/liquid/WaterBlock.php @@ -1,6 +1,6 @@ hardness = 500; @@ -8,116 +8,15 @@ class WaterBlock extends LiquidBlock{ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $ret = $this->level->setBlock($this, $this, true, false, true); - ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 5, BLOCK_UPDATE_NORMAL); + //TODO place ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 5, BLOCK_UPDATE_NORMAL); return $ret; } - public function getSourceCount(){ - $count = 0; - for($side = 2; $side <= 5; ++$side){ - if( $this->getSide($side) instanceof WaterBlock ){ - $b = $this->getSide($side); - $level = $b->meta & 0x07; - if($level == 0x00){ - $count++; - } - } - } - return $count; - } - - public function checkLava(){ - $ret = false; - for($side = 0; $side <= 5; ++$side){ - if($side == 1){ - continue; - } - $b = $this->getSide($side); - if($b instanceof LavaBlock){ - $level = $b->meta & 0x07; - if($level == 0x00){ - $this->level->setBlock($b, new ObsidianBlock(), false, false, true); - }else{ - $this->level->setBlock($b, new CobblestoneBlock(), false, false, true); - } - $ret = true; - } - } - return $ret; - } - - public function getFrom(){ - for($side = 0; $side <= 5; ++$side){ - $b = $this->getSide($side); - if($b instanceof WaterBlock){ - $tlevel = $b->meta & 0x07; - $level = $this->meta & 0x07; - if( ($tlevel + 1) == $level || ($side == 0x01 && $level == 0x01 )){ - return $b; - } - } - } - return null; + public static function getTickDelay(){ + return 5; } public static function onUpdate(Level $level, $x, $y, $z, $type){ - //TODO rewrite - return false; - /*$newId = $this->id; - $level = $this->meta & 0x07; - - if($type !== BLOCK_UPDATE_NORMAL){ - return false; - } - - $this->checkLava(); - - $falling = $this->meta >> 3; - $down = $this->getSide(0); - - $from = $this->getFrom(); - //Has Source or Its Source - if($from !== null || $level == 0x00){ - if($down instanceof AirBlock || $down instanceof WaterBlock){ - $this->level->setBlock($down, new WaterBlock(1), false, false, true); //TODO fix somehow - ServerAPI::request()->api->block->scheduleBlockUpdate($down, 5, BLOCK_UPDATE_NORMAL); - }elseif($level !== 0x07){{ - for($side = 2; $side <= 5; ++$side){ - $b = $this->getSide($side); - if($b instanceof WaterBlock){ - if($this->getSourceCount() >= 2 && $level != 0x00){ //Infinite water source - $this->level->setBlock($this, new WaterBlock(0), false, false, true); - } - }elseif($b->isFlowable === true){ - $this->level->setBlock($b, new WaterBlock($level + 1), false, false, true); - ServerAPI::request()->api->block->scheduleBlockUpdate($b, 5, BLOCK_UPDATE_NORMAL); - } - } - } - } - }else{ - //Extend Remove for Left Waters - for($side = 2; $side <= 5; ++$side){ - $sb = $this->getSide($side); - if($sb instanceof WaterBlock){ - $tlevel = $sb->meta & 0x07; - if($tlevel != 0x00){ - ServerAPI::request()->api->block->blockUpdateAround($sb, BLOCK_UPDATE_NORMAL, 5); - $this->level->setBlock($sb, new AirBlock(), false, false, true); - } - } - $b = $this->getSide(0)->getSide($side); - if($b instanceof WaterBlock){ - $tlevel = $b->meta & 0x07; - if($tlevel != 0x00){ - ServerAPI::request()->api->block->blockUpdateAround($b, BLOCK_UPDATE_NORMAL, 5); - $this->level->setBlock($b, new AirBlock(), false, false, true); - } - } - } - ServerAPI::request()->api->block->blockUpdateAround($this, BLOCK_UPDATE_NORMAL, 5); - $this->level->setBlock($this, new AirBlock(), false, false, true); - } - return false;*/ + } }