mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
test light simulation + ice melting
This commit is contained in:
parent
a071f577bf
commit
945730e148
9 changed files with 74 additions and 16 deletions
|
|
@ -19,12 +19,14 @@
|
|||
*
|
||||
*/
|
||||
|
||||
class TorchBlock extends FlowableBlock{
|
||||
class TorchBlock extends FlowableBlock implements LightingBlock{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(TORCH, $meta, "Torch");
|
||||
$this->hardness = 0;
|
||||
}
|
||||
|
||||
public function getMaxLightValue(){
|
||||
return 15;
|
||||
}
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
$side = $this->getMetadata();
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
class LavaBlock extends LiquidBlock{
|
||||
class LavaBlock extends LiquidBlock implements LightingBlock{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(LAVA, $meta, "Lava");
|
||||
$this->hardness = 0;
|
||||
|
|
@ -31,6 +31,10 @@ class LavaBlock extends LiquidBlock{
|
|||
return $ret;
|
||||
}
|
||||
|
||||
public function getMaxLightValue(){
|
||||
return 15;
|
||||
}
|
||||
|
||||
public function getSourceCount(){
|
||||
$count = 0;
|
||||
for($side = 2; $side <= 5; ++$side){
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
class FireBlock extends FlowableBlock{
|
||||
class FireBlock extends FlowableBlock implements LightingBlock{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(FIRE, $meta, "Fire");
|
||||
$this->isReplaceable = true;
|
||||
|
|
@ -31,7 +31,9 @@ class FireBlock extends FlowableBlock{
|
|||
public function getDrops(Item $item, Player $player){
|
||||
return array();
|
||||
}
|
||||
|
||||
public function getMaxLightValue(){
|
||||
return 15;
|
||||
}
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
for($s = 0; $s <= 5; ++$s){
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
class GlowingRedstoneOreBlock extends SolidBlock{
|
||||
class GlowingRedstoneOreBlock extends SolidBlock implements LightingBlock{
|
||||
public function __construct(){
|
||||
parent::__construct(GLOWING_REDSTONE_ORE, 0, "Glowing Redstone Ore");
|
||||
$this->hardness = 15;
|
||||
|
|
@ -34,7 +34,9 @@ class GlowingRedstoneOreBlock extends SolidBlock{
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getMaxLightValue(){
|
||||
return 9;
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
class BurningFurnaceBlock extends SolidBlock{
|
||||
class BurningFurnaceBlock extends SolidBlock implements LightingBlock{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(BURNING_FURNACE, $meta, "Burning Furnace");
|
||||
$this->isActivable = true;
|
||||
|
|
@ -37,7 +37,9 @@ class BurningFurnaceBlock extends SolidBlock{
|
|||
$this->level->setBlock($block, $this, true, false, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getMaxLightValue(){
|
||||
return 13;
|
||||
}
|
||||
public function onBreak(Item $item, Player $player){
|
||||
$this->level->setBlock($this, new AirBlock(), true, true, true);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -19,9 +19,13 @@
|
|||
*
|
||||
*/
|
||||
|
||||
class GlowingObsidianBlock extends SolidBlock{
|
||||
class GlowingObsidianBlock extends SolidBlock implements LightingBlock{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(GLOWING_OBSIDIAN, $meta, "Glowing Obsidian");
|
||||
}
|
||||
|
||||
public function getMaxLightValue(){
|
||||
return 12;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -19,12 +19,16 @@
|
|||
*
|
||||
*/
|
||||
|
||||
class GlowstoneBlock extends TransparentBlock{
|
||||
class GlowstoneBlock extends TransparentBlock implements LightingBlock{
|
||||
public function __construct(){
|
||||
parent::__construct(GLOWSTONE_BLOCK, 0, "Glowstone");
|
||||
$this->hardness = 1.5;
|
||||
}
|
||||
|
||||
|
||||
public function getMaxLightValue(){
|
||||
return 15;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
return array(
|
||||
array(GLOWSTONE_DUST, 0, mt_rand(2, 4)),
|
||||
|
|
|
|||
|
|
@ -24,7 +24,11 @@ class IceBlock extends TransparentBlock{
|
|||
parent::__construct(ICE, 0, "Ice");
|
||||
$this->hardness = 2.5;
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$ret = $this->level->setBlock($this, $this, true, false, true);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
return $ret;
|
||||
}
|
||||
public function onBreak(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$this->level->setBlock($this, new WaterBlock(), true, false, true);
|
||||
|
|
@ -34,7 +38,37 @@ class IceBlock extends TransparentBlock{
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
Scan for blocks which can emit light
|
||||
args: offsetX: int, offsetY: int, offsetZ: int
|
||||
do not set offsets more than 15 : no lighting sources are giving so much light
|
||||
*/
|
||||
private function scanForNearbyLightSources($offsetX, $offsetY, $offsetZ){
|
||||
for($x = -$offsetX; $x <= $offsetX; ++$x){ //i hope it is possible to optimize it
|
||||
for($z = -$offsetZ; $z <= $offsetZ; ++$z){
|
||||
for($y = -$offsetY; $y <= $offsetY; ++$y){
|
||||
$pX = $this->x+$x;
|
||||
$pY = $this->y+$y;
|
||||
$pZ = $this->z+$z;
|
||||
$block = $this->level->getBlock(new Vector3($pX, $pY, $pZ));
|
||||
if($block instanceof LightingBlock){ //idk is it possible to make it better
|
||||
return $block;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public function onUpdate($type){ /*Taken from https://github.com/PocketMine/PocketMine-MP/issues/3249*/
|
||||
if($type === BLOCK_UPDATE_RANDOM){
|
||||
$light = $this->scanForNearbyLightSources(3,3,3);
|
||||
if(LightUtils::getLightValueFromNearbySource($light,$this) > 12){
|
||||
$this->level->setBlock($this, new WaterBlock(), true);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); //additional request for update
|
||||
}
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public function getBreakTime(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
return 0.20;
|
||||
|
|
|
|||
|
|
@ -19,12 +19,16 @@
|
|||
*
|
||||
*/
|
||||
|
||||
class LitPumpkinBlock extends SolidBlock{
|
||||
class LitPumpkinBlock extends SolidBlock implements LightingBlock{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(LIT_PUMPKIN, $meta, "Jack o'Lantern");
|
||||
$this->hardness = 5;
|
||||
}
|
||||
|
||||
|
||||
public function getMaxLightValue(){
|
||||
return 15;
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$faces = array(
|
||||
0 => 1,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue