mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 20:28:31 +00:00
Added Liquid flow
This commit is contained in:
parent
474091c013
commit
48bc919a33
@ -50,8 +50,8 @@ class Lava extends Liquid{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
$ret = $this->getLevel()->setBlock($this, $this, true);
|
$ret = $this->getLevel()->setBlock($this, $this, true, false);
|
||||||
$this->getLevel()->scheduleUpdate(clone $this, 40);
|
$this->getLevel()->scheduleUpdate($this, $this->tickRate());
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
@ -82,8 +82,22 @@ class Liquid extends Transparent{
|
|||||||
|
|
||||||
$decay = $this->getEffectiveFlowDecay($this);
|
$decay = $this->getEffectiveFlowDecay($this);
|
||||||
|
|
||||||
for($side = 2; $side <= 5; ++$side){
|
for($j = 0; $j < 4; ++$j){
|
||||||
$sideBlock = $this->getSide($side);
|
|
||||||
|
$x = $this->x;
|
||||||
|
$y = $this->y;
|
||||||
|
$z = $this->z;
|
||||||
|
|
||||||
|
if($j === 0){
|
||||||
|
--$x;
|
||||||
|
}elseif($j === 1){
|
||||||
|
++$x;
|
||||||
|
}elseif($j === 2){
|
||||||
|
--$z;
|
||||||
|
}elseif($j === 3){
|
||||||
|
++$z;
|
||||||
|
}
|
||||||
|
$sideBlock = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
|
||||||
$blockDecay = $this->getEffectiveFlowDecay($sideBlock);
|
$blockDecay = $this->getEffectiveFlowDecay($sideBlock);
|
||||||
|
|
||||||
if($blockDecay < 0){
|
if($blockDecay < 0){
|
||||||
@ -149,20 +163,22 @@ class Liquid extends Transparent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onUpdate($type){
|
public function onUpdate($type){
|
||||||
if($type === Level::BLOCK_UPDATE_NORMAL or $type === Level::BLOCK_UPDATE_SCHEDULED){
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
|
$this->checkForHarden();
|
||||||
|
$this->getLevel()->scheduleUpdate($this, $this->tickRate());
|
||||||
|
}elseif($type === Level::BLOCK_UPDATE_SCHEDULED){
|
||||||
$decay = $this->getFlowDecay($this);
|
$decay = $this->getFlowDecay($this);
|
||||||
|
$multiplier = $this instanceof Lava ? 2 : 1;
|
||||||
//TODO: If lava and on hell, set this to two
|
|
||||||
$multiplier = 1;
|
|
||||||
|
|
||||||
$flag = true;
|
$flag = true;
|
||||||
|
|
||||||
if($decay > 0){
|
if($decay > 0){
|
||||||
$smallestFlowDecay = -100;
|
$smallestFlowDecay = -100;
|
||||||
$this->adjacentSources = 0;
|
$this->adjacentSources = 0;
|
||||||
for($side = 2; $side <= 5; ++$side){
|
$smallestFlowDecay = $this->getSmallestFlowDecay($this->getSide(4), $smallestFlowDecay);
|
||||||
$smallestFlowDecay = $this->getSmallestFlowDecay($this->getSide($side), $smallestFlowDecay);
|
$smallestFlowDecay = $this->getSmallestFlowDecay($this->getSide(5), $smallestFlowDecay);
|
||||||
}
|
$smallestFlowDecay = $this->getSmallestFlowDecay($this->getSide(2), $smallestFlowDecay);
|
||||||
|
$smallestFlowDecay = $this->getSmallestFlowDecay($this->getSide(3), $smallestFlowDecay);
|
||||||
|
|
||||||
$k = $smallestFlowDecay + $multiplier;
|
$k = $smallestFlowDecay + $multiplier;
|
||||||
|
|
||||||
@ -198,8 +214,10 @@ class Liquid extends Transparent{
|
|||||||
$this->getLevel()->setBlock($this, Block::get(Item::AIR), true);
|
$this->getLevel()->setBlock($this, Block::get(Item::AIR), true);
|
||||||
}else{
|
}else{
|
||||||
$this->getLevel()->setBlock($this, Block::get($this->id, $decay), true);
|
$this->getLevel()->setBlock($this, Block::get($this->id, $decay), true);
|
||||||
|
$this->getLevel()->scheduleUpdate($this, $this->tickRate());
|
||||||
}
|
}
|
||||||
}elseif($flag){
|
}elseif($flag){
|
||||||
|
$this->getLevel()->scheduleUpdate($this, $this->tickRate());
|
||||||
//$this->updateFlow();
|
//$this->updateFlow();
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
@ -208,16 +226,18 @@ class Liquid extends Transparent{
|
|||||||
|
|
||||||
$bottomBlock = $this->getSide(0);
|
$bottomBlock = $this->getSide(0);
|
||||||
|
|
||||||
if($bottomBlock instanceof Liquid){
|
if($bottomBlock->isFlowable or $bottomBlock instanceof Liquid){
|
||||||
if($this instanceof Lava and $bottomBlock instanceof Water){
|
if($this instanceof Lava and $bottomBlock instanceof Water){
|
||||||
$this->getLevel()->setBlock($bottomBlock, Block::get(Item::STONE), true);
|
$this->getLevel()->setBlock($bottomBlock, Block::get(Item::STONE), true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($decay >= 8){
|
if($decay >= 8){
|
||||||
$this->getLevel()->setBlock($bottomBlock, Block::get($this->id, $decay));
|
$this->getLevel()->setBlock($bottomBlock, Block::get($this->id, $decay), true);
|
||||||
|
$this->getLevel()->scheduleUpdate($bottomBlock, $this->tickRate());
|
||||||
}else{
|
}else{
|
||||||
$this->getLevel()->setBlock($bottomBlock, Block::get($this->id, $decay | 0x80));
|
$this->getLevel()->setBlock($bottomBlock, Block::get($this->id, $decay + 8), true);
|
||||||
|
$this->getLevel()->scheduleUpdate($bottomBlock, $this->tickRate());
|
||||||
}
|
}
|
||||||
}elseif($decay >= 0 and ($decay === 0 or !$bottomBlock->isFlowable)){
|
}elseif($decay >= 0 and ($decay === 0 or !$bottomBlock->isFlowable)){
|
||||||
$flags = $this->getOptimalFlowDirections();
|
$flags = $this->getOptimalFlowDirections();
|
||||||
@ -226,27 +246,32 @@ class Liquid extends Transparent{
|
|||||||
|
|
||||||
if($decay >= 8){
|
if($decay >= 8){
|
||||||
$l = 1;
|
$l = 1;
|
||||||
}elseif($l >= 8){
|
}
|
||||||
|
|
||||||
|
if($l >= 8){
|
||||||
|
$this->checkForHarden();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($flags[0]){
|
if($flags[0]){
|
||||||
$this->flowIntoBlock($this->getSide(2), $l);
|
|
||||||
}
|
|
||||||
|
|
||||||
if($flags[1]){
|
|
||||||
$this->flowIntoBlock($this->getSide(3), $l);
|
|
||||||
}
|
|
||||||
|
|
||||||
if($flags[2]){
|
|
||||||
$this->flowIntoBlock($this->getSide(4), $l);
|
$this->flowIntoBlock($this->getSide(4), $l);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($flags[3]){
|
if($flags[1]){
|
||||||
$this->flowIntoBlock($this->getSide(5), $l);
|
$this->flowIntoBlock($this->getSide(5), $l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($flags[2]){
|
||||||
|
$this->flowIntoBlock($this->getSide(2), $l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($flags[3]){
|
||||||
|
$this->flowIntoBlock($this->getSide(3), $l);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->checkForHarden();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,7 +281,8 @@ class Liquid extends Transparent{
|
|||||||
$this->getLevel()->useBreakOn($block);
|
$this->getLevel()->useBreakOn($block);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->getLevel()->setBlock($this, Block::get($this->id, $newFlowDecay), true);
|
$this->getLevel()->setBlock($block, Block::get($this->id, $newFlowDecay), true);
|
||||||
|
$this->getLevel()->scheduleUpdate($block, $this->tickRate());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,7 +296,20 @@ class Liquid extends Transparent{
|
|||||||
($j === 2 and $previousDirection === 3) or
|
($j === 2 and $previousDirection === 3) or
|
||||||
($j === 3 and $previousDirection === 2)
|
($j === 3 and $previousDirection === 2)
|
||||||
){
|
){
|
||||||
$blockSide = $block->getSide($j + 2);
|
$x = $block->x;
|
||||||
|
$y = $block->y;
|
||||||
|
$z = $block->z;
|
||||||
|
|
||||||
|
if($j === 0){
|
||||||
|
--$x;
|
||||||
|
}elseif($j === 1){
|
||||||
|
++$x;
|
||||||
|
}elseif($j === 2){
|
||||||
|
--$z;
|
||||||
|
}elseif($j === 3){
|
||||||
|
++$z;
|
||||||
|
}
|
||||||
|
$blockSide = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
|
||||||
|
|
||||||
if(!$blockSide->isFlowable or ($blockSide instanceof Liquid and $blockSide->getDamage() === 0)){
|
if(!$blockSide->isFlowable or ($blockSide instanceof Liquid and $blockSide->getDamage() === 0)){
|
||||||
continue;
|
continue;
|
||||||
@ -294,17 +333,30 @@ class Liquid extends Transparent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function getOptimalFlowDirections(){
|
private function getOptimalFlowDirections(){
|
||||||
for($side = 2; $side <= 5; ++$side){
|
for($j = 0; $j < 4; ++$j){
|
||||||
$this->flowCost[$side - 2] = 1000;
|
$this->flowCost[$j] = 1000;
|
||||||
|
|
||||||
$block = $this->getSide($side);
|
$x = $this->x;
|
||||||
|
$y = $this->y;
|
||||||
|
$z = $this->z;
|
||||||
|
|
||||||
|
if($j === 0){
|
||||||
|
--$x;
|
||||||
|
}elseif($j === 1){
|
||||||
|
++$x;
|
||||||
|
}elseif($j === 2){
|
||||||
|
--$z;
|
||||||
|
}elseif($j === 3){
|
||||||
|
++$z;
|
||||||
|
}
|
||||||
|
$block = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
|
||||||
|
|
||||||
if(!$block->isFlowable or ($block instanceof Liquid and $block->getDamage() === 0)){
|
if(!$block->isFlowable or ($block instanceof Liquid and $block->getDamage() === 0)){
|
||||||
continue;
|
continue;
|
||||||
}elseif($block->getSide(0)->isFlowable){
|
}elseif($block->getSide(0)->isFlowable){
|
||||||
$this->flowCost[$side - 2] = 0;
|
$this->flowCost[$j] = 0;
|
||||||
}else{
|
}else{
|
||||||
$this->flowCost[$side - 2] = $this->calculateFlowCost($block, 1, $side - 2);
|
$this->flowCost[$j] = $this->calculateFlowCost($block, 1, $j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,9 +380,9 @@ class Liquid extends Transparent{
|
|||||||
|
|
||||||
if($blockDecay < 0){
|
if($blockDecay < 0){
|
||||||
return $decay;
|
return $decay;
|
||||||
}elseif($decay === 0){
|
}elseif($blockDecay === 0){
|
||||||
++$this->adjacentSources;
|
++$this->adjacentSources;
|
||||||
}elseif($blockDecay >= 0){
|
}elseif($blockDecay >= 8){
|
||||||
$blockDecay = 0;
|
$blockDecay = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,6 +390,19 @@ class Liquid extends Transparent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function checkForHarden(){
|
private function checkForHarden(){
|
||||||
//TODO
|
if($this instanceof Lava){
|
||||||
|
$colliding = false;
|
||||||
|
for($side = 0; $side <= 5 and !$colliding; ++$side){
|
||||||
|
$colliding = $this->getSide($side) instanceof Water;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($colliding){
|
||||||
|
if($this->getDamage() === 0){
|
||||||
|
$this->getLevel()->setBlock($this, Block::get(Item::OBSIDIAN), true);
|
||||||
|
}elseif($this->getDamage() <= 4){
|
||||||
|
$this->getLevel()->setBlock($this, Block::get(Item::COBBLESTONE), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -44,8 +44,8 @@ class Water extends Liquid{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
$ret = $this->getLevel()->setBlock($this, $this, true);
|
$ret = $this->getLevel()->setBlock($this, $this, true, false);
|
||||||
$this->getLevel()->scheduleUpdate(clone $this, 10);
|
$this->getLevel()->scheduleUpdate($this, $this->tickRate());
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
@ -49,8 +49,7 @@ class Bucket extends Item{
|
|||||||
}elseif($this->meta === Item::WATER){
|
}elseif($this->meta === Item::WATER){
|
||||||
//Support Make Non-Support Water to Support Water
|
//Support Make Non-Support Water to Support Water
|
||||||
if($block->getID() === self::AIR || ($block instanceof Water && ($block->getDamage() & 0x07) != 0x00)){
|
if($block->getID() === self::AIR || ($block instanceof Water && ($block->getDamage() & 0x07) != 0x00)){
|
||||||
$water = new Water();
|
$water = Block::get(Item::WATER, 0, $block);
|
||||||
$level->setBlock($block, $water, true);
|
|
||||||
$water->place(clone $this, $block, $target, $face, $fx, $fy, $fz, $player);
|
$water->place(clone $this, $block, $target, $face, $fx, $fy, $fz, $player);
|
||||||
if(($player->gamemode & 0x01) === 0){
|
if(($player->gamemode & 0x01) === 0){
|
||||||
$this->meta = 0;
|
$this->meta = 0;
|
||||||
@ -59,8 +58,9 @@ class Bucket extends Item{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}elseif($this->meta === Item::LAVA){
|
}elseif($this->meta === Item::LAVA){
|
||||||
|
$lava = Block::get(Item::LAVA, 0, $block);
|
||||||
|
$lava->place(clone $this, $block, $target, $face, $fx, $fy, $fz, $player);
|
||||||
if($block->getID() === self::AIR){
|
if($block->getID() === self::AIR){
|
||||||
$level->setBlock($block, new Lava(), true);
|
|
||||||
if(($player->gamemode & 0x01) === 0){
|
if(($player->gamemode & 0x01) === 0){
|
||||||
$this->meta = 0;
|
$this->meta = 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user