mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-09 15:29:47 +00:00
Implemented frosted ice
This commit is contained in:
parent
6124f93cb4
commit
2d51622b12
@ -136,6 +136,7 @@ class BlockFactory{
|
||||
self::register(new Flower(new BID(Block::RED_FLOWER, Flower::TYPE_RED_TULIP), "Red Tulip"));
|
||||
self::register(new Flower(new BID(Block::RED_FLOWER, Flower::TYPE_WHITE_TULIP), "White Tulip"));
|
||||
self::register(new FlowerPot(new BID(Block::FLOWER_POT_BLOCK, 0, ItemIds::FLOWER_POT, \pocketmine\tile\FlowerPot::class), "Flower Pot"));
|
||||
self::register(new FrostedIce(new BID(Block::FROSTED_ICE), "Frosted Ice"));
|
||||
self::register(new Furnace(new BlockIdentifierFlattened(Block::FURNACE, Block::LIT_FURNACE, 0, null, \pocketmine\tile\Furnace::class), "Furnace"));
|
||||
self::register(new Glass(new BID(Block::GLASS), "Glass"));
|
||||
self::register(new GlassPane(new BID(Block::GLASS_PANE), "Glass Pane"));
|
||||
|
115
src/pocketmine/block/FrostedIce.php
Normal file
115
src/pocketmine/block/FrostedIce.php
Normal file
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\BlockDataValidator;
|
||||
use function max;
|
||||
use function mt_rand;
|
||||
|
||||
class FrostedIce extends Ice{
|
||||
|
||||
/** @var int */
|
||||
protected $age = 0;
|
||||
|
||||
public function readStateFromData(int $id, int $stateMeta) : void{
|
||||
$this->age = BlockDataValidator::readBoundedInt("age", $stateMeta, 0, 3);
|
||||
}
|
||||
|
||||
protected function writeStateToMeta() : int{
|
||||
return $this->age;
|
||||
}
|
||||
|
||||
public function getStateBitmask() : int{
|
||||
return 0b11;
|
||||
}
|
||||
|
||||
public function getHardness() : float{
|
||||
return 2.5;
|
||||
}
|
||||
|
||||
public function onNearbyBlockChange() : void{
|
||||
if(!$this->checkAdjacentBlocks(2)){
|
||||
$this->level->useBreakOn($this);
|
||||
}else{
|
||||
$this->level->scheduleDelayedBlockUpdate($this, mt_rand(20, 40));
|
||||
}
|
||||
}
|
||||
|
||||
public function onRandomTick() : void{
|
||||
if((!$this->checkAdjacentBlocks(4) or mt_rand(0, 2) === 0) and
|
||||
max( //TODO: move this to Level
|
||||
$this->level->getHighestAdjacentBlockLight($this->x, $this->y, $this->z),
|
||||
$this->level->getHighestAdjacentBlockSkyLight($this->x, $this->y, $this->z) - $this->level->getSkyLightReduction()
|
||||
) >= 12 - $this->age){
|
||||
if($this->tryMelt()){
|
||||
foreach($this->getAllSides() as $block){
|
||||
if($block instanceof FrostedIce){
|
||||
$block->tryMelt();
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$this->level->scheduleDelayedBlockUpdate($this, mt_rand(20, 40));
|
||||
}
|
||||
}
|
||||
|
||||
public function onScheduledUpdate() : void{
|
||||
$this->onRandomTick();
|
||||
}
|
||||
|
||||
private function checkAdjacentBlocks(int $requirement) : bool{
|
||||
$found = 0;
|
||||
for($x = -1; $x <= 1; ++$x){
|
||||
for($z = -1; $z <= 1; ++$z){
|
||||
if($x === 0 and $z === 0){
|
||||
continue;
|
||||
}
|
||||
if(
|
||||
$this->level->getBlockAt($this->x + $x, $this->y, $this->z + $z) instanceof FrostedIce and
|
||||
++$found >= $requirement
|
||||
){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the age of the ice, destroying it if appropriate.
|
||||
*
|
||||
* @return bool Whether the ice was destroyed.
|
||||
*/
|
||||
private function tryMelt() : bool{
|
||||
if($this->age >= 3){
|
||||
$this->level->useBreakOn($this);
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->age++;
|
||||
$this->level->setBlock($this, $this);
|
||||
$this->level->scheduleDelayedBlockUpdate($this, mt_rand(20, 40));
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user