From 77ca6da14cc804e7b85e4720134d6f19282927a5 Mon Sep 17 00:00:00 2001 From: "beN39sGroup (Blue Electric)" Date: Sun, 10 Nov 2013 17:19:50 +0900 Subject: [PATCH] Simple Flowable Water! Meet the 'Flowing' Water. --- src/material/block/liquid/Water.php | 107 ++++++++++++++++++++++++++- src/material/item/generic/Bucket.php | 9 ++- src/pmf/Level.php | 6 ++ src/world/Level.php | 1 + 4 files changed, 116 insertions(+), 7 deletions(-) diff --git a/src/material/block/liquid/Water.php b/src/material/block/liquid/Water.php index 2faacf2bb..aa76230d3 100644 --- a/src/material/block/liquid/Water.php +++ b/src/material/block/liquid/Water.php @@ -23,16 +23,52 @@ class WaterBlock extends LiquidBlock{ 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); ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 10, 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 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 function onUpdate($type){ - return false; + //return false; $newId = $this->id; $level = $this->meta & 0x07; if($type !== BLOCK_UPDATE_NORMAL){ @@ -42,6 +78,68 @@ class WaterBlock extends LiquidBlock{ $falling = $this->meta >> 3; $down = $this->getSide(0); + $from = $this->getFrom(); + //출처가 있거나 이 자체가 출처이면 + if($from !== null || $level == 0x00) + { + if($level !== 0x07) + { + if($down instanceof AirBlock || $down instanceof WaterBlock) + { + $this->level->setBlock($down, new WaterBlock(0x01), false, false, true); + ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); + } + else + { + for($side = 2; $side <= 5; ++$side) + { + $b = $this->getSide($side); + if($b instanceof WaterBlock) + { + if( $this->getSourceCount() >= 2) + { + $this->level->setBlock($this, new WaterBlock(0), false, false, true); + } + } + else if($b->isFlowable === true) + { + $this->level->setBlock($b, new WaterBlock($level + 1), false, false, true); + ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, 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) + { + $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) + { + $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); + } + + /* if($falling === 0){ $countSources = 0; $maxLevel = $level; @@ -86,7 +184,7 @@ class WaterBlock extends LiquidBlock{ } } } - + if($down->isFlowable){ $this->level->setBlock($down, new WaterBlock(0b1001), false, false, true); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL); @@ -108,6 +206,7 @@ class WaterBlock extends LiquidBlock{ ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); return false; } + */ return false; } } \ No newline at end of file diff --git a/src/material/item/generic/Bucket.php b/src/material/item/generic/Bucket.php index 40fc11e87..d011f9ee2 100644 --- a/src/material/item/generic/Bucket.php +++ b/src/material/item/generic/Bucket.php @@ -36,8 +36,11 @@ class BucketItem extends Item{ return true; } }elseif($this->meta === WATER){ - if($block->getID() === AIR){ - $level->setBlock($block, new StillWaterBlock(), true, false, true); + //Support Make Non-Support Water to Support Water + if($block->getID() === AIR || ( $block instanceof WaterBlock && ($block->getMetadata() & 0x07) != 0x00 ) ){ + $water = new WaterBlock(); + $level->setBlock($block, $water, true, false, true); + $water->place(clone $this, $player, $block, $target, $face, $fx, $fy, $fz); if(($player->gamemode & 0x01) === 0){ $this->meta = 0; } @@ -45,7 +48,7 @@ class BucketItem extends Item{ } }elseif($this->meta === LAVA){ if($block->getID() === AIR){ - $level->setBlock($block, new StillLavaBlock(), true, false, true); + $level->setBlock($block, new LavaBlock(), true, false, true); if(($player->gamemode & 0x01) === 0){ $this->meta = 0; } diff --git a/src/pmf/Level.php b/src/pmf/Level.php index 5870085d8..73091db12 100644 --- a/src/pmf/Level.php +++ b/src/pmf/Level.php @@ -469,6 +469,12 @@ class PMFLevel extends PMF{ ++$this->chunkChange[$index][$Y]; } $this->chunkChange[$index][-1] = true; + $pos = new Position($x, $y, $z, $this->level); + for($side = 0; $side <= 5; ++$side) + { + $b = $pos->getSide($side); + ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); + } return true; } return false; diff --git a/src/world/Level.php b/src/world/Level.php index 497ce8b86..396668e43 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -26,6 +26,7 @@ class Level{ public function __construct(PMFLevel $level, Config $entities, Config $tiles, Config $blockUpdates, $name){ $this->server = ServerAPI::request(); $this->level = $level; + $this->level->level = $this; $this->entities = $entities; $this->tiles = $tiles; $this->blockUpdates = $blockUpdates;