mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
vanilla(or close to vanila) liquid physics
This commit is contained in:
parent
589bc9f1c0
commit
9c21a984cd
5 changed files with 12 additions and 26 deletions
|
|
@ -569,18 +569,15 @@ class BlockAPI{
|
|||
}
|
||||
public function scheduleBlockUpdateXYZ(Level $level, $x, $y, $z, $type = BLOCK_UPDATE_SCHEDULED, $delay = false){
|
||||
$type = (int) $type;
|
||||
ConsoleAPI::debug($delay);
|
||||
if($delay < 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
$index = $x . "." . $y . "." . $z . "." . $level->getName() . "." . $type;
|
||||
$delay = microtime(true) + $delay * 0.05;
|
||||
ConsoleAPI::debug($index);
|
||||
if(!isset($this->scheduledUpdates[$index])){
|
||||
$this->scheduledUpdates[$index] = new Position($x, $y, $z, $level); //TODO dont create a position
|
||||
$this->server->query("INSERT INTO blockUpdates (x, y, z, level, type, delay) VALUES ($x, $y, $z, '{$level->getName()}', $type, $delay);");
|
||||
ConsoleAPI::debug("added block update $x $y $z $type");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -70,7 +70,6 @@ class LiquidBlockDynamic extends LiquidBlock{
|
|||
|
||||
if(static::isWaterBlocking($level, $xs, $ys, $zs)) continue;
|
||||
[$id, $meta] = $level->level->getBlock($xs, $ys, $zs);
|
||||
|
||||
if(((static::$blockID == WATER && ($id == WATER || $id == STILL_WATER)) || (static::$blockID == LAVA && ($id == LAVA || $id == STILL_LAVA))) && $meta == 0){
|
||||
continue;
|
||||
}
|
||||
|
|
@ -78,8 +77,10 @@ class LiquidBlockDynamic extends LiquidBlock{
|
|||
if(!static::isWaterBlocking($level, $xs, $ys - 1, $zs)) static::$spread[$i] = 0;
|
||||
else static::$spread[$i] = static::getSlopeDistance($level, $xs, $ys, $zs, 1, $i);
|
||||
}
|
||||
|
||||
$i1 = max(static::$spread);
|
||||
$i1 = static::$spread[0];
|
||||
for($k1 = 1; $k1 < 4; ++$k1){
|
||||
if(static::$spread[$k1] < $i1) $i1 = static::$spread[$k1];
|
||||
}
|
||||
$ba = [];
|
||||
for($i = 0; $i < 4; ++$i) $ba[$i] = ($i1 == static::$spread[$i]);
|
||||
return $ba;
|
||||
|
|
@ -164,7 +165,6 @@ class LiquidBlockDynamic extends LiquidBlock{
|
|||
$highest = static::getHighest($level, $x + 1, $y, $z, $highest);
|
||||
$highest = static::getHighest($level, $x, $y, $z - 1, $highest);
|
||||
$highest = static::getHighest($level, $x, $y, $z + 1, $highest);
|
||||
ConsoleAPI::debug("h".$highest);
|
||||
$j1 = $highest + $flowAdd;
|
||||
if($j1 >= 8 || $highest < 0) $j1 = -1;
|
||||
$l1 = static::getDepth($level, $x, $y + 1, $z);
|
||||
|
|
@ -204,10 +204,10 @@ class LiquidBlockDynamic extends LiquidBlock{
|
|||
$k1 = $depth >= 8 ? 1 : ($depth + $flowAdd);
|
||||
if($k1 >= 8) return;
|
||||
//TODO flags are broken, no flags makes too much of the liquid
|
||||
/*if($flags[0])*/ static::trySpreadTo($level, $x - 1, $y, $z, $k1);
|
||||
/*if($flags[1])*/ static::trySpreadTo($level, $x + 1, $y, $z, $k1);
|
||||
/*if($flags[2])*/ static::trySpreadTo($level, $x, $y, $z - 1, $k1);
|
||||
/*if($flags[3])*/ static::trySpreadTo($level, $x, $y, $z + 1, $k1);
|
||||
if($flags[0]) static::trySpreadTo($level, $x - 1, $y, $z, $k1);
|
||||
if($flags[1]) static::trySpreadTo($level, $x + 1, $y, $z, $k1);
|
||||
if($flags[2]) static::trySpreadTo($level, $x, $y, $z - 1, $k1);
|
||||
if($flags[3]) static::trySpreadTo($level, $x, $y, $z + 1, $k1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -21,7 +21,6 @@ class LiquidBlockStatic extends LiquidBlock{
|
|||
$oldID = $level->level->getBlockID($x, $y, $z);
|
||||
static::updateLiquid($level, $x, $y, $z);
|
||||
$newID = $level->level->getBlockID($x, $y, $z);
|
||||
ConsoleAPI::debug($oldID.":".$newID);
|
||||
if($oldID == $newID){
|
||||
static::setDynamic($level, $x, $y, $z);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class BucketItem extends Item{
|
|||
|
||||
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
if($this->meta === AIR){
|
||||
if($target instanceof LiquidBlock){
|
||||
if($block instanceof LiquidBlock){
|
||||
$level->setBlock($target, new AirBlock(), true, false, true);
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$this->meta = ($target instanceof WaterBlock) ? WATER : LAVA;
|
||||
|
|
@ -24,11 +24,9 @@ class BucketItem extends Item{
|
|||
return true;
|
||||
}
|
||||
}elseif($this->meta === WATER){
|
||||
//Support Make Non-Support Water to Support Water
|
||||
if($block->getID() === AIR || ( $block instanceof WaterBlock && ($block->getMetadata() & 0x07) != 0x00 ) || ($block instanceof LavaBlock)){
|
||||
if($block->getID() === AIR || $block instanceof LiquidBlock){
|
||||
$water = new WaterBlock();
|
||||
$level->setBlock($block, $water, true, false, true);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate($block, 5, BLOCK_UPDATE_NORMAL);
|
||||
//$water->place($this, $player, $block, $target, $face, $fx, $fy, $fz);
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$this->meta = 0;
|
||||
|
|
@ -36,21 +34,14 @@ class BucketItem extends Item{
|
|||
return true;
|
||||
}
|
||||
}elseif($this->meta === LAVA){
|
||||
if($block->getID() === AIR || ($block instanceof LavaBlock && ($block->getMetadata() & 0x6) != 0)){
|
||||
if($block->getID() === AIR || $block instanceof LiquidBlock){
|
||||
$lava = new LavaBlock();
|
||||
$level->setBlock($block, $lava, true, false, true);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate($block, 40, BLOCK_UPDATE_NORMAL);
|
||||
//$lava->place(clone $this, $player, $block, $target, $face, $fx, $fy, $fz);
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$this->meta = 0;
|
||||
}
|
||||
return true;
|
||||
}elseif($block instanceof WaterBlock){
|
||||
$level->setBlock($block, new ObsidianBlock(), true, false, true);
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$this->meta = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ class Explosion{
|
|||
$index = ($vBlock->x << 16) + ($vBlock->z << 8) + $vBlock->y;
|
||||
|
||||
if(StaticBlock::getIsLiquid($blockID) && !isset($visited[$index])){
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($vBlock->x, $vBlock->y, $vBlock->z, $this->level), 5, BLOCK_UPDATE_NORMAL);
|
||||
$visited[$index] = true;
|
||||
}
|
||||
|
||||
|
|
@ -202,7 +201,7 @@ class Explosion{
|
|||
}
|
||||
}
|
||||
}
|
||||
$this->level->fastSetBlockUpdate($x, $y, $z, 0, 0);
|
||||
$this->level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
|
||||
$send[] = $xyz;
|
||||
}
|
||||
$pk = new ExplodePacket;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue