mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-04 09:10:00 +00:00
Static support trait (#6044)
Added StaticSupportTrait for blocks which require unconditional support dynamic support requirements, such as those presented by item frames and torches, are not included. in addition, double blocks, such as tallgrass, small dripleaf and doors, do not cooperate well with this, so they are also not included. some blocks which could be migrated (such as chorus plant) were skipped due to unresolved problems.
This commit is contained in:
parent
2a528b4afb
commit
b293d7bf1f
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\block\utils\SupportType;
|
use pocketmine\block\utils\SupportType;
|
||||||
use pocketmine\data\runtime\RuntimeDataDescriber;
|
use pocketmine\data\runtime\RuntimeDataDescriber;
|
||||||
use pocketmine\event\block\StructureGrowEvent;
|
use pocketmine\event\block\StructureGrowEvent;
|
||||||
@ -46,6 +47,7 @@ use function mt_rand;
|
|||||||
use const PHP_INT_MAX;
|
use const PHP_INT_MAX;
|
||||||
|
|
||||||
class Bamboo extends Transparent{
|
class Bamboo extends Transparent{
|
||||||
|
use StaticSupportTrait;
|
||||||
|
|
||||||
public const NO_LEAVES = 0;
|
public const NO_LEAVES = 0;
|
||||||
public const SMALL_LEAVES = 1;
|
public const SMALL_LEAVES = 1;
|
||||||
@ -120,12 +122,14 @@ class Bamboo extends Transparent{
|
|||||||
return new Vector3($retX, 0, $retZ);
|
return new Vector3($retX, 0, $retZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
|
$supportBlock = $block->getSide(Facing::DOWN);
|
||||||
return
|
return
|
||||||
$block->getTypeId() === BlockTypeIds::GRAVEL ||
|
$supportBlock->hasSameTypeId($this) ||
|
||||||
$block->hasTypeTag(BlockTypeTags::DIRT) ||
|
$supportBlock->getTypeId() === BlockTypeIds::GRAVEL ||
|
||||||
$block->hasTypeTag(BlockTypeTags::MUD) ||
|
$supportBlock->hasTypeTag(BlockTypeTags::DIRT) ||
|
||||||
$block->hasTypeTag(BlockTypeTags::SAND);
|
$supportBlock->hasTypeTag(BlockTypeTags::MUD) ||
|
||||||
|
$supportBlock->hasTypeTag(BlockTypeTags::SAND);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function seekToTop() : Bamboo{
|
private function seekToTop() : Bamboo{
|
||||||
@ -153,14 +157,6 @@ class Bamboo extends Transparent{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
|
||||||
$world = $this->position->getWorld();
|
|
||||||
$below = $world->getBlock($this->position->down());
|
|
||||||
if(!$this->canBeSupportedBy($below) && !$below->hasSameTypeId($this)){
|
|
||||||
$world->useBreakOn($this->position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function grow(int $maxHeight, int $growAmount, ?Player $player) : bool{
|
private function grow(int $maxHeight, int $growAmount, ?Player $player) : bool{
|
||||||
$world = $this->position->getWorld();
|
$world = $this->position->getWorld();
|
||||||
if(!$world->getBlock($this->position->up())->canBeReplaced()){
|
if(!$world->getBlock($this->position->up())->canBeReplaced()){
|
||||||
|
@ -23,17 +23,21 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\data\runtime\RuntimeDataDescriber;
|
use pocketmine\data\runtime\RuntimeDataDescriber;
|
||||||
use pocketmine\event\block\StructureGrowEvent;
|
use pocketmine\event\block\StructureGrowEvent;
|
||||||
use pocketmine\item\Bamboo as ItemBamboo;
|
use pocketmine\item\Bamboo as ItemBamboo;
|
||||||
use pocketmine\item\Fertilizer;
|
use pocketmine\item\Fertilizer;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\VanillaItems;
|
use pocketmine\item\VanillaItems;
|
||||||
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\player\Player;
|
use pocketmine\player\Player;
|
||||||
use pocketmine\world\BlockTransaction;
|
use pocketmine\world\BlockTransaction;
|
||||||
|
|
||||||
final class BambooSapling extends Flowable{
|
final class BambooSapling extends Flowable{
|
||||||
|
use StaticSupportTrait;
|
||||||
|
|
||||||
private bool $ready = false;
|
private bool $ready = false;
|
||||||
|
|
||||||
protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
|
protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
|
||||||
@ -48,19 +52,13 @@ final class BambooSapling extends Flowable{
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
|
$supportBlock = $block->getSide(Facing::DOWN);
|
||||||
return
|
return
|
||||||
$block->getTypeId() === BlockTypeIds::GRAVEL ||
|
$supportBlock->getTypeId() === BlockTypeIds::GRAVEL ||
|
||||||
$block->hasTypeTag(BlockTypeTags::DIRT) ||
|
$supportBlock->hasTypeTag(BlockTypeTags::DIRT) ||
|
||||||
$block->hasTypeTag(BlockTypeTags::MUD) ||
|
$supportBlock->hasTypeTag(BlockTypeTags::MUD) ||
|
||||||
$block->hasTypeTag(BlockTypeTags::SAND);
|
$supportBlock->hasTypeTag(BlockTypeTags::SAND);
|
||||||
}
|
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
|
||||||
if(!$this->canBeSupportedBy($blockReplace->position->getWorld()->getBlock($blockReplace->position->down()))){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
||||||
@ -73,13 +71,6 @@ final class BambooSapling extends Flowable{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
|
||||||
$world = $this->position->getWorld();
|
|
||||||
if(!$this->canBeSupportedBy($world->getBlock($this->position->down()))){
|
|
||||||
$world->useBreakOn($this->position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function grow(?Player $player) : bool{
|
private function grow(?Player $player) : bool{
|
||||||
$world = $this->position->getWorld();
|
$world = $this->position->getWorld();
|
||||||
if(!$world->getBlock($this->position->up())->canBeReplaced()){
|
if(!$world->getBlock($this->position->up())->canBeReplaced()){
|
||||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\block\utils\SupportType;
|
use pocketmine\block\utils\SupportType;
|
||||||
use pocketmine\entity\effect\EffectInstance;
|
use pocketmine\entity\effect\EffectInstance;
|
||||||
use pocketmine\entity\FoodSource;
|
use pocketmine\entity\FoodSource;
|
||||||
@ -31,27 +32,16 @@ use pocketmine\item\Item;
|
|||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\player\Player;
|
use pocketmine\player\Player;
|
||||||
use pocketmine\world\BlockTransaction;
|
|
||||||
|
|
||||||
abstract class BaseCake extends Transparent implements FoodSource{
|
abstract class BaseCake extends Transparent implements FoodSource{
|
||||||
|
use StaticSupportTrait;
|
||||||
|
|
||||||
public function getSupportType(int $facing) : SupportType{
|
public function getSupportType(int $facing) : SupportType{
|
||||||
return SupportType::NONE;
|
return SupportType::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
$down = $this->getSide(Facing::DOWN);
|
return $block->getSide(Facing::DOWN)->getTypeId() !== BlockTypeIds::AIR;
|
||||||
if($down->getTypeId() !== BlockTypeIds::AIR){
|
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
|
||||||
if($this->getSide(Facing::DOWN)->getTypeId() === BlockTypeIds::AIR){ //Replace with common break method
|
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
||||||
|
@ -25,19 +25,17 @@ namespace pocketmine\block;
|
|||||||
|
|
||||||
use pocketmine\block\utils\AgeableTrait;
|
use pocketmine\block\utils\AgeableTrait;
|
||||||
use pocketmine\block\utils\BlockEventHelper;
|
use pocketmine\block\utils\BlockEventHelper;
|
||||||
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\block\utils\SupportType;
|
use pocketmine\block\utils\SupportType;
|
||||||
use pocketmine\entity\Entity;
|
use pocketmine\entity\Entity;
|
||||||
use pocketmine\event\entity\EntityDamageByBlockEvent;
|
use pocketmine\event\entity\EntityDamageByBlockEvent;
|
||||||
use pocketmine\event\entity\EntityDamageEvent;
|
use pocketmine\event\entity\EntityDamageEvent;
|
||||||
use pocketmine\item\Item;
|
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
|
||||||
use pocketmine\player\Player;
|
|
||||||
use pocketmine\world\BlockTransaction;
|
|
||||||
|
|
||||||
class Cactus extends Transparent{
|
class Cactus extends Transparent{
|
||||||
use AgeableTrait;
|
use AgeableTrait;
|
||||||
|
use StaticSupportTrait;
|
||||||
|
|
||||||
public const MAX_AGE = 15;
|
public const MAX_AGE = 15;
|
||||||
|
|
||||||
@ -63,23 +61,18 @@ class Cactus extends Transparent{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
return $block->hasSameTypeId($this) || $block->hasTypeTag(BlockTypeTags::SAND);
|
$supportBlock = $block->getSide(Facing::DOWN);
|
||||||
}
|
if(!$supportBlock->hasSameTypeId($this) && !$supportBlock->hasTypeTag(BlockTypeTags::SAND)){
|
||||||
|
return false;
|
||||||
public function onNearbyBlockChange() : void{
|
}
|
||||||
$world = $this->position->getWorld();
|
foreach(Facing::HORIZONTAL as $side){
|
||||||
if(!$this->canBeSupportedBy($this->getSide(Facing::DOWN))){
|
if($block->getSide($side)->isSolid()){
|
||||||
$world->useBreakOn($this->position);
|
return false;
|
||||||
}else{
|
|
||||||
foreach(Facing::HORIZONTAL as $side){
|
|
||||||
$b = $this->getSide($side);
|
|
||||||
if($b->isSolid()){
|
|
||||||
$world->useBreakOn($this->position);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ticksRandomly() : bool{
|
public function ticksRandomly() : bool{
|
||||||
@ -109,18 +102,4 @@ class Cactus extends Transparent{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
|
||||||
if($this->canBeSupportedBy($this->getSide(Facing::DOWN))){
|
|
||||||
foreach(Facing::HORIZONTAL as $side){
|
|
||||||
if($this->getSide($side)->isSolid()){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -24,15 +24,13 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\utils\ColoredTrait;
|
use pocketmine\block\utils\ColoredTrait;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
|
||||||
use pocketmine\player\Player;
|
|
||||||
use pocketmine\world\BlockTransaction;
|
|
||||||
|
|
||||||
class Carpet extends Flowable{
|
class Carpet extends Flowable{
|
||||||
use ColoredTrait;
|
use ColoredTrait;
|
||||||
|
use StaticSupportTrait;
|
||||||
|
|
||||||
public function isSolid() : bool{
|
public function isSolid() : bool{
|
||||||
return true;
|
return true;
|
||||||
@ -45,19 +43,8 @@ class Carpet extends Flowable{
|
|||||||
return [AxisAlignedBB::one()->trim(Facing::UP, 15 / 16)];
|
return [AxisAlignedBB::one()->trim(Facing::UP, 15 / 16)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
$down = $this->getSide(Facing::DOWN);
|
return $block->getSide(Facing::DOWN)->getTypeId() !== BlockTypeIds::AIR;
|
||||||
if($down->getTypeId() !== BlockTypeIds::AIR){
|
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
|
||||||
if($this->getSide(Facing::DOWN)->getTypeId() === BlockTypeIds::AIR){
|
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFlameEncouragement() : int{
|
public function getFlameEncouragement() : int{
|
||||||
|
@ -25,6 +25,7 @@ namespace pocketmine\block;
|
|||||||
|
|
||||||
use pocketmine\block\utils\AgeableTrait;
|
use pocketmine\block\utils\AgeableTrait;
|
||||||
use pocketmine\block\utils\BlockEventHelper;
|
use pocketmine\block\utils\BlockEventHelper;
|
||||||
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\block\utils\SupportType;
|
use pocketmine\block\utils\SupportType;
|
||||||
use pocketmine\data\runtime\RuntimeDataDescriber;
|
use pocketmine\data\runtime\RuntimeDataDescriber;
|
||||||
use pocketmine\entity\Entity;
|
use pocketmine\entity\Entity;
|
||||||
@ -40,6 +41,7 @@ use function mt_rand;
|
|||||||
|
|
||||||
class CaveVines extends Flowable{
|
class CaveVines extends Flowable{
|
||||||
use AgeableTrait;
|
use AgeableTrait;
|
||||||
|
use StaticSupportTrait;
|
||||||
|
|
||||||
public const MAX_AGE = 25;
|
public const MAX_AGE = 25;
|
||||||
|
|
||||||
@ -81,16 +83,7 @@ class CaveVines extends Flowable{
|
|||||||
return $supportBlock->getSupportType(Facing::DOWN) === SupportType::FULL || $supportBlock->hasSameTypeId($this);
|
return $supportBlock->getSupportType(Facing::DOWN) === SupportType::FULL || $supportBlock->hasSameTypeId($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
|
||||||
if(!$this->canBeSupportedAt($this)){
|
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if(!$this->canBeSupportedAt($blockReplace)){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$this->age = mt_rand(0, self::MAX_AGE);
|
$this->age = mt_rand(0, self::MAX_AGE);
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||||
}
|
}
|
||||||
|
@ -24,17 +24,15 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\utils\AgeableTrait;
|
use pocketmine\block\utils\AgeableTrait;
|
||||||
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\entity\projectile\Projectile;
|
use pocketmine\entity\projectile\Projectile;
|
||||||
use pocketmine\event\block\StructureGrowEvent;
|
use pocketmine\event\block\StructureGrowEvent;
|
||||||
use pocketmine\item\Item;
|
|
||||||
use pocketmine\math\Axis;
|
use pocketmine\math\Axis;
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\RayTraceResult;
|
use pocketmine\math\RayTraceResult;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\player\Player;
|
|
||||||
use pocketmine\world\BlockTransaction;
|
use pocketmine\world\BlockTransaction;
|
||||||
use pocketmine\world\Position;
|
|
||||||
use pocketmine\world\sound\ChorusFlowerDieSound;
|
use pocketmine\world\sound\ChorusFlowerDieSound;
|
||||||
use pocketmine\world\sound\ChorusFlowerGrowSound;
|
use pocketmine\world\sound\ChorusFlowerGrowSound;
|
||||||
use pocketmine\world\World;
|
use pocketmine\world\World;
|
||||||
@ -44,6 +42,7 @@ use function mt_rand;
|
|||||||
|
|
||||||
final class ChorusFlower extends Flowable{
|
final class ChorusFlower extends Flowable{
|
||||||
use AgeableTrait;
|
use AgeableTrait;
|
||||||
|
use StaticSupportTrait;
|
||||||
|
|
||||||
public const MIN_AGE = 0;
|
public const MIN_AGE = 0;
|
||||||
public const MAX_AGE = 5;
|
public const MAX_AGE = 5;
|
||||||
@ -54,7 +53,8 @@ final class ChorusFlower extends Flowable{
|
|||||||
return [AxisAlignedBB::one()];
|
return [AxisAlignedBB::one()];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canBeSupportedAt(Position $position) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
|
$position = $block->getPosition();
|
||||||
$world = $position->getWorld();
|
$world = $position->getWorld();
|
||||||
$down = $world->getBlock($position->down());
|
$down = $world->getBlock($position->down());
|
||||||
|
|
||||||
@ -79,19 +79,6 @@ final class ChorusFlower extends Flowable{
|
|||||||
return $plantAdjacent;
|
return $plantAdjacent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
|
||||||
if(!$this->canBeSupportedAt($blockReplace->getPosition())){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
|
||||||
if(!$this->canBeSupportedAt($this->position)){
|
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onProjectileHit(Projectile $projectile, RayTraceResult $hitResult) : void{
|
public function onProjectileHit(Projectile $projectile, RayTraceResult $hitResult) : void{
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
$this->position->getWorld()->useBreakOn($this->position);
|
||||||
}
|
}
|
||||||
|
@ -23,29 +23,11 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\item\Item;
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
|
||||||
use pocketmine\player\Player;
|
|
||||||
use pocketmine\world\BlockTransaction;
|
|
||||||
|
|
||||||
final class Coral extends BaseCoral{
|
final class Coral extends BaseCoral{
|
||||||
|
use StaticSupportTrait;
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
|
||||||
if(!$this->canBeSupportedAt($blockReplace)){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
|
||||||
$world = $this->position->getWorld();
|
|
||||||
if(!$this->canBeSupportedAt($this)){
|
|
||||||
$world->useBreakOn($this->position);
|
|
||||||
}else{
|
|
||||||
parent::onNearbyBlockChange();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function canBeSupportedAt(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
return $block->getAdjacentSupportType(Facing::DOWN)->hasCenterSupport();
|
return $block->getAdjacentSupportType(Facing::DOWN)->hasCenterSupport();
|
||||||
|
@ -25,25 +25,22 @@ namespace pocketmine\block;
|
|||||||
|
|
||||||
use pocketmine\block\utils\AgeableTrait;
|
use pocketmine\block\utils\AgeableTrait;
|
||||||
use pocketmine\block\utils\BlockEventHelper;
|
use pocketmine\block\utils\BlockEventHelper;
|
||||||
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\item\Fertilizer;
|
use pocketmine\item\Fertilizer;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\player\Player;
|
use pocketmine\player\Player;
|
||||||
use pocketmine\world\BlockTransaction;
|
|
||||||
use function mt_rand;
|
use function mt_rand;
|
||||||
|
|
||||||
abstract class Crops extends Flowable{
|
abstract class Crops extends Flowable{
|
||||||
use AgeableTrait;
|
use AgeableTrait;
|
||||||
|
use StaticSupportTrait;
|
||||||
|
|
||||||
public const MAX_AGE = 7;
|
public const MAX_AGE = 7;
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
if($blockReplace->getSide(Facing::DOWN)->getTypeId() === BlockTypeIds::FARMLAND){
|
return $block->getSide(Facing::DOWN)->getTypeId() === BlockTypeIds::FARMLAND;
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
||||||
@ -64,12 +61,6 @@ abstract class Crops extends Flowable{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
|
||||||
if($this->getSide(Facing::DOWN)->getTypeId() !== BlockTypeIds::FARMLAND){
|
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ticksRandomly() : bool{
|
public function ticksRandomly() : bool{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -23,29 +23,14 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\VanillaItems;
|
use pocketmine\item\VanillaItems;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
|
||||||
use pocketmine\player\Player;
|
|
||||||
use pocketmine\world\BlockTransaction;
|
|
||||||
use function mt_rand;
|
use function mt_rand;
|
||||||
|
|
||||||
class DeadBush extends Flowable{
|
class DeadBush extends Flowable{
|
||||||
|
use StaticSupportTrait;
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
|
||||||
if($this->canBeSupportedBy($this->getSide(Facing::DOWN))){
|
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
|
||||||
if(!$this->canBeSupportedBy($this->getSide(Facing::DOWN))){
|
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDropsForIncompatibleTool(Item $item) : array{
|
public function getDropsForIncompatibleTool(Item $item) : array{
|
||||||
return [
|
return [
|
||||||
@ -65,14 +50,18 @@ class DeadBush extends Flowable{
|
|||||||
return 100;
|
return 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
$blockId = $block->getTypeId();
|
$supportBlock = $block->getSide(Facing::DOWN);
|
||||||
return $blockId === BlockTypeIds::SAND
|
//TODO: can we use tags here?
|
||||||
|| $blockId === BlockTypeIds::RED_SAND
|
return match($supportBlock->getTypeId()){
|
||||||
|| $blockId === BlockTypeIds::PODZOL
|
BlockTypeIds::SAND,
|
||||||
|| $blockId === BlockTypeIds::MYCELIUM
|
BlockTypeIds::RED_SAND,
|
||||||
|| $blockId === BlockTypeIds::DIRT
|
BlockTypeIds::PODZOL,
|
||||||
|| $blockId === BlockTypeIds::HARDENED_CLAY
|
BlockTypeIds::MYCELIUM,
|
||||||
|| $blockId === BlockTypeIds::STAINED_CLAY;
|
BlockTypeIds::DIRT,
|
||||||
|
BlockTypeIds::HARDENED_CLAY,
|
||||||
|
BlockTypeIds::STAINED_CLAY => true,
|
||||||
|
default => false
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\data\runtime\RuntimeDataDescriber;
|
use pocketmine\data\runtime\RuntimeDataDescriber;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\VanillaItems;
|
use pocketmine\item\VanillaItems;
|
||||||
@ -35,6 +36,8 @@ use function atan2;
|
|||||||
use function rad2deg;
|
use function rad2deg;
|
||||||
|
|
||||||
final class FloorCoralFan extends BaseCoral{
|
final class FloorCoralFan extends BaseCoral{
|
||||||
|
use StaticSupportTrait;
|
||||||
|
|
||||||
private int $axis = Axis::X;
|
private int $axis = Axis::X;
|
||||||
|
|
||||||
protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
|
protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
|
||||||
@ -53,9 +56,6 @@ final class FloorCoralFan extends BaseCoral{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if(!$this->canBeSupportedAt($blockReplace)){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if($player !== null){
|
if($player !== null){
|
||||||
$playerBlockPos = $player->getPosition()->floor();
|
$playerBlockPos = $player->getPosition()->floor();
|
||||||
$directionVector = $blockReplace->getPosition()->subtractVector($playerBlockPos)->normalize();
|
$directionVector = $blockReplace->getPosition()->subtractVector($playerBlockPos)->normalize();
|
||||||
@ -73,15 +73,6 @@ final class FloorCoralFan extends BaseCoral{
|
|||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
|
||||||
$world = $this->position->getWorld();
|
|
||||||
if(!$this->canBeSupportedAt($this)){
|
|
||||||
$world->useBreakOn($this->position);
|
|
||||||
}else{
|
|
||||||
parent::onNearbyBlockChange();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function canBeSupportedAt(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
return $block->getAdjacentSupportType(Facing::DOWN)->hasCenterSupport();
|
return $block->getAdjacentSupportType(Facing::DOWN)->hasCenterSupport();
|
||||||
}
|
}
|
||||||
|
@ -23,28 +23,15 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\item\Item;
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
|
||||||
use pocketmine\player\Player;
|
|
||||||
use pocketmine\world\BlockTransaction;
|
|
||||||
|
|
||||||
class Flower extends Flowable{
|
class Flower extends Flowable{
|
||||||
|
use StaticSupportTrait;
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
$down = $this->getSide(Facing::DOWN);
|
$supportBlock = $block->getSide(Facing::DOWN);
|
||||||
if($down->hasTypeTag(BlockTypeTags::DIRT) || $down->hasTypeTag(BlockTypeTags::MUD)){
|
return $supportBlock->hasTypeTag(BlockTypeTags::DIRT) || $supportBlock->hasTypeTag(BlockTypeTags::MUD);
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
|
||||||
$down = $this->getSide(Facing::DOWN);
|
|
||||||
if(!$down->hasTypeTag(BlockTypeTags::DIRT) && !$down->hasTypeTag(BlockTypeTags::MUD)){
|
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFlameEncouragement() : int{
|
public function getFlameEncouragement() : int{
|
||||||
|
@ -24,15 +24,16 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\tile\FlowerPot as TileFlowerPot;
|
use pocketmine\block\tile\FlowerPot as TileFlowerPot;
|
||||||
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\player\Player;
|
use pocketmine\player\Player;
|
||||||
use pocketmine\world\BlockTransaction;
|
|
||||||
use function assert;
|
use function assert;
|
||||||
|
|
||||||
class FlowerPot extends Flowable{
|
class FlowerPot extends Flowable{
|
||||||
|
use StaticSupportTrait;
|
||||||
|
|
||||||
protected ?Block $plant = null;
|
protected ?Block $plant = null;
|
||||||
|
|
||||||
@ -89,20 +90,6 @@ class FlowerPot extends Flowable{
|
|||||||
return [AxisAlignedBB::one()->contract(3 / 16, 0, 3 / 16)->trim(Facing::UP, 5 / 8)];
|
return [AxisAlignedBB::one()->contract(3 / 16, 0, 3 / 16)->trim(Facing::UP, 5 / 8)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
|
||||||
if(!$this->canBeSupportedAt($blockReplace)){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
|
||||||
if(!$this->canBeSupportedAt($this)){
|
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function canBeSupportedAt(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
return $block->getAdjacentSupportType(Facing::DOWN)->hasCenterSupport();
|
return $block->getAdjacentSupportType(Facing::DOWN)->hasCenterSupport();
|
||||||
}
|
}
|
||||||
|
@ -23,32 +23,18 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\item\enchantment\VanillaEnchantments;
|
use pocketmine\item\enchantment\VanillaEnchantments;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
|
||||||
use pocketmine\player\Player;
|
|
||||||
use pocketmine\world\BlockTransaction;
|
|
||||||
|
|
||||||
final class HangingRoots extends Flowable{
|
final class HangingRoots extends Flowable{
|
||||||
|
use StaticSupportTrait;
|
||||||
|
|
||||||
private function canBeSupportedAt(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
return $block->getAdjacentSupportType(Facing::UP)->hasCenterSupport(); //weird I know, but they can be placed on the bottom of fences
|
return $block->getAdjacentSupportType(Facing::UP)->hasCenterSupport(); //weird I know, but they can be placed on the bottom of fences
|
||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
|
||||||
if(!$this->canBeSupportedAt($blockReplace)){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
|
||||||
if(!$this->canBeSupportedAt($this)){
|
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDropsForIncompatibleTool(Item $item) : array{
|
public function getDropsForIncompatibleTool(Item $item) : array{
|
||||||
if($item->hasEnchantment(VanillaEnchantments::SILK_TOUCH())){
|
if($item->hasEnchantment(VanillaEnchantments::SILK_TOUCH())){
|
||||||
return $this->getDropsForCompatibleTool($item);
|
return $this->getDropsForCompatibleTool($item);
|
||||||
|
@ -25,6 +25,7 @@ namespace pocketmine\block;
|
|||||||
|
|
||||||
use pocketmine\block\utils\AgeableTrait;
|
use pocketmine\block\utils\AgeableTrait;
|
||||||
use pocketmine\block\utils\FortuneDropHelper;
|
use pocketmine\block\utils\FortuneDropHelper;
|
||||||
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\block\utils\SupportType;
|
use pocketmine\block\utils\SupportType;
|
||||||
use pocketmine\entity\Entity;
|
use pocketmine\entity\Entity;
|
||||||
use pocketmine\event\block\StructureGrowEvent;
|
use pocketmine\event\block\StructureGrowEvent;
|
||||||
@ -42,6 +43,7 @@ use function mt_rand;
|
|||||||
*/
|
*/
|
||||||
class NetherVines extends Flowable{
|
class NetherVines extends Flowable{
|
||||||
use AgeableTrait;
|
use AgeableTrait;
|
||||||
|
use StaticSupportTrait;
|
||||||
|
|
||||||
public const MAX_AGE = 25;
|
public const MAX_AGE = 25;
|
||||||
|
|
||||||
@ -70,12 +72,6 @@ class NetherVines extends Flowable{
|
|||||||
return $supportBlock->getSupportType($this->growthFace)->hasCenterSupport() || $supportBlock->hasSameTypeId($this);
|
return $supportBlock->getSupportType($this->growthFace)->hasCenterSupport() || $supportBlock->hasSameTypeId($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
|
||||||
if(!$this->canBeSupportedAt($this)){
|
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the block at the end of the vine structure furthest from the supporting block.
|
* Returns the block at the end of the vine structure furthest from the supporting block.
|
||||||
*/
|
*/
|
||||||
@ -88,9 +84,6 @@ class NetherVines extends Flowable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if(!$this->canBeSupportedAt($blockReplace)){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$this->age = mt_rand(0, self::MAX_AGE - 1);
|
$this->age = mt_rand(0, self::MAX_AGE - 1);
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||||
}
|
}
|
||||||
|
@ -26,31 +26,19 @@ namespace pocketmine\block;
|
|||||||
use pocketmine\block\utils\AgeableTrait;
|
use pocketmine\block\utils\AgeableTrait;
|
||||||
use pocketmine\block\utils\BlockEventHelper;
|
use pocketmine\block\utils\BlockEventHelper;
|
||||||
use pocketmine\block\utils\FortuneDropHelper;
|
use pocketmine\block\utils\FortuneDropHelper;
|
||||||
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
|
||||||
use pocketmine\player\Player;
|
|
||||||
use pocketmine\world\BlockTransaction;
|
|
||||||
use function mt_rand;
|
use function mt_rand;
|
||||||
|
|
||||||
class NetherWartPlant extends Flowable{
|
class NetherWartPlant extends Flowable{
|
||||||
use AgeableTrait;
|
use AgeableTrait;
|
||||||
|
use StaticSupportTrait;
|
||||||
|
|
||||||
public const MAX_AGE = 3;
|
public const MAX_AGE = 3;
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
$down = $this->getSide(Facing::DOWN);
|
return $block->getSide(Facing::DOWN)->getTypeId() === BlockTypeIds::SOUL_SAND;
|
||||||
if($down->getTypeId() === BlockTypeIds::SOUL_SAND){
|
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
|
||||||
if($this->getSide(Facing::DOWN)->getTypeId() !== BlockTypeIds::SOUL_SAND){
|
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ticksRandomly() : bool{
|
public function ticksRandomly() : bool{
|
||||||
|
@ -25,6 +25,7 @@ namespace pocketmine\block;
|
|||||||
|
|
||||||
use pocketmine\block\utils\BlockEventHelper;
|
use pocketmine\block\utils\BlockEventHelper;
|
||||||
use pocketmine\block\utils\HorizontalFacingTrait;
|
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||||
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\data\runtime\RuntimeDataDescriber;
|
use pocketmine\data\runtime\RuntimeDataDescriber;
|
||||||
use pocketmine\item\Fertilizer;
|
use pocketmine\item\Fertilizer;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
@ -35,6 +36,9 @@ use pocketmine\world\BlockTransaction;
|
|||||||
|
|
||||||
class PinkPetals extends Flowable{
|
class PinkPetals extends Flowable{
|
||||||
use HorizontalFacingTrait;
|
use HorizontalFacingTrait;
|
||||||
|
use StaticSupportTrait {
|
||||||
|
canBePlacedAt as supportedWhenPlacedAt;
|
||||||
|
}
|
||||||
|
|
||||||
public const MIN_COUNT = 1;
|
public const MIN_COUNT = 1;
|
||||||
public const MAX_COUNT = 4;
|
public const MAX_COUNT = 4;
|
||||||
@ -65,20 +69,11 @@ class PinkPetals extends Flowable{
|
|||||||
return $supportBlock->hasTypeTag(BlockTypeTags::DIRT) || $supportBlock->hasTypeTag(BlockTypeTags::MUD);
|
return $supportBlock->hasTypeTag(BlockTypeTags::DIRT) || $supportBlock->hasTypeTag(BlockTypeTags::MUD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
|
||||||
if(!$this->canBeSupportedAt($this)){
|
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{
|
public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{
|
||||||
return ($blockReplace instanceof PinkPetals && $blockReplace->getCount() < self::MAX_COUNT) || parent::canBePlacedAt($blockReplace, $clickVector, $face, $isClickedBlock);
|
return ($blockReplace instanceof PinkPetals && $blockReplace->getCount() < self::MAX_COUNT) || $this->supportedWhenPlacedAt($blockReplace, $clickVector, $face, $isClickedBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if(!$this->canBeSupportedAt($this)){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if($blockReplace instanceof PinkPetals && $blockReplace->getCount() < self::MAX_COUNT){
|
if($blockReplace instanceof PinkPetals && $blockReplace->getCount() < self::MAX_COUNT){
|
||||||
$this->count = $blockReplace->getCount() + 1;
|
$this->count = $blockReplace->getCount() + 1;
|
||||||
$this->facing = $blockReplace->getFacing();
|
$this->facing = $blockReplace->getFacing();
|
||||||
|
@ -23,21 +23,19 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\block\utils\SupportType;
|
use pocketmine\block\utils\SupportType;
|
||||||
use pocketmine\entity\Entity;
|
use pocketmine\entity\Entity;
|
||||||
use pocketmine\event\block\PressurePlateUpdateEvent;
|
use pocketmine\event\block\PressurePlateUpdateEvent;
|
||||||
use pocketmine\item\Item;
|
|
||||||
use pocketmine\math\Axis;
|
use pocketmine\math\Axis;
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
|
||||||
use pocketmine\player\Player;
|
|
||||||
use pocketmine\world\BlockTransaction;
|
|
||||||
use pocketmine\world\sound\PressurePlateActivateSound;
|
use pocketmine\world\sound\PressurePlateActivateSound;
|
||||||
use pocketmine\world\sound\PressurePlateDeactivateSound;
|
use pocketmine\world\sound\PressurePlateDeactivateSound;
|
||||||
use function count;
|
use function count;
|
||||||
|
|
||||||
abstract class PressurePlate extends Transparent{
|
abstract class PressurePlate extends Transparent{
|
||||||
|
use StaticSupportTrait;
|
||||||
|
|
||||||
private readonly int $deactivationDelayTicks;
|
private readonly int $deactivationDelayTicks;
|
||||||
|
|
||||||
@ -63,23 +61,10 @@ abstract class PressurePlate extends Transparent{
|
|||||||
return SupportType::NONE;
|
return SupportType::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
|
||||||
if($this->canBeSupportedAt($blockReplace)){
|
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function canBeSupportedAt(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
return $block->getAdjacentSupportType(Facing::DOWN) !== SupportType::NONE;
|
return $block->getAdjacentSupportType(Facing::DOWN) !== SupportType::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
|
||||||
if(!$this->canBeSupportedAt($this)){
|
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function hasEntityCollision() : bool{
|
public function hasEntityCollision() : bool{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ use pocketmine\block\tile\Comparator;
|
|||||||
use pocketmine\block\utils\AnalogRedstoneSignalEmitterTrait;
|
use pocketmine\block\utils\AnalogRedstoneSignalEmitterTrait;
|
||||||
use pocketmine\block\utils\HorizontalFacingTrait;
|
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||||
use pocketmine\block\utils\PoweredByRedstoneTrait;
|
use pocketmine\block\utils\PoweredByRedstoneTrait;
|
||||||
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\block\utils\SupportType;
|
use pocketmine\block\utils\SupportType;
|
||||||
use pocketmine\data\runtime\RuntimeDataDescriber;
|
use pocketmine\data\runtime\RuntimeDataDescriber;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
@ -41,6 +42,7 @@ class RedstoneComparator extends Flowable{
|
|||||||
use HorizontalFacingTrait;
|
use HorizontalFacingTrait;
|
||||||
use AnalogRedstoneSignalEmitterTrait;
|
use AnalogRedstoneSignalEmitterTrait;
|
||||||
use PoweredByRedstoneTrait;
|
use PoweredByRedstoneTrait;
|
||||||
|
use StaticSupportTrait;
|
||||||
|
|
||||||
protected bool $isSubtractMode = false;
|
protected bool $isSubtractMode = false;
|
||||||
|
|
||||||
@ -85,14 +87,10 @@ class RedstoneComparator extends Flowable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if($this->canBeSupportedAt($blockReplace)){
|
if($player !== null){
|
||||||
if($player !== null){
|
$this->facing = Facing::opposite($player->getHorizontalFacing());
|
||||||
$this->facing = Facing::opposite($player->getHorizontalFacing());
|
|
||||||
}
|
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
|
||||||
}
|
}
|
||||||
|
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
||||||
@ -101,12 +99,6 @@ class RedstoneComparator extends Flowable{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
|
||||||
if(!$this->canBeSupportedAt($this)){
|
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function canBeSupportedAt(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
return $block->getAdjacentSupportType(Facing::DOWN) !== SupportType::NONE;
|
return $block->getAdjacentSupportType(Facing::DOWN) !== SupportType::NONE;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ namespace pocketmine\block;
|
|||||||
|
|
||||||
use pocketmine\block\utils\HorizontalFacingTrait;
|
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||||
use pocketmine\block\utils\PoweredByRedstoneTrait;
|
use pocketmine\block\utils\PoweredByRedstoneTrait;
|
||||||
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\block\utils\SupportType;
|
use pocketmine\block\utils\SupportType;
|
||||||
use pocketmine\data\runtime\RuntimeDataDescriber;
|
use pocketmine\data\runtime\RuntimeDataDescriber;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
@ -37,6 +38,7 @@ use pocketmine\world\BlockTransaction;
|
|||||||
class RedstoneRepeater extends Flowable{
|
class RedstoneRepeater extends Flowable{
|
||||||
use HorizontalFacingTrait;
|
use HorizontalFacingTrait;
|
||||||
use PoweredByRedstoneTrait;
|
use PoweredByRedstoneTrait;
|
||||||
|
use StaticSupportTrait;
|
||||||
|
|
||||||
public const MIN_DELAY = 1;
|
public const MIN_DELAY = 1;
|
||||||
public const MAX_DELAY = 4;
|
public const MAX_DELAY = 4;
|
||||||
@ -68,15 +70,11 @@ class RedstoneRepeater extends Flowable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if($this->canBeSupportedAt($blockReplace)){
|
if($player !== null){
|
||||||
if($player !== null){
|
$this->facing = Facing::opposite($player->getHorizontalFacing());
|
||||||
$this->facing = Facing::opposite($player->getHorizontalFacing());
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
||||||
@ -87,12 +85,6 @@ class RedstoneRepeater extends Flowable{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
|
||||||
if(!$this->canBeSupportedAt($this)){
|
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function canBeSupportedAt(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
return $block->getAdjacentSupportType(Facing::DOWN) !== SupportType::NONE;
|
return $block->getAdjacentSupportType(Facing::DOWN) !== SupportType::NONE;
|
||||||
}
|
}
|
||||||
|
@ -24,22 +24,14 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\utils\AnalogRedstoneSignalEmitterTrait;
|
use pocketmine\block\utils\AnalogRedstoneSignalEmitterTrait;
|
||||||
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\VanillaItems;
|
use pocketmine\item\VanillaItems;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
|
||||||
use pocketmine\player\Player;
|
|
||||||
use pocketmine\world\BlockTransaction;
|
|
||||||
|
|
||||||
class RedstoneWire extends Flowable{
|
class RedstoneWire extends Flowable{
|
||||||
use AnalogRedstoneSignalEmitterTrait;
|
use AnalogRedstoneSignalEmitterTrait;
|
||||||
|
use StaticSupportTrait;
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
|
||||||
if($this->canBeSupportedAt($blockReplace)){
|
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function readStateFromWorld() : Block{
|
public function readStateFromWorld() : Block{
|
||||||
parent::readStateFromWorld();
|
parent::readStateFromWorld();
|
||||||
@ -48,12 +40,6 @@ class RedstoneWire extends Flowable{
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
|
||||||
if(!$this->canBeSupportedAt($this)){
|
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function canBeSupportedAt(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
return $block->getAdjacentSupportType(Facing::DOWN)->hasCenterSupport();
|
return $block->getAdjacentSupportType(Facing::DOWN)->hasCenterSupport();
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\utils\SaplingType;
|
use pocketmine\block\utils\SaplingType;
|
||||||
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\data\runtime\RuntimeDataDescriber;
|
use pocketmine\data\runtime\RuntimeDataDescriber;
|
||||||
use pocketmine\event\block\StructureGrowEvent;
|
use pocketmine\event\block\StructureGrowEvent;
|
||||||
use pocketmine\item\Fertilizer;
|
use pocketmine\item\Fertilizer;
|
||||||
@ -32,11 +33,12 @@ use pocketmine\math\Facing;
|
|||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\player\Player;
|
use pocketmine\player\Player;
|
||||||
use pocketmine\utils\Random;
|
use pocketmine\utils\Random;
|
||||||
use pocketmine\world\BlockTransaction;
|
|
||||||
use pocketmine\world\generator\object\TreeFactory;
|
use pocketmine\world\generator\object\TreeFactory;
|
||||||
use function mt_rand;
|
use function mt_rand;
|
||||||
|
|
||||||
class Sapling extends Flowable{
|
class Sapling extends Flowable{
|
||||||
|
use StaticSupportTrait;
|
||||||
|
|
||||||
protected bool $ready = false;
|
protected bool $ready = false;
|
||||||
|
|
||||||
private SaplingType $saplingType;
|
private SaplingType $saplingType;
|
||||||
@ -58,13 +60,9 @@ class Sapling extends Flowable{
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
$down = $this->getSide(Facing::DOWN);
|
$supportBlock = $block->getSide(Facing::DOWN);
|
||||||
if($down->hasTypeTag(BlockTypeTags::DIRT) || $down->hasTypeTag(BlockTypeTags::MUD)){
|
return $supportBlock->hasTypeTag(BlockTypeTags::DIRT) || $supportBlock->hasTypeTag(BlockTypeTags::MUD);
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
||||||
@ -77,13 +75,6 @@ class Sapling extends Flowable{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
|
||||||
$down = $this->getSide(Facing::DOWN);
|
|
||||||
if(!$down->hasTypeTag(BlockTypeTags::DIRT) && !$down->hasTypeTag(BlockTypeTags::MUD)){
|
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ticksRandomly() : bool{
|
public function ticksRandomly() : bool{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -23,30 +23,14 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\block\utils\SupportType;
|
use pocketmine\block\utils\SupportType;
|
||||||
use pocketmine\item\Item;
|
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
|
||||||
use pocketmine\player\Player;
|
|
||||||
use pocketmine\world\BlockTransaction;
|
|
||||||
|
|
||||||
final class SporeBlossom extends Flowable{
|
final class SporeBlossom extends Flowable{
|
||||||
|
use StaticSupportTrait;
|
||||||
|
|
||||||
private function canBeSupportedAt(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
return $block->getAdjacentSupportType(Facing::UP) === SupportType::FULL;
|
return $block->getAdjacentSupportType(Facing::UP) === SupportType::FULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
|
||||||
if(!$this->canBeSupportedAt($blockReplace)){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
|
||||||
if(!$this->canBeSupportedAt($this)){
|
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ namespace pocketmine\block;
|
|||||||
|
|
||||||
use pocketmine\block\utils\AgeableTrait;
|
use pocketmine\block\utils\AgeableTrait;
|
||||||
use pocketmine\block\utils\BlockEventHelper;
|
use pocketmine\block\utils\BlockEventHelper;
|
||||||
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\item\Fertilizer;
|
use pocketmine\item\Fertilizer;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
@ -35,6 +36,7 @@ use pocketmine\world\Position;
|
|||||||
|
|
||||||
class Sugarcane extends Flowable{
|
class Sugarcane extends Flowable{
|
||||||
use AgeableTrait;
|
use AgeableTrait;
|
||||||
|
use StaticSupportTrait;
|
||||||
|
|
||||||
public const MAX_AGE = 15;
|
public const MAX_AGE = 15;
|
||||||
|
|
||||||
@ -82,18 +84,12 @@ class Sugarcane extends Flowable{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
return
|
$supportBlock = $block->getSide(Facing::DOWN);
|
||||||
$block->hasTypeTag(BlockTypeTags::MUD) ||
|
return $supportBlock->hasSameTypeId($this) ||
|
||||||
$block->hasTypeTag(BlockTypeTags::DIRT) ||
|
$supportBlock->hasTypeTag(BlockTypeTags::MUD) ||
|
||||||
$block->hasTypeTag(BlockTypeTags::SAND);
|
$supportBlock->hasTypeTag(BlockTypeTags::DIRT) ||
|
||||||
}
|
$supportBlock->hasTypeTag(BlockTypeTags::SAND);
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
|
||||||
$down = $this->getSide(Facing::DOWN);
|
|
||||||
if(!$down->hasSameTypeId($this) && !$this->canBeSupportedBy($down)){
|
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ticksRandomly() : bool{
|
public function ticksRandomly() : bool{
|
||||||
@ -112,15 +108,16 @@ class Sugarcane extends Flowable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
$down = $this->getSide(Facing::DOWN);
|
$down = $blockReplace->getSide(Facing::DOWN);
|
||||||
if($down->hasSameTypeId($this)){
|
if($down->hasSameTypeId($this)){
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||||
}elseif($this->canBeSupportedBy($down)){
|
}
|
||||||
foreach(Facing::HORIZONTAL as $side){
|
|
||||||
$sideBlock = $down->getSide($side);
|
//support criteria are checked by FixedSupportTrait, but this part applies to placement only
|
||||||
if($sideBlock instanceof Water || $sideBlock instanceof FrostedIce){
|
foreach(Facing::HORIZONTAL as $side){
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
$sideBlock = $down->getSide($side);
|
||||||
}
|
if($sideBlock instanceof Water || $sideBlock instanceof FrostedIce){
|
||||||
|
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ namespace pocketmine\block;
|
|||||||
use pocketmine\block\utils\AgeableTrait;
|
use pocketmine\block\utils\AgeableTrait;
|
||||||
use pocketmine\block\utils\BlockEventHelper;
|
use pocketmine\block\utils\BlockEventHelper;
|
||||||
use pocketmine\block\utils\FortuneDropHelper;
|
use pocketmine\block\utils\FortuneDropHelper;
|
||||||
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\entity\Entity;
|
use pocketmine\entity\Entity;
|
||||||
use pocketmine\entity\Living;
|
use pocketmine\entity\Living;
|
||||||
use pocketmine\event\entity\EntityDamageByBlockEvent;
|
use pocketmine\event\entity\EntityDamageByBlockEvent;
|
||||||
@ -35,11 +36,11 @@ use pocketmine\item\VanillaItems;
|
|||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\player\Player;
|
use pocketmine\player\Player;
|
||||||
use pocketmine\world\BlockTransaction;
|
|
||||||
use function mt_rand;
|
use function mt_rand;
|
||||||
|
|
||||||
class SweetBerryBush extends Flowable{
|
class SweetBerryBush extends Flowable{
|
||||||
use AgeableTrait;
|
use AgeableTrait;
|
||||||
|
use StaticSupportTrait;
|
||||||
|
|
||||||
public const STAGE_SAPLING = 0;
|
public const STAGE_SAPLING = 0;
|
||||||
public const STAGE_BUSH_NO_BERRIES = 1;
|
public const STAGE_BUSH_NO_BERRIES = 1;
|
||||||
@ -56,16 +57,17 @@ class SweetBerryBush extends Flowable{
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
protected function canBeSupportedBy(Block $block) : bool{
|
protected function canBeSupportedBy(Block $block) : bool{
|
||||||
return $block->getTypeId() !== BlockTypeIds::FARMLAND && //bedrock-specific thing (bug?)
|
return $block->getTypeId() !== BlockTypeIds::FARMLAND && //bedrock-specific thing (bug?)
|
||||||
($block->hasTypeTag(BlockTypeTags::DIRT) || $block->hasTypeTag(BlockTypeTags::MUD));
|
($block->hasTypeTag(BlockTypeTags::DIRT) || $block->hasTypeTag(BlockTypeTags::MUD));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
if(!$this->canBeSupportedBy($blockReplace->getSide(Facing::DOWN))){
|
$supportBlock = $block->getSide(Facing::DOWN);
|
||||||
return false;
|
return $this->canBeSupportedBy($supportBlock);
|
||||||
}
|
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
||||||
@ -99,12 +101,6 @@ class SweetBerryBush extends Flowable{
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
|
||||||
if(!$this->canBeSupportedBy($this->getSide(Facing::DOWN))){
|
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ticksRandomly() : bool{
|
public function ticksRandomly() : bool{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -23,31 +23,16 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\block\utils\TallGrassTrait;
|
use pocketmine\block\utils\TallGrassTrait;
|
||||||
use pocketmine\item\Item;
|
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
|
||||||
use pocketmine\player\Player;
|
|
||||||
use pocketmine\world\BlockTransaction;
|
|
||||||
|
|
||||||
class TallGrass extends Flowable{
|
class TallGrass extends Flowable{
|
||||||
use TallGrassTrait;
|
use TallGrassTrait;
|
||||||
|
use StaticSupportTrait;
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
return $block->hasTypeTag(BlockTypeTags::DIRT) || $block->hasTypeTag(BlockTypeTags::MUD);
|
$supportBlock = $block->getSide(Facing::DOWN);
|
||||||
}
|
return $supportBlock->hasTypeTag(BlockTypeTags::DIRT) || $supportBlock->hasTypeTag(BlockTypeTags::MUD);
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
|
||||||
if($this->canBeSupportedBy($this->getSide(Facing::DOWN))){
|
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
|
||||||
if(!$this->canBeSupportedBy($this->getSide(Facing::DOWN))){ //Replace with common break method
|
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,14 +23,15 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\item\Item;
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\player\Player;
|
|
||||||
use pocketmine\world\BlockTransaction;
|
|
||||||
|
|
||||||
class WaterLily extends Flowable{
|
class WaterLily extends Flowable{
|
||||||
|
use StaticSupportTrait {
|
||||||
|
canBePlacedAt as supportedWhenPlacedAt;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return AxisAlignedBB[]
|
* @return AxisAlignedBB[]
|
||||||
@ -40,23 +41,10 @@ class WaterLily extends Flowable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{
|
public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{
|
||||||
return !$blockReplace instanceof Water && parent::canBePlacedAt($blockReplace, $clickVector, $face, $isClickedBlock);
|
return !$blockReplace instanceof Water && $this->supportedWhenPlacedAt($blockReplace, $clickVector, $face, $isClickedBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
return $block instanceof Water;
|
return $block->getSide(Facing::DOWN) instanceof Water;
|
||||||
}
|
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
|
||||||
if(!$this->canBeSupportedBy($blockReplace->getSide(Facing::DOWN))){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
|
||||||
if(!$this->canBeSupportedBy($this->getSide(Facing::DOWN))){
|
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,23 +23,22 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\block\utils\StaticSupportTrait;
|
||||||
use pocketmine\entity\effect\EffectInstance;
|
use pocketmine\entity\effect\EffectInstance;
|
||||||
use pocketmine\entity\effect\VanillaEffects;
|
use pocketmine\entity\effect\VanillaEffects;
|
||||||
use pocketmine\entity\Entity;
|
use pocketmine\entity\Entity;
|
||||||
use pocketmine\entity\Living;
|
use pocketmine\entity\Living;
|
||||||
use pocketmine\item\Item;
|
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
|
||||||
use pocketmine\player\Player;
|
|
||||||
use pocketmine\world\BlockTransaction;
|
|
||||||
|
|
||||||
class WitherRose extends Flowable{
|
class WitherRose extends Flowable{
|
||||||
|
use StaticSupportTrait;
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
|
$supportBlock = $block->getSide(Facing::DOWN);
|
||||||
return
|
return
|
||||||
$block->hasTypeTag(BlockTypeTags::DIRT) ||
|
$supportBlock->hasTypeTag(BlockTypeTags::DIRT) ||
|
||||||
$block->hasTypeTag(BlockTypeTags::MUD) ||
|
$supportBlock->hasTypeTag(BlockTypeTags::MUD) ||
|
||||||
match($block->getTypeId()){
|
match($supportBlock->getTypeId()){
|
||||||
BlockTypeIds::NETHERRACK,
|
BlockTypeIds::NETHERRACK,
|
||||||
BlockTypeIds::SOUL_SAND,
|
BlockTypeIds::SOUL_SAND,
|
||||||
BlockTypeIds::SOUL_SOIL => true,
|
BlockTypeIds::SOUL_SOIL => true,
|
||||||
@ -47,19 +46,6 @@ class WitherRose extends Flowable{
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
|
||||||
if(!$this->canBeSupportedBy($this->getSide(Facing::DOWN))){
|
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
|
||||||
if(!$this->canBeSupportedBy($blockReplace->getSide(Facing::DOWN))){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function hasEntityCollision() : bool{ return true; }
|
public function hasEntityCollision() : bool{ return true; }
|
||||||
|
|
||||||
public function onEntityInside(Entity $entity) : bool{
|
public function onEntityInside(Entity $entity) : bool{
|
||||||
|
57
src/block/utils/StaticSupportTrait.php
Normal file
57
src/block/utils/StaticSupportTrait.php
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
use pocketmine\block\Block;
|
||||||
|
use pocketmine\math\Vector3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used by blocks which always have the same support requirements no matter what state they are in.
|
||||||
|
* Prevents placement if support isn't available, and automatically destroys itself if support is removed.
|
||||||
|
*/
|
||||||
|
trait StaticSupportTrait{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implement this to define the block's support requirements.
|
||||||
|
*/
|
||||||
|
abstract private function canBeSupportedAt(Block $block) : bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Block::canBePlacedAt()
|
||||||
|
*/
|
||||||
|
public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{
|
||||||
|
return $this->canBeSupportedAt($blockReplace) && parent::canBePlacedAt($blockReplace, $clickVector, $face, $isClickedBlock);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Block::onNearbyBlockChange()
|
||||||
|
*/
|
||||||
|
public function onNearbyBlockChange() : void{
|
||||||
|
if(!$this->canBeSupportedAt($this)){
|
||||||
|
$this->position->getWorld()->useBreakOn($this->position);
|
||||||
|
}else{
|
||||||
|
parent::onNearbyBlockChange();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user