Merge pull request #920 from beN39sGroup/master

Liquid Flowing. This requires further testing before stable release.
This commit is contained in:
Michael Yoo 2013-11-12 21:48:02 -08:00
commit d4a5e4e5c4
6 changed files with 264 additions and 64 deletions

View File

@ -25,4 +25,139 @@ class LavaBlock extends LiquidBlock{
$this->hardness = 0; $this->hardness = 0;
} }
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);
return $ret;
}
public function getSourceCount()
{
$count = 0;
for($side = 2; $side <= 5; ++$side)
{
if( $this->getSide($side) instanceof LavaBlock )
{
$b = $this->getSide($side);
$level = $b->meta & 0x07;
if($level == 0x00)
{
$count++;
}
}
}
return $count;
}
public function checkWater()
{
for($side = 1; $side <= 5; ++$side)
{
$b = $this->getSide($side);
if($b instanceof WaterBlock)
{
$level = $this->meta & 0x07;
if($level == 0x00)
{
$this->level->setBlock($this, new ObsidianBlock(), false, false, true);
}
else
{
$this->level->setBlock($this, 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 & 0x07;
$level = $this->meta & 0x07;
if( ($tlevel + 2) == $level || ($side == 0x01 && $level == 0x01 ) || ($tlevel == 6 && $level == 7 ))
{
return $b;
}
}
}
return null;
}
public function onUpdate($type){
//return false;
$newId = $this->id;
$level = $this->meta & 0x07;
if($type !== BLOCK_UPDATE_NORMAL){
return false;
}
if( $this->checkWater() ) { return; }
$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 LavaBlock)
{
$this->level->setBlock($down, new LavaBlock(0x01), false, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
}
else
{
for($side = 2; $side <= 5; ++$side)
{
$b = $this->getSide($side);
if($b instanceof LavaBlock)
{
}
else if($b->isFlowable === true)
{
$this->level->setBlock($b, new LavaBlock( min($level + 2,7) ), false, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 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 & 0x07;
if($tlevel != 0x00)
{
$this->level->setBlock($sb, new AirBlock(), false, false, true);
}
}
$b = $this->getSide(0)->getSide($side);
if($b instanceof LavaBlock)
{
$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);
}
return false;
}
} }

View File

@ -23,90 +23,144 @@ class WaterBlock extends LiquidBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(WATER, $meta, "Water"); parent::__construct(WATER, $meta, "Water");
$this->hardness = 500; $this->hardness = 500;
} }
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$ret = $this->level->setBlock($this, $this, true, false, true); $ret = $this->level->setBlock($this, $this, true, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 10, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 10, BLOCK_UPDATE_NORMAL);
return $ret; return $ret;
} }
public function onUpdate($type){ 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()
{
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);
}
return true;
}
}
return false; return false;
}
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;
$newId = $this->id; $newId = $this->id;
$level = $this->meta & 0x07; $level = $this->meta & 0x07;
if($type !== BLOCK_UPDATE_NORMAL){ if($type !== BLOCK_UPDATE_NORMAL){
return false; return false;
} }
$this->checkLava();
$falling = $this->meta >> 3; $falling = $this->meta >> 3;
$down = $this->getSide(0); $down = $this->getSide(0);
if($falling === 0){ $from = $this->getFrom();
$countSources = 0; //Has Source or Its Source
$maxLevel = $level; if($from !== null || $level == 0x00)
$hasPath = false; {
for($side = 2; $side <= 5; ++$side){ if($level !== 0x07)
$b = $this->getSide($side); {
if($b->isFlowable === true and $level < 0x07){ if($down instanceof AirBlock || $down instanceof WaterBlock)
$d = $b->getSide(0); {
$this->level->setBlock($b, new WaterBlock($level + 1), false, false, true); $this->level->setBlock($down, new WaterBlock(0x01), false, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL);
}elseif($b instanceof WaterBlock){ }
$oLevel = $b->getMetadata(); else
$oFalling = $oLevel >> 3; {
$oLevel &= 0x07; for($side = 2; $side <= 5; ++$side)
if($oFalling === 0){ {
if($oLevel === 0){ $b = $this->getSide($side);
++$countSources; if($b instanceof WaterBlock)
$maxLevel = 1; {
$hasPath = true; if( $this->getSourceCount() >= 2)
}elseif($oLevel < 0x07 and ($oLevel + 1) <= $maxLevel){ {
$maxLevel = $oLevel + 1; $this->level->setBlock($this, new WaterBlock(0), false, false, true);
$hasPath = true; }
}elseif(($level + 1) < $oLevel){ }
else if($b->isFlowable === true)
{
$this->level->setBlock($b, new WaterBlock($level + 1), false, false, 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); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL);
}elseif($level === $oLevel){
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL);
} }
} }
} }
} }
if($countSources >= 2){ }
$level = 0; //Source block else
}elseif($maxLevel < $level){ {
$level = $maxLevel; //Extend Remove for Left Waters
}elseif($maxLevel === $level and $level > 0 and $hasPath === false){ for($side = 2; $side <= 5; ++$side)
if($level < 0x07){ {
++$level; $sb = $this->getSide($side);
}else{ if($sb instanceof WaterBlock)
$newId = AIR; {
$level = 0; $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($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);
return false;
}elseif($down instanceof LiquidBlock){
if($down instanceof WaterBlock and ($down->getMetadata() >> 3) === 0){
$this->level->setBlock($down, new WaterBlock(0b1000 & min($down->getMetadata(), 1)), false, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL);
}
}else{
$falling = 0;
}
$newMeta = ($falling << 0x03) | $level;
if($newMeta !== $this->meta or $newId !== $this->id){
$this->id = $newId;
$this->meta = $newMeta;
$this->level->setBlock($this, $this, false, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL);
return false;
} }
return false; return false;
} }

View File

@ -36,8 +36,11 @@ class BucketItem extends Item{
return true; return true;
} }
}elseif($this->meta === WATER){ }elseif($this->meta === WATER){
if($block->getID() === AIR){ //Support Make Non-Support Water to Support Water
$level->setBlock($block, new StillWaterBlock(), true, false, true); 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){ if(($player->gamemode & 0x01) === 0){
$this->meta = 0; $this->meta = 0;
} }
@ -45,7 +48,7 @@ class BucketItem extends Item{
} }
}elseif($this->meta === LAVA){ }elseif($this->meta === LAVA){
if($block->getID() === AIR){ 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){ if(($player->gamemode & 0x01) === 0){
$this->meta = 0; $this->meta = 0;
} }

View File

@ -469,6 +469,12 @@ class PMFLevel extends PMF{
++$this->chunkChange[$index][$Y]; ++$this->chunkChange[$index][$Y];
} }
$this->chunkChange[$index][-1] = true; $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 true;
} }
return false; return false;

View File

@ -410,7 +410,8 @@ class Entity extends Position{
if($this->isStatic === false){ if($this->isStatic === false){
$startX = floor($this->x - 0.5 - $this->size - 1); $startX = floor($this->x - 0.5 - $this->size - 1);
$y = (int) round($this->y - 1); //prefix for flying when player on fence
$y = (int) floor($this->y - 1);
$startZ = floor($this->z - 0.5 - $this->size - 1); $startZ = floor($this->z - 0.5 - $this->size - 1);
$endX = ceil($this->x - 0.5 + $this->size + 1); $endX = ceil($this->x - 0.5 + $this->size + 1);
$endZ = ceil($this->z - 0.5 + $this->size + 1); $endZ = ceil($this->z - 0.5 + $this->size + 1);

View File

@ -26,6 +26,7 @@ class Level{
public function __construct(PMFLevel $level, Config $entities, Config $tiles, Config $blockUpdates, $name){ public function __construct(PMFLevel $level, Config $entities, Config $tiles, Config $blockUpdates, $name){
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
$this->level = $level; $this->level = $level;
$this->level->level = $this;
$this->entities = $entities; $this->entities = $entities;
$this->tiles = $tiles; $this->tiles = $tiles;
$this->blockUpdates = $blockUpdates; $this->blockUpdates = $blockUpdates;