Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6161 implement interface common block properties #6383

Draft
wants to merge 7 commits into
base: minor-next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/block/AmethystCluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
use pocketmine\utils\AssumptionFailedError;
use pocketmine\world\BlockTransaction;

final class AmethystCluster extends Transparent{
final class AmethystCluster extends Transparent implements FacingInterface{
use AmethystTrait;
use AnyFacingTrait;

Expand Down
37 changes: 37 additions & 0 deletions src/block/FacingInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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;

interface FacingInterface {

/**
* Get the current facing direction of the block
*/
public function getFacing() : int;

/**
* Set the current facing direction of the block
*/
public function setFacing(int $facing) : object;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its block not object

}
2 changes: 1 addition & 1 deletion src/block/Hopper.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;

class Hopper extends Transparent{
class Hopper extends Transparent implements FacingInterface{
use PoweredByRedstoneTrait;

private int $facing = Facing::DOWN;
Expand Down
2 changes: 1 addition & 1 deletion src/block/MobHead.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
use function assert;
use function floor;

class MobHead extends Flowable{
class MobHead extends Flowable implements FacingInterface{
public const MIN_ROTATION = 0;
public const MAX_ROTATION = 15;

Expand Down
2 changes: 1 addition & 1 deletion src/block/Stem.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
use function array_rand;
use function mt_rand;

abstract class Stem extends Crops{
abstract class Stem extends Crops implements FacingInterface{
protected int $facing = Facing::UP;

protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
Expand Down
2 changes: 1 addition & 1 deletion src/block/Torch.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;

class Torch extends Flowable{
class Torch extends Flowable implements FacingInterface{

protected int $facing = Facing::UP;

Expand Down
8 changes: 6 additions & 2 deletions src/block/tile/Bell.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@

namespace pocketmine\block\tile;

use pocketmine\block\FacingInterface;
use pocketmine\math\Facing;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\protocol\BlockActorDataPacket;
use pocketmine\network\mcpe\protocol\types\BlockPosition;
use pocketmine\network\mcpe\protocol\types\CacheableNbt;
use pocketmine\utils\AssumptionFailedError;

final class Bell extends Spawnable{
final class Bell extends Spawnable implements FacingInterface{
public const TAG_DIRECTION = "Direction"; //TAG_Int
public const TAG_RINGING = "Ringing"; //TAG_Byte
public const TAG_TICKS = "Ticks"; //TAG_Int
Expand All @@ -45,7 +46,10 @@ public function setRinging(bool $ringing) : void{ $this->ringing = $ringing; }

public function getFacing() : int{ return $this->facing; }

public function setFacing(int $facing) : void{ $this->facing = $facing; }
public function setFacing(int $facing) : self {
$this->facing = $facing;
return $this;
}

public function getTicks() : int{ return $this->ticks; }

Expand Down
6 changes: 4 additions & 2 deletions src/block/tile/ShulkerBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@

namespace pocketmine\block\tile;

use pocketmine\block\FacingInterface;
use pocketmine\block\inventory\ShulkerBoxInventory;
use pocketmine\item\Item;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\world\World;

class ShulkerBox extends Spawnable implements Container, Nameable{
class ShulkerBox extends Spawnable implements Container, Nameable, FacingInterface{
use NameableTrait {
addAdditionalSpawnData as addNameSpawnData;
}
Expand Down Expand Up @@ -89,8 +90,9 @@ public function getFacing() : int{
return $this->facing;
}

public function setFacing(int $facing) : void{
public function setFacing(int $facing) : self {
$this->facing = $facing;
return $this;
}

public function getInventory() : ShulkerBoxInventory{
Expand Down
8 changes: 7 additions & 1 deletion src/entity/object/Painting.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace pocketmine\entity\object;

use pocketmine\block\FacingInterface;
use pocketmine\block\VanillaBlocks;
use pocketmine\entity\Entity;
use pocketmine\entity\EntitySizeInfo;
Expand All @@ -40,7 +41,7 @@
use pocketmine\world\World;
use function ceil;

class Painting extends Entity{
class Painting extends Entity implements FacingInterface{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Design error, you're using an interface made for blocks in an entity, I don't think you should do that

public const TAG_TILE_X = "TileX"; //TAG_Int
public const TAG_TILE_Y = "TileY"; //TAG_Int
public const TAG_TILE_Z = "TileZ"; //TAG_Int
Expand Down Expand Up @@ -176,6 +177,11 @@ public function getFacing() : int{
return $this->facing;
}

public function setFacing(int $facing) : self {
$this->facing = $facing;
return $this;
}

/**
* Returns the bounding-box a painting with the specified motive would have at the given position and direction.
*/
Expand Down