mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-12 14:35:35 +00:00
Reduce code duplication between BaseCoral and CoralBlock
This commit is contained in:
parent
4f4aa62479
commit
5128bc02bb
@ -24,34 +24,17 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\utils\CoralType;
|
use pocketmine\block\utils\CoralType;
|
||||||
|
use pocketmine\block\utils\CoralTypeTrait;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
abstract class BaseCoral extends Transparent{
|
abstract class BaseCoral extends Transparent{
|
||||||
|
use CoralTypeTrait;
|
||||||
protected CoralType $coralType;
|
|
||||||
protected bool $dead = false;
|
|
||||||
|
|
||||||
public function __construct(BlockIdentifier $idInfo, string $name, BlockBreakInfo $breakInfo){
|
public function __construct(BlockIdentifier $idInfo, string $name, BlockBreakInfo $breakInfo){
|
||||||
parent::__construct($idInfo, $name, $breakInfo);
|
parent::__construct($idInfo, $name, $breakInfo);
|
||||||
$this->coralType = CoralType::TUBE();
|
$this->coralType = CoralType::TUBE();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCoralType() : CoralType{ return $this->coralType; }
|
|
||||||
|
|
||||||
/** @return $this */
|
|
||||||
public function setCoralType(CoralType $coralType) : self{
|
|
||||||
$this->coralType = $coralType;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isDead() : bool{ return $this->dead; }
|
|
||||||
|
|
||||||
/** @return $this */
|
|
||||||
public function setDead(bool $dead) : self{
|
|
||||||
$this->dead = $dead;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if(!$this->dead){
|
if(!$this->dead){
|
||||||
$world = $this->position->getWorld();
|
$world = $this->position->getWorld();
|
||||||
|
@ -24,15 +24,14 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\utils\CoralType;
|
use pocketmine\block\utils\CoralType;
|
||||||
|
use pocketmine\block\utils\CoralTypeTrait;
|
||||||
use pocketmine\block\utils\InvalidBlockStateException;
|
use pocketmine\block\utils\InvalidBlockStateException;
|
||||||
use pocketmine\data\bedrock\CoralTypeIdMap;
|
use pocketmine\data\bedrock\CoralTypeIdMap;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use function mt_rand;
|
use function mt_rand;
|
||||||
|
|
||||||
final class CoralBlock extends Opaque{
|
final class CoralBlock extends Opaque{
|
||||||
|
use CoralTypeTrait;
|
||||||
private CoralType $coralType;
|
|
||||||
private bool $dead = false;
|
|
||||||
|
|
||||||
public function __construct(BlockIdentifier $idInfo, string $name, BlockBreakInfo $breakInfo){
|
public function __construct(BlockIdentifier $idInfo, string $name, BlockBreakInfo $breakInfo){
|
||||||
$this->coralType = CoralType::TUBE();
|
$this->coralType = CoralType::TUBE();
|
||||||
@ -60,22 +59,6 @@ final class CoralBlock extends Opaque{
|
|||||||
return 0b1111;
|
return 0b1111;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCoralType() : CoralType{ return $this->coralType; }
|
|
||||||
|
|
||||||
/** @return $this */
|
|
||||||
public function setCoralType(CoralType $coralType) : self{
|
|
||||||
$this->coralType = $coralType;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isDead() : bool{ return $this->dead; }
|
|
||||||
|
|
||||||
/** @return $this */
|
|
||||||
public function setDead(bool $dead) : self{
|
|
||||||
$this->dead = $dead;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if(!$this->dead){
|
if(!$this->dead){
|
||||||
$this->position->getWorld()->scheduleDelayedBlockUpdate($this->position, mt_rand(40, 200));
|
$this->position->getWorld()->scheduleDelayedBlockUpdate($this->position, mt_rand(40, 200));
|
||||||
|
46
src/block/utils/CoralTypeTrait.php
Normal file
46
src/block/utils/CoralTypeTrait.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?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\utils;
|
||||||
|
|
||||||
|
trait CoralTypeTrait{
|
||||||
|
|
||||||
|
protected CoralType $coralType;
|
||||||
|
protected bool $dead = false;
|
||||||
|
|
||||||
|
public function getCoralType() : CoralType{ return $this->coralType; }
|
||||||
|
|
||||||
|
/** @return $this */
|
||||||
|
public function setCoralType(CoralType $coralType) : self{
|
||||||
|
$this->coralType = $coralType;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isDead() : bool{ return $this->dead; }
|
||||||
|
|
||||||
|
/** @return $this */
|
||||||
|
public function setDead(bool $dead) : self{
|
||||||
|
$this->dead = $dead;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user