mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 12:09:43 +00:00
begin reimplementing liquids
This commit is contained in:
parent
2ebc482e3d
commit
2f2c053255
7 changed files with 89 additions and 222 deletions
|
|
@ -24,6 +24,39 @@ class LiquidBlock extends TransparentBlock{
|
||||||
return $f;
|
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){
|
public function getDrops(Item $item, Player $player){
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class LavaBlock extends LiquidBlock implements LightingBlock{
|
class LavaBlock extends LiquidBlockDynamic implements LightingBlock{
|
||||||
public function __construct($meta = 0){
|
public function __construct($meta = 0){
|
||||||
parent::__construct(LAVA, $meta, "Lava");
|
parent::__construct(LAVA, $meta, "Lava");
|
||||||
$this->hardness = 500;
|
$this->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){
|
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, 40, BLOCK_UPDATE_NORMAL);
|
//TODO place ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 40, BLOCK_UPDATE_NORMAL);
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getTickDelay(){
|
||||||
|
return 30;
|
||||||
|
}
|
||||||
|
|
||||||
public function getMaxLightValue(){
|
public function getMaxLightValue(){
|
||||||
return 15;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
7
src/material/block/liquid/LiquidBlockDynamic.php
Normal file
7
src/material/block/liquid/LiquidBlockDynamic.php
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class LiquidBlockDynamic extends LiquidBlock{
|
||||||
|
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||||
|
parent::__construct($id, $meta, $name);
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/material/block/liquid/LiquidBlockStatic.php
Normal file
29
src/material/block/liquid/LiquidBlockStatic.php
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class LiquidBlockStatic extends LiquidBlock{
|
||||||
|
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||||
|
parent::__construct($id, $meta, $name);
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: tick: try spread fire if lava
|
||||||
|
|
||||||
|
public static function setDynamic(Level $level, $x, $y, $z){
|
||||||
|
//TODO set dynamic
|
||||||
|
[$id, $meta] = $level->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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class StillLavaBlock extends LiquidBlock{
|
class StillLavaBlock extends LiquidBlockStatic{
|
||||||
public function __construct($meta = 0){
|
public function __construct($meta = 0){
|
||||||
parent::__construct(STILL_LAVA, $meta, "Still Lava");
|
parent::__construct(STILL_LAVA, $meta, "Still Lava");
|
||||||
$this->hardness = 500;
|
$this->hardness = 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getTickDelay(){
|
||||||
|
return 30;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -5,10 +5,13 @@
|
||||||
require_once("WaterBlock.php"); //TODO class loader?
|
require_once("WaterBlock.php"); //TODO class loader?
|
||||||
/***REM_END***/
|
/***REM_END***/
|
||||||
|
|
||||||
class StillWaterBlock extends WaterBlock{
|
class StillWaterBlock extends LiquidBlockStatic{
|
||||||
public function __construct($meta = 0){
|
public function __construct($meta = 0){
|
||||||
LiquidBlock::__construct(STILL_WATER, $meta, "Still Water");
|
LiquidBlock::__construct(STILL_WATER, $meta, "Still Water");
|
||||||
$this->hardness = 500;
|
$this->hardness = 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getTickDelay(){
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class WaterBlock extends LiquidBlock{
|
class WaterBlock extends LiquidBlockDynamic{
|
||||||
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;
|
||||||
|
|
@ -8,116 +8,15 @@ class WaterBlock extends LiquidBlock{
|
||||||
|
|
||||||
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, 5, BLOCK_UPDATE_NORMAL);
|
//TODO place ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 5, BLOCK_UPDATE_NORMAL);
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSourceCount(){
|
public static function getTickDelay(){
|
||||||
$count = 0;
|
return 5;
|
||||||
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 onUpdate(Level $level, $x, $y, $z, $type){
|
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;*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue