Separate facing/bearing handling from Vector3, deobfusticate a ton of @shoghicp old code

This commit is contained in:
Dylan K. Taylor 2018-09-05 19:56:14 +01:00
parent 99fb267333
commit f218868338
57 changed files with 338 additions and 384 deletions

View File

@ -31,7 +31,7 @@
"pocketmine/spl": "^0.3.0", "pocketmine/spl": "^0.3.0",
"pocketmine/binaryutils": "^0.1.0", "pocketmine/binaryutils": "^0.1.0",
"pocketmine/nbt": "^0.2.1", "pocketmine/nbt": "^0.2.1",
"pocketmine/math": "^0.2.0", "pocketmine/math": "dev-master",
"pocketmine/snooze": "^0.1.0" "pocketmine/snooze": "^0.1.0"
}, },
"autoload": { "autoload": {

17
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "9ff16274822f181c2ed533797d2e22f7", "content-hash": "cef68cbc2596130f6b20e6f2ecdfd58d",
"packages": [ "packages": [
{ {
"name": "fgrosse/phpasn1", "name": "fgrosse/phpasn1",
@ -183,16 +183,16 @@
}, },
{ {
"name": "pocketmine/math", "name": "pocketmine/math",
"version": "0.2.1", "version": "dev-master",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/pmmp/Math.git", "url": "https://github.com/pmmp/Math.git",
"reference": "ee299f5c9c444ca526c9c691b920f321458cf0b6" "reference": "ec66eaa959b86ec3d3d22084a534ae466910aabe"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/pmmp/Math/zipball/ee299f5c9c444ca526c9c691b920f321458cf0b6", "url": "https://api.github.com/repos/pmmp/Math/zipball/ec66eaa959b86ec3d3d22084a534ae466910aabe",
"reference": "ee299f5c9c444ca526c9c691b920f321458cf0b6", "reference": "ec66eaa959b86ec3d3d22084a534ae466910aabe",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -210,10 +210,10 @@
], ],
"description": "PHP library containing math related code used in PocketMine-MP", "description": "PHP library containing math related code used in PocketMine-MP",
"support": { "support": {
"source": "https://github.com/pmmp/Math/tree/0.2.1", "source": "https://github.com/pmmp/Math/tree/master",
"issues": "https://github.com/pmmp/Math/issues" "issues": "https://github.com/pmmp/Math/issues"
}, },
"time": "2018-08-15T15:43:27+00:00" "time": "2018-09-05T18:50:26+00:00"
}, },
{ {
"name": "pocketmine/nbt", "name": "pocketmine/nbt",
@ -367,7 +367,8 @@
"aliases": [], "aliases": [],
"minimum-stability": "stable", "minimum-stability": "stable",
"stability-flags": { "stability-flags": {
"ext-pthreads": 20 "ext-pthreads": 20,
"pocketmine/math": 20
}, },
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,

View File

@ -27,6 +27,7 @@ use pocketmine\inventory\AnvilInventory;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\TieredTool; use pocketmine\item\TieredTool;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Bearing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -94,7 +95,7 @@ class Anvil extends Fallable{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$direction = ($player !== null ? $player->getDirection() : 0) & 0x03; $direction = $player !== null ? Bearing::rotate($player->getDirection(), -1) : 0;
$this->meta = $this->getVariant() | $direction; $this->meta = $this->getVariant() | $direction;
return $this->getLevel()->setBlock($blockReplace, $this, true, true); return $this->getLevel()->setBlock($blockReplace, $this, true, true);
} }

View File

@ -28,6 +28,8 @@ use pocketmine\item\ItemFactory;
use pocketmine\lang\TranslationContainer; use pocketmine\lang\TranslationContainer;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Bearing;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\tile\Bed as TileBed; use pocketmine\tile\Bed as TileBed;
@ -90,26 +92,9 @@ class Bed extends Transparent{
* @return int * @return int
*/ */
public static function getOtherHalfSide(int $meta, bool $isHead = false) : int{ public static function getOtherHalfSide(int $meta, bool $isHead = false) : int{
$rotation = $meta & 0x03; $side = Bearing::toFacing($meta & 0x03);
$side = -1;
switch($rotation){
case 0x00: //South
$side = Vector3::SIDE_SOUTH;
break;
case 0x01: //West
$side = Vector3::SIDE_WEST;
break;
case 0x02: //North
$side = Vector3::SIDE_NORTH;
break;
case 0x03: //East
$side = Vector3::SIDE_EAST;
break;
}
if($isHead){ if($isHead){
$side = Vector3::getOppositeSide($side); $side = Facing::opposite($side);
} }
return $side; return $side;
@ -165,11 +150,11 @@ class Bed extends Transparent{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN); $down = $this->getSide(Facing::DOWN);
if(!$down->isTransparent()){ if(!$down->isTransparent()){
$meta = (($player instanceof Player ? $player->getDirection() : 0) - 1) & 0x03; $meta = $player instanceof Player ? Bearing::rotate($player->getDirection(), 2) : 0; //rotate 180 degrees
$next = $this->getSide(self::getOtherHalfSide($meta)); $next = $this->getSide(self::getOtherHalfSide($meta));
if($next->canBeReplaced() and !$next->getSide(Vector3::SIDE_DOWN)->isTransparent()){ if($next->canBeReplaced() and !$next->getSide(Facing::DOWN)->isTransparent()){
$this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->id, $meta), true, true); $this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->id, $meta), true, true);
$this->getLevel()->setBlock($next, BlockFactory::get($this->id, $meta | self::BITFLAG_HEAD), true, true); $this->getLevel()->setBlock($next, BlockFactory::get($this->id, $meta | self::BITFLAG_HEAD), true, true);

View File

@ -32,6 +32,7 @@ use pocketmine\item\Item;
use pocketmine\item\ItemFactory; use pocketmine\item\ItemFactory;
use pocketmine\level\Position; use pocketmine\level\Position;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\RayTraceResult; use pocketmine\math\RayTraceResult;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\metadata\Metadatable; use pocketmine\metadata\Metadatable;
@ -588,10 +589,10 @@ class Block extends Position implements BlockIds, Metadatable{
*/ */
public function getHorizontalSides() : array{ public function getHorizontalSides() : array{
return [ return [
$this->getSide(Vector3::SIDE_NORTH), $this->getSide(Facing::NORTH),
$this->getSide(Vector3::SIDE_SOUTH), $this->getSide(Facing::SOUTH),
$this->getSide(Vector3::SIDE_WEST), $this->getSide(Facing::WEST),
$this->getSide(Vector3::SIDE_EAST) $this->getSide(Facing::EAST)
]; ];
} }
@ -603,8 +604,8 @@ class Block extends Position implements BlockIds, Metadatable{
public function getAllSides() : array{ public function getAllSides() : array{
return array_merge( return array_merge(
[ [
$this->getSide(Vector3::SIDE_DOWN), $this->getSide(Facing::DOWN),
$this->getSide(Vector3::SIDE_UP) $this->getSide(Facing::UP)
], ],
$this->getHorizontalSides() $this->getHorizontalSides()
); );

View File

@ -25,6 +25,7 @@ namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\TieredTool; use pocketmine\item\TieredTool;
use pocketmine\math\Bearing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\tile\Furnace as TileFurnace; use pocketmine\tile\Furnace as TileFurnace;
@ -61,13 +62,9 @@ class BurningFurnace extends Solid{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$faces = [ if($player !== null){
0 => 4, $this->meta = Bearing::toFacing($player->getDirection());
1 => 2, }
2 => 5,
3 => 3
];
$this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0];
$this->getLevel()->setBlock($blockReplace, $this, true, true); $this->getLevel()->setBlock($blockReplace, $this, true, true);
Tile::createTile(Tile::FURNACE, $this->getLevel(), TileFurnace::createNBT($this, $face, $item, $player)); Tile::createTile(Tile::FURNACE, $this->getLevel(), TileFurnace::createNBT($this, $face, $item, $player));

View File

@ -29,6 +29,7 @@ use pocketmine\event\entity\EntityDamageByBlockEvent;
use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\Server; use pocketmine\Server;
@ -64,7 +65,7 @@ class Cactus extends Transparent{
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
$down = $this->getSide(Vector3::SIDE_DOWN); $down = $this->getSide(Facing::DOWN);
if($down->getId() !== self::SAND and $down->getId() !== self::CACTUS){ if($down->getId() !== self::SAND and $down->getId() !== self::CACTUS){
$this->getLevel()->useBreakOn($this); $this->getLevel()->useBreakOn($this);
}else{ }else{
@ -83,7 +84,7 @@ class Cactus extends Transparent{
} }
public function onRandomTick() : void{ public function onRandomTick() : void{
if($this->getSide(Vector3::SIDE_DOWN)->getId() !== self::CACTUS){ if($this->getSide(Facing::DOWN)->getId() !== self::CACTUS){
if($this->meta === 0x0f){ if($this->meta === 0x0f){
for($y = 1; $y < 3; ++$y){ for($y = 1; $y < 3; ++$y){
$b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z); $b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z);
@ -104,12 +105,12 @@ class Cactus extends Transparent{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN); $down = $this->getSide(Facing::DOWN);
if($down->getId() === self::SAND or $down->getId() === self::CACTUS){ if($down->getId() === self::SAND or $down->getId() === self::CACTUS){
$block0 = $this->getSide(Vector3::SIDE_NORTH); $block0 = $this->getSide(Facing::NORTH);
$block1 = $this->getSide(Vector3::SIDE_SOUTH); $block1 = $this->getSide(Facing::SOUTH);
$block2 = $this->getSide(Vector3::SIDE_WEST); $block2 = $this->getSide(Facing::WEST);
$block3 = $this->getSide(Vector3::SIDE_EAST); $block3 = $this->getSide(Facing::EAST);
if(!$block0->isSolid() and !$block1->isSolid() and !$block2->isSolid() and !$block3->isSolid()){ if(!$block0->isSolid() and !$block1->isSolid() and !$block2->isSolid() and !$block3->isSolid()){
$this->getLevel()->setBlock($this, $this, true); $this->getLevel()->setBlock($this, $this, true);

View File

@ -28,6 +28,7 @@ use pocketmine\entity\Living;
use pocketmine\item\FoodSource; use pocketmine\item\FoodSource;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -61,7 +62,7 @@ class Cake extends Transparent implements FoodSource{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN); $down = $this->getSide(Facing::DOWN);
if($down->getId() !== self::AIR){ if($down->getId() !== self::AIR){
$this->getLevel()->setBlock($blockReplace, $this, true, true); $this->getLevel()->setBlock($blockReplace, $this, true, true);
@ -72,7 +73,7 @@ class Cake extends Transparent implements FoodSource{
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){ //Replace with common break method if($this->getSide(Facing::DOWN)->getId() === self::AIR){ //Replace with common break method
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true); $this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true);
} }
} }

View File

@ -26,6 +26,7 @@ namespace pocketmine\block;
use pocketmine\block\utils\ColorBlockMetaHelper; use pocketmine\block\utils\ColorBlockMetaHelper;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -54,7 +55,7 @@ class Carpet extends Flowable{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN); $down = $this->getSide(Facing::DOWN);
if($down->getId() !== self::AIR){ if($down->getId() !== self::AIR){
$this->getLevel()->setBlock($blockReplace, $this, true, true); $this->getLevel()->setBlock($blockReplace, $this, true, true);
@ -65,7 +66,7 @@ class Carpet extends Flowable{
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){ if($this->getSide(Facing::DOWN)->getId() === self::AIR){
$this->getLevel()->useBreakOn($this); $this->getLevel()->useBreakOn($this);
} }
} }

View File

@ -25,6 +25,8 @@ namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Bearing;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\tile\Chest as TileChest; use pocketmine\tile\Chest as TileChest;
@ -56,22 +58,15 @@ class Chest extends Transparent{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$faces = [
0 => 4,
1 => 2,
2 => 5,
3 => 3
];
$chest = null; $chest = null;
$this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0]; if($player !== null){
$this->meta = Bearing::toFacing($player->getDirection());
}
for($side = 2; $side <= 5; ++$side){ foreach([
if(($this->meta === 4 or $this->meta === 5) and ($side === 4 or $side === 5)){ Bearing::toFacing(Bearing::rotate($player->getDirection(), -1)),
continue; Bearing::toFacing(Bearing::rotate($player->getDirection(), 1))
}elseif(($this->meta === 3 or $this->meta === 2) and ($side === 2 or $side === 3)){ ] as $side){
continue;
}
$c = $this->getSide($side); $c = $this->getSide($side);
if($c->getId() === $this->id and $c->getDamage() === $this->meta){ if($c->getId() === $this->id and $c->getDamage() === $this->meta){
$tile = $this->getLevel()->getTile($c); $tile = $this->getLevel()->getTile($c);
@ -105,8 +100,8 @@ class Chest extends Transparent{
} }
if( if(
!$this->getSide(Vector3::SIDE_UP)->isTransparent() or !$this->getSide(Facing::UP)->isTransparent() or
($chest->isPaired() and !$chest->getPair()->getBlock()->getSide(Vector3::SIDE_UP)->isTransparent()) or ($chest->isPaired() and !$chest->getPair()->getBlock()->getSide(Facing::UP)->isTransparent()) or
!$chest->canOpenWith($item->getCustomName()) !$chest->canOpenWith($item->getCustomName())
){ ){
return true; return true;

View File

@ -25,7 +25,7 @@ namespace pocketmine\block;
use pocketmine\item\TieredTool; use pocketmine\item\TieredTool;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3; use pocketmine\math\Facing;
class CobblestoneWall extends Transparent{ class CobblestoneWall extends Transparent{
public const NONE_MOSSY_WALL = 0; public const NONE_MOSSY_WALL = 0;
@ -60,14 +60,14 @@ class CobblestoneWall extends Transparent{
protected function recalculateBoundingBox() : ?AxisAlignedBB{ protected function recalculateBoundingBox() : ?AxisAlignedBB{
//walls don't have any special collision boxes like fences do //walls don't have any special collision boxes like fences do
$north = $this->canConnect($this->getSide(Vector3::SIDE_NORTH)); $north = $this->canConnect($this->getSide(Facing::NORTH));
$south = $this->canConnect($this->getSide(Vector3::SIDE_SOUTH)); $south = $this->canConnect($this->getSide(Facing::SOUTH));
$west = $this->canConnect($this->getSide(Vector3::SIDE_WEST)); $west = $this->canConnect($this->getSide(Facing::WEST));
$east = $this->canConnect($this->getSide(Vector3::SIDE_EAST)); $east = $this->canConnect($this->getSide(Facing::EAST));
$inset = 0.25; $inset = 0.25;
if( if(
$this->getSide(Vector3::SIDE_UP)->getId() === Block::AIR and //if there is a block on top, it stays as a post $this->getSide(Facing::UP)->getId() === Block::AIR and //if there is a block on top, it stays as a post
( (
($north and $south and !$west and !$east) or ($north and $south and !$west and !$east) or
(!$north and !$south and $west and $east) (!$north and !$south and $west and $east)

View File

@ -25,6 +25,7 @@ namespace pocketmine\block;
use pocketmine\event\block\BlockGrowEvent; use pocketmine\event\block\BlockGrowEvent;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\Server; use pocketmine\Server;
@ -32,7 +33,7 @@ use pocketmine\Server;
abstract class Crops extends Flowable{ abstract class Crops extends Flowable{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($blockReplace->getSide(Vector3::SIDE_DOWN)->getId() === Block::FARMLAND){ if($blockReplace->getSide(Facing::DOWN)->getId() === Block::FARMLAND){
$this->getLevel()->setBlock($blockReplace, $this, true, true); $this->getLevel()->setBlock($blockReplace, $this, true, true);
return true; return true;
@ -65,7 +66,7 @@ abstract class Crops extends Flowable{
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->getId() !== Block::FARMLAND){ if($this->getSide(Facing::DOWN)->getId() !== Block::FARMLAND){
$this->getLevel()->useBreakOn($this); $this->getLevel()->useBreakOn($this);
} }
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -41,7 +42,7 @@ class Dandelion extends Flowable{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN); $down = $this->getSide(Facing::DOWN);
if($down->getId() === Block::GRASS or $down->getId() === Block::DIRT or $down->getId() === Block::FARMLAND){ if($down->getId() === Block::GRASS or $down->getId() === Block::DIRT or $down->getId() === Block::FARMLAND){
$this->getLevel()->setBlock($blockReplace, $this, true, true); $this->getLevel()->setBlock($blockReplace, $this, true, true);
@ -52,7 +53,7 @@ class Dandelion extends Flowable{
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){ if($this->getSide(Facing::DOWN)->isTransparent()){
$this->getLevel()->useBreakOn($this); $this->getLevel()->useBreakOn($this);
} }
} }

View File

@ -25,6 +25,7 @@ namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory; use pocketmine\item\ItemFactory;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -41,7 +42,7 @@ class DeadBush extends Flowable{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if(!$this->getSide(Vector3::SIDE_DOWN)->isTransparent()){ if(!$this->getSide(Facing::DOWN)->isTransparent()){
return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player);
} }
@ -49,7 +50,7 @@ class DeadBush extends Flowable{
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){ if($this->getSide(Facing::DOWN)->isTransparent()){
$this->getLevel()->useBreakOn($this); $this->getLevel()->useBreakOn($this);
} }
} }

View File

@ -26,6 +26,8 @@ namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\level\sound\DoorSound; use pocketmine\level\sound\DoorSound;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Bearing;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -41,11 +43,11 @@ abstract class Door extends Transparent{
$isUp = ($damage & 0x08) > 0; $isUp = ($damage & 0x08) > 0;
if($isUp){ if($isUp){
$down = $this->getSide(Vector3::SIDE_DOWN)->getDamage(); $down = $this->getSide(Facing::DOWN)->getDamage();
$up = $damage; $up = $damage;
}else{ }else{
$down = $damage; $down = $damage;
$up = $this->getSide(Vector3::SIDE_UP)->getDamage(); $up = $this->getSide(Facing::UP)->getDamage();
} }
$isRight = ($up & 0x01) > 0; $isRight = ($up & 0x01) > 0;
@ -109,36 +111,33 @@ abstract class Door extends Transparent{
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){ //Replace with common break method if($this->getSide(Facing::DOWN)->getId() === self::AIR){ //Replace with common break method
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), false); $this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), false);
if($this->getSide(Vector3::SIDE_UP) instanceof Door){ if($this->getSide(Facing::UP) instanceof Door){
$this->getLevel()->setBlock($this->getSide(Vector3::SIDE_UP), BlockFactory::get(Block::AIR), false); $this->getLevel()->setBlock($this->getSide(Facing::UP), BlockFactory::get(Block::AIR), false);
} }
} }
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($face === Vector3::SIDE_UP){ if($face === Facing::UP){
$blockUp = $this->getSide(Vector3::SIDE_UP); $blockUp = $this->getSide(Facing::UP);
$blockDown = $this->getSide(Vector3::SIDE_DOWN); $blockDown = $this->getSide(Facing::DOWN);
if(!$blockUp->canBeReplaced() or $blockDown->isTransparent()){ if(!$blockUp->canBeReplaced() or $blockDown->isTransparent()){
return false; return false;
} }
$direction = $player instanceof Player ? $player->getDirection() : 0;
$faces = [ $ccw = Bearing::toFacing($player instanceof Player ? Bearing::rotate($player->getDirection(), -1) : Facing::EAST);
0 => 3,
1 => 4, $next = $this->getSide(Facing::opposite($ccw));
2 => 2, $next2 = $this->getSide($ccw);
3 => 5
];
$next = $this->getSide($faces[($direction + 2) % 4]);
$next2 = $this->getSide($faces[$direction]);
$metaUp = 0x08; $metaUp = 0x08;
if($next->getId() === $this->getId() or (!$next2->isTransparent() and $next->isTransparent())){ //Door hinge if($next->getId() === $this->getId() or (!$next2->isTransparent() and $next->isTransparent())){ //Door hinge
$metaUp |= 0x01; $metaUp |= 0x01;
} }
$this->setDamage($player->getDirection() & 0x03); $this->setDamage(Bearing::rotate($player->getDirection(), -1));
$this->getLevel()->setBlock($blockReplace, $this, true, true); //Bottom $this->getLevel()->setBlock($blockReplace, $this, true, true); //Bottom
$this->getLevel()->setBlock($blockUp, BlockFactory::get($this->getId(), $metaUp), true); //Top $this->getLevel()->setBlock($blockUp, BlockFactory::get($this->getId(), $metaUp), true); //Top
return true; return true;
@ -149,7 +148,7 @@ abstract class Door extends Transparent{
public function onActivate(Item $item, Player $player = null) : bool{ public function onActivate(Item $item, Player $player = null) : bool{
if(($this->getDamage() & 0x08) === 0x08){ //Top if(($this->getDamage() & 0x08) === 0x08){ //Top
$down = $this->getSide(Vector3::SIDE_DOWN); $down = $this->getSide(Facing::DOWN);
if($down->getId() === $this->getId()){ if($down->getId() === $this->getId()){
$meta = $down->getDamage() ^ 0x04; $meta = $down->getDamage() ^ 0x04;
$this->level->setBlock($down, BlockFactory::get($this->getId(), $meta), true); $this->level->setBlock($down, BlockFactory::get($this->getId(), $meta), true);
@ -185,12 +184,12 @@ abstract class Door extends Transparent{
public function getAffectedBlocks() : array{ public function getAffectedBlocks() : array{
if(($this->getDamage() & 0x08) === 0x08){ if(($this->getDamage() & 0x08) === 0x08){
$down = $this->getSide(Vector3::SIDE_DOWN); $down = $this->getSide(Facing::DOWN);
if($down->getId() === $this->getId()){ if($down->getId() === $this->getId()){
return [$this, $down]; return [$this, $down];
} }
}else{ }else{
$up = $this->getSide(Vector3::SIDE_UP); $up = $this->getSide(Facing::UP);
if($up->getId() === $this->getId()){ if($up->getId() === $this->getId()){
return [$this, $up]; return [$this, $up];
} }

View File

@ -25,6 +25,7 @@ namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory; use pocketmine\item\ItemFactory;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -54,10 +55,10 @@ class DoublePlant extends Flowable{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$id = $blockReplace->getSide(Vector3::SIDE_DOWN)->getId(); $id = $blockReplace->getSide(Facing::DOWN)->getId();
if(($id === Block::GRASS or $id === Block::DIRT) and $blockReplace->getSide(Vector3::SIDE_UP)->canBeReplaced()){ if(($id === Block::GRASS or $id === Block::DIRT) and $blockReplace->getSide(Facing::UP)->canBeReplaced()){
$this->getLevel()->setBlock($blockReplace, $this, false, false); $this->getLevel()->setBlock($blockReplace, $this, false, false);
$this->getLevel()->setBlock($blockReplace->getSide(Vector3::SIDE_UP), BlockFactory::get($this->id, $this->meta | self::BITFLAG_TOP), false, false); $this->getLevel()->setBlock($blockReplace->getSide(Facing::UP), BlockFactory::get($this->id, $this->meta | self::BITFLAG_TOP), false, false);
return true; return true;
} }
@ -71,9 +72,9 @@ class DoublePlant extends Flowable{
*/ */
public function isValidHalfPlant() : bool{ public function isValidHalfPlant() : bool{
if($this->meta & self::BITFLAG_TOP){ if($this->meta & self::BITFLAG_TOP){
$other = $this->getSide(Vector3::SIDE_DOWN); $other = $this->getSide(Facing::DOWN);
}else{ }else{
$other = $this->getSide(Vector3::SIDE_UP); $other = $this->getSide(Facing::UP);
} }
return ( return (
@ -84,7 +85,7 @@ class DoublePlant extends Flowable{
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
if(!$this->isValidHalfPlant() or (($this->meta & self::BITFLAG_TOP) === 0 and $this->getSide(Vector3::SIDE_DOWN)->isTransparent())){ if(!$this->isValidHalfPlant() or (($this->meta & self::BITFLAG_TOP) === 0 and $this->getSide(Facing::DOWN)->isTransparent())){
$this->getLevel()->useBreakOn($this); $this->getLevel()->useBreakOn($this);
} }
} }
@ -119,7 +120,7 @@ class DoublePlant extends Flowable{
public function getAffectedBlocks() : array{ public function getAffectedBlocks() : array{
if($this->isValidHalfPlant()){ if($this->isValidHalfPlant()){
return [$this, $this->getSide(($this->meta & self::BITFLAG_TOP) !== 0 ? Vector3::SIDE_DOWN : Vector3::SIDE_UP)]; return [$this, $this->getSide(($this->meta & self::BITFLAG_TOP) !== 0 ? Facing::DOWN : Facing::UP)];
} }
return parent::getAffectedBlocks(); return parent::getAffectedBlocks();

View File

@ -25,6 +25,7 @@ namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -41,7 +42,7 @@ class EndRod extends Flowable{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($face === Vector3::SIDE_UP or $face === Vector3::SIDE_DOWN){ if(Facing::axis($face) === Facing::AXIS_Y){
$this->meta = $face; $this->meta = $face;
}else{ }else{
$this->meta = $face ^ 0x01; $this->meta = $face ^ 0x01;
@ -62,11 +63,11 @@ class EndRod extends Flowable{
} }
protected function recalculateBoundingBox() : ?AxisAlignedBB{ protected function recalculateBoundingBox() : ?AxisAlignedBB{
$m = $this->meta & ~0x01; $m = $this->meta >> 1; //everything except up/down are inverted, but we can still use this for axis
$width = 0.375; $width = 0.375;
switch($m){ switch($m){
case 0x00: //up/down case Facing::AXIS_Y:
return new AxisAlignedBB( return new AxisAlignedBB(
$width, $width,
0, 0,
@ -75,7 +76,7 @@ class EndRod extends Flowable{
1, 1,
1 - $width 1 - $width
); );
case 0x02: //north/south case Facing::AXIS_Z:
return new AxisAlignedBB( return new AxisAlignedBB(
0, 0,
$width, $width,
@ -84,7 +85,7 @@ class EndRod extends Flowable{
1 - $width, 1 - $width,
1 - $width 1 - $width
); );
case 0x04: //east/west case Facing::AXIS_X:
return new AxisAlignedBB( return new AxisAlignedBB(
$width, $width,
$width, $width,

View File

@ -26,6 +26,8 @@ namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory; use pocketmine\item\ItemFactory;
use pocketmine\item\TieredTool; use pocketmine\item\TieredTool;
use pocketmine\math\Bearing;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\tile\EnderChest as TileEnderChest; use pocketmine\tile\EnderChest as TileEnderChest;
@ -60,14 +62,9 @@ class EnderChest extends Chest{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$faces = [ if($player !== null){
0 => 4, $this->meta = Bearing::toFacing($player->getDirection());
1 => 2, }
2 => 5,
3 => 3
];
$this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0];
$this->getLevel()->setBlock($blockReplace, $this, true, true); $this->getLevel()->setBlock($blockReplace, $this, true, true);
Tile::createTile(Tile::ENDER_CHEST, $this->getLevel(), TileEnderChest::createNBT($this, $face, $item, $player)); Tile::createTile(Tile::ENDER_CHEST, $this->getLevel(), TileEnderChest::createNBT($this, $face, $item, $player));
@ -86,7 +83,7 @@ class EnderChest extends Chest{
$enderChest = Tile::createTile(Tile::ENDER_CHEST, $this->getLevel(), TileEnderChest::createNBT($this)); $enderChest = Tile::createTile(Tile::ENDER_CHEST, $this->getLevel(), TileEnderChest::createNBT($this));
} }
if(!$this->getSide(Vector3::SIDE_UP)->isTransparent()){ if(!$this->getSide(Facing::UP)->isTransparent()){
return true; return true;
} }

View File

@ -24,12 +24,12 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\entity\Entity; use pocketmine\entity\Entity;
use pocketmine\math\Vector3; use pocketmine\math\Facing;
abstract class Fallable extends Solid{ abstract class Fallable extends Solid{
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
$down = $this->getSide(Vector3::SIDE_DOWN); $down = $this->getSide(Facing::DOWN);
if($down->getId() === self::AIR or $down instanceof Liquid or $down instanceof Fire){ if($down->getId() === self::AIR or $down instanceof Liquid or $down instanceof Fire){
$this->level->setBlock($this, BlockFactory::get(Block::AIR), true); $this->level->setBlock($this, BlockFactory::get(Block::AIR), true);

View File

@ -26,7 +26,7 @@ namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory; use pocketmine\item\ItemFactory;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3; use pocketmine\math\Facing;
class Farmland extends Transparent{ class Farmland extends Transparent{
@ -53,7 +53,7 @@ class Farmland extends Transparent{
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_UP)->isSolid()){ if($this->getSide(Facing::UP)->isSolid()){
$this->level->setBlock($this, BlockFactory::get(Block::DIRT), true); $this->level->setBlock($this, BlockFactory::get(Block::DIRT), true);
} }
} }

View File

@ -24,7 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3; use pocketmine\math\Facing;
abstract class Fence extends Transparent{ abstract class Fence extends Transparent{
@ -40,12 +40,12 @@ abstract class Fence extends Transparent{
$width = 0.5 - $this->getThickness() / 2; $width = 0.5 - $this->getThickness() / 2;
return new AxisAlignedBB( return new AxisAlignedBB(
($this->canConnect($this->getSide(Vector3::SIDE_WEST)) ? 0 : $width), ($this->canConnect($this->getSide(Facing::WEST)) ? 0 : $width),
0, 0,
($this->canConnect($this->getSide(Vector3::SIDE_NORTH)) ? 0 : $width), ($this->canConnect($this->getSide(Facing::NORTH)) ? 0 : $width),
1 - ($this->canConnect($this->getSide(Vector3::SIDE_EAST)) ? 0 : $width), 1 - ($this->canConnect($this->getSide(Facing::EAST)) ? 0 : $width),
1.5, 1.5,
1 - ($this->canConnect($this->getSide(Vector3::SIDE_SOUTH)) ? 0 : $width) 1 - ($this->canConnect($this->getSide(Facing::SOUTH)) ? 0 : $width)
); );
} }
@ -55,8 +55,8 @@ abstract class Fence extends Transparent{
/** @var AxisAlignedBB[] $bbs */ /** @var AxisAlignedBB[] $bbs */
$bbs = []; $bbs = [];
$connectWest = $this->canConnect($this->getSide(Vector3::SIDE_WEST)); $connectWest = $this->canConnect($this->getSide(Facing::WEST));
$connectEast = $this->canConnect($this->getSide(Vector3::SIDE_EAST)); $connectEast = $this->canConnect($this->getSide(Facing::EAST));
if($connectWest or $connectEast){ if($connectWest or $connectEast){
//X axis (west/east) //X axis (west/east)
@ -70,8 +70,8 @@ abstract class Fence extends Transparent{
); );
} }
$connectNorth = $this->canConnect($this->getSide(Vector3::SIDE_NORTH)); $connectNorth = $this->canConnect($this->getSide(Facing::NORTH));
$connectSouth = $this->canConnect($this->getSide(Vector3::SIDE_SOUTH)); $connectSouth = $this->canConnect($this->getSide(Facing::SOUTH));
if($connectNorth or $connectSouth){ if($connectNorth or $connectSouth){
//Z axis (north/south) //Z axis (north/south)

View File

@ -26,6 +26,7 @@ namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\level\sound\DoorSound; use pocketmine\level\sound\DoorSound;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Bearing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -68,7 +69,9 @@ class FenceGate extends Transparent{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$this->meta = ($player instanceof Player ? ($player->getDirection() - 1) & 0x03 : 0); if($player !== null){
$this->meta = Bearing::rotate($player->getDirection(), 2);
}
$this->getLevel()->setBlock($blockReplace, $this, true, true); $this->getLevel()->setBlock($blockReplace, $this, true, true);
return true; return true;
@ -82,7 +85,7 @@ class FenceGate extends Transparent{
$this->meta = (($this->meta ^ 0x04) & ~0x02); $this->meta = (($this->meta ^ 0x04) & ~0x02);
if($player !== null){ if($player !== null){
$this->meta |= (($player->getDirection() - 1) & 0x02); $this->meta |= (Bearing::rotate($player->getDirection(), 2) & 0x02); //open towards the player, retaining axis
} }
$this->getLevel()->setBlock($this, $this, true); $this->getLevel()->setBlock($this, $this, true);

View File

@ -30,7 +30,7 @@ use pocketmine\event\entity\EntityCombustByBlockEvent;
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\item\Item;
use pocketmine\math\Vector3; use pocketmine\math\Facing;
use pocketmine\Server; use pocketmine\Server;
class Fire extends Flowable{ class Fire extends Flowable{
@ -80,7 +80,7 @@ class Fire extends Flowable{
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
if(!$this->getSide(Vector3::SIDE_DOWN)->isSolid() and !$this->hasAdjacentFlammableBlocks()){ if(!$this->getSide(Facing::DOWN)->isSolid() and !$this->hasAdjacentFlammableBlocks()){
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true); $this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true);
}else{ }else{
$this->level->scheduleDelayedBlockUpdate($this, mt_rand(30, 40)); $this->level->scheduleDelayedBlockUpdate($this, mt_rand(30, 40));
@ -92,7 +92,7 @@ class Fire extends Flowable{
} }
public function onRandomTick() : void{ public function onRandomTick() : void{
$down = $this->getSide(Vector3::SIDE_DOWN); $down = $this->getSide(Facing::DOWN);
$result = null; $result = null;
if($this->meta < 15 and mt_rand(0, 2) === 0){ if($this->meta < 15 and mt_rand(0, 2) === 0){
@ -130,8 +130,8 @@ class Fire extends Flowable{
} }
//vanilla uses a 250 upper bound here, but I don't think they intended to increase the chance of incineration //vanilla uses a 250 upper bound here, but I don't think they intended to increase the chance of incineration
$this->burnBlock($this->getSide(Vector3::SIDE_UP), 350); $this->burnBlock($this->getSide(Facing::UP), 350);
$this->burnBlock($this->getSide(Vector3::SIDE_DOWN), 350); $this->burnBlock($this->getSide(Facing::DOWN), 350);
//TODO: fire spread //TODO: fire spread
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -60,7 +61,7 @@ class Flower extends Flowable{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN); $down = $this->getSide(Facing::DOWN);
if($down->getId() === Block::GRASS or $down->getId() === Block::DIRT or $down->getId() === Block::FARMLAND){ if($down->getId() === Block::GRASS or $down->getId() === Block::DIRT or $down->getId() === Block::FARMLAND){
$this->getLevel()->setBlock($blockReplace, $this, true); $this->getLevel()->setBlock($blockReplace, $this, true);
@ -71,7 +72,7 @@ class Flower extends Flowable{
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){ if($this->getSide(Facing::DOWN)->isTransparent()){
$this->getLevel()->useBreakOn($this); $this->getLevel()->useBreakOn($this);
} }
} }

View File

@ -25,6 +25,7 @@ namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\tile\FlowerPot as TileFlowerPot; use pocketmine\tile\FlowerPot as TileFlowerPot;
@ -52,7 +53,7 @@ class FlowerPot extends Flowable{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){ if($this->getSide(Facing::DOWN)->isTransparent()){
return false; return false;
} }
@ -62,7 +63,7 @@ class FlowerPot extends Flowable{
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){ if($this->getSide(Facing::DOWN)->isTransparent()){
$this->getLevel()->useBreakOn($this); $this->getLevel()->useBreakOn($this);
} }
} }

View File

@ -26,6 +26,7 @@ namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\TieredTool; use pocketmine\item\TieredTool;
use pocketmine\math\Bearing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -45,15 +46,8 @@ class GlazedTerracotta extends Solid{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($player !== null){ if($player !== null){
$faces = [ $this->meta = Bearing::toFacing($player->getDirection());
0 => 4,
1 => 3,
2 => 5,
3 => 2
];
$this->meta = $faces[(~($player->getDirection() - 1)) & 0x03];
} }
return $this->getLevel()->setBlock($blockReplace, $this, true, true); return $this->getLevel()->setBlock($blockReplace, $this, true, true);
} }

View File

@ -29,7 +29,7 @@ use pocketmine\item\Item;
use pocketmine\item\ItemFactory; use pocketmine\item\ItemFactory;
use pocketmine\item\Shovel; use pocketmine\item\Shovel;
use pocketmine\level\generator\object\TallGrass as TallGrassObject; use pocketmine\level\generator\object\TallGrass as TallGrassObject;
use pocketmine\math\Vector3; use pocketmine\math\Facing;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\utils\Random; use pocketmine\utils\Random;
@ -105,7 +105,7 @@ class Grass extends Solid{
$this->getLevel()->setBlock($this, BlockFactory::get(Block::FARMLAND)); $this->getLevel()->setBlock($this, BlockFactory::get(Block::FARMLAND));
return true; return true;
}elseif($item instanceof Shovel and $this->getSide(Vector3::SIDE_UP)->getId() === Block::AIR){ }elseif($item instanceof Shovel and $this->getSide(Facing::UP)->getId() === Block::AIR){
$item->applyDamage(1); $item->applyDamage(1);
$this->getLevel()->setBlock($this, BlockFactory::get(Block::GRASS_PATH)); $this->getLevel()->setBlock($this, BlockFactory::get(Block::GRASS_PATH));

View File

@ -26,7 +26,7 @@ namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory; use pocketmine\item\ItemFactory;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3; use pocketmine\math\Facing;
class GrassPath extends Transparent{ class GrassPath extends Transparent{
@ -53,7 +53,7 @@ class GrassPath extends Transparent{
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_UP)->isSolid()){ if($this->getSide(Facing::UP)->isSolid()){
$this->level->setBlock($this, BlockFactory::get(Block::DIRT), true); $this->level->setBlock($this, BlockFactory::get(Block::DIRT), true);
} }
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\tile\ItemFrame as TileItemFrame; use pocketmine\tile\ItemFrame as TileItemFrame;
@ -59,10 +60,10 @@ class ItemFrame extends Flowable{
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
$sides = [ $sides = [
0 => Vector3::SIDE_WEST, 0 => Facing::WEST,
1 => Vector3::SIDE_EAST, 1 => Facing::EAST,
2 => Vector3::SIDE_NORTH, 2 => Facing::NORTH,
3 => Vector3::SIDE_SOUTH 3 => Facing::SOUTH
]; ];
if(!$this->getSide($sides[$this->meta])->isSolid()){ if(!$this->getSide($sides[$this->meta])->isSolid()){
$this->level->useBreakOn($this); $this->level->useBreakOn($this);
@ -70,15 +71,15 @@ class ItemFrame extends Flowable{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($face === Vector3::SIDE_DOWN or $face === Vector3::SIDE_UP or !$blockClicked->isSolid()){ if($face === Facing::DOWN or $face === Facing::UP or !$blockClicked->isSolid()){
return false; return false;
} }
$faces = [ $faces = [
Vector3::SIDE_NORTH => 3, Facing::NORTH => 3,
Vector3::SIDE_SOUTH => 2, Facing::SOUTH => 2,
Vector3::SIDE_WEST => 1, Facing::WEST => 1,
Vector3::SIDE_EAST => 0 Facing::EAST => 0
]; ];
$this->meta = $faces[$face]; $this->meta = $faces[$face];

View File

@ -26,6 +26,7 @@ namespace pocketmine\block;
use pocketmine\event\block\LeavesDecayEvent; use pocketmine\event\block\LeavesDecayEvent;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory; use pocketmine\item\ItemFactory;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -76,7 +77,7 @@ class Leaves extends Transparent{
return true; return true;
}elseif($pos->getId() === $this->id and $distance < 3){ }elseif($pos->getId() === $this->id and $distance < 3){
$visited[$index] = true; $visited[$index] = true;
$down = $pos->getSide(Vector3::SIDE_DOWN)->getId(); $down = $pos->getSide(Facing::DOWN)->getId();
if($down === $this->woodType){ if($down === $this->woodType){
return true; return true;
} }
@ -89,38 +90,38 @@ class Leaves extends Transparent{
}else{ //No more loops }else{ //No more loops
switch($fromSide){ switch($fromSide){
case 2: case 2:
if($this->findLog($pos->getSide(Vector3::SIDE_NORTH), $visited, $distance + 1, $fromSide)){ if($this->findLog($pos->getSide(Facing::NORTH), $visited, $distance + 1, $fromSide)){
return true; return true;
}elseif($this->findLog($pos->getSide(Vector3::SIDE_WEST), $visited, $distance + 1, $fromSide)){ }elseif($this->findLog($pos->getSide(Facing::WEST), $visited, $distance + 1, $fromSide)){
return true; return true;
}elseif($this->findLog($pos->getSide(Vector3::SIDE_EAST), $visited, $distance + 1, $fromSide)){ }elseif($this->findLog($pos->getSide(Facing::EAST), $visited, $distance + 1, $fromSide)){
return true; return true;
} }
break; break;
case 3: case 3:
if($this->findLog($pos->getSide(Vector3::SIDE_SOUTH), $visited, $distance + 1, $fromSide)){ if($this->findLog($pos->getSide(Facing::SOUTH), $visited, $distance + 1, $fromSide)){
return true; return true;
}elseif($this->findLog($pos->getSide(Vector3::SIDE_WEST), $visited, $distance + 1, $fromSide)){ }elseif($this->findLog($pos->getSide(Facing::WEST), $visited, $distance + 1, $fromSide)){
return true; return true;
}elseif($this->findLog($pos->getSide(Vector3::SIDE_EAST), $visited, $distance + 1, $fromSide)){ }elseif($this->findLog($pos->getSide(Facing::EAST), $visited, $distance + 1, $fromSide)){
return true; return true;
} }
break; break;
case 4: case 4:
if($this->findLog($pos->getSide(Vector3::SIDE_NORTH), $visited, $distance + 1, $fromSide)){ if($this->findLog($pos->getSide(Facing::NORTH), $visited, $distance + 1, $fromSide)){
return true; return true;
}elseif($this->findLog($pos->getSide(Vector3::SIDE_SOUTH), $visited, $distance + 1, $fromSide)){ }elseif($this->findLog($pos->getSide(Facing::SOUTH), $visited, $distance + 1, $fromSide)){
return true; return true;
}elseif($this->findLog($pos->getSide(Vector3::SIDE_WEST), $visited, $distance + 1, $fromSide)){ }elseif($this->findLog($pos->getSide(Facing::WEST), $visited, $distance + 1, $fromSide)){
return true; return true;
} }
break; break;
case 5: case 5:
if($this->findLog($pos->getSide(Vector3::SIDE_NORTH), $visited, $distance + 1, $fromSide)){ if($this->findLog($pos->getSide(Facing::NORTH), $visited, $distance + 1, $fromSide)){
return true; return true;
}elseif($this->findLog($pos->getSide(Vector3::SIDE_SOUTH), $visited, $distance + 1, $fromSide)){ }elseif($this->findLog($pos->getSide(Facing::SOUTH), $visited, $distance + 1, $fromSide)){
return true; return true;
}elseif($this->findLog($pos->getSide(Vector3::SIDE_EAST), $visited, $distance + 1, $fromSide)){ }elseif($this->findLog($pos->getSide(Facing::EAST), $visited, $distance + 1, $fromSide)){
return true; return true;
} }
break; break;

View File

@ -24,6 +24,8 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\Bearing;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -52,19 +54,20 @@ class Lever extends Flowable{
return false; return false;
} }
if($face === Vector3::SIDE_DOWN){ if($face === Facing::DOWN){
$this->meta = 0; $this->meta = 0;
}else{ }else{
$this->meta = 6 - $face; $this->meta = 6 - $face;
} }
if($player !== null){ if($player !== null){
if(($player->getDirection() & 0x01) === 0){ $bearing = $player->getDirection();
if($face === Vector3::SIDE_UP){ if($bearing === Bearing::EAST or $bearing === Bearing::WEST){
if($face === Facing::UP){
$this->meta = 6; $this->meta = 6;
} }
}else{ }else{
if($face === Vector3::SIDE_DOWN){ if($face === Facing::DOWN){
$this->meta = 7; $this->meta = 7;
} }
} }
@ -74,15 +77,15 @@ class Lever extends Flowable{
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
$faces = [ static $faces = [
0 => Vector3::SIDE_UP, 0 => Facing::UP,
1 => Vector3::SIDE_WEST, 1 => Facing::WEST,
2 => Vector3::SIDE_EAST, 2 => Facing::EAST,
3 => Vector3::SIDE_NORTH, 3 => Facing::NORTH,
4 => Vector3::SIDE_SOUTH, 4 => Facing::SOUTH,
5 => Vector3::SIDE_DOWN, 5 => Facing::DOWN,
6 => Vector3::SIDE_DOWN, 6 => Facing::DOWN,
7 => Vector3::SIDE_UP 7 => Facing::UP
]; ];
if(!$this->getSide($faces[$this->meta & 0x07])->isSolid()){ if(!$this->getSide($faces[$this->meta & 0x07])->isSolid()){
$this->level->useBreakOn($this); $this->level->useBreakOn($this);

View File

@ -26,7 +26,7 @@ namespace pocketmine\block;
use pocketmine\event\block\BlockGrowEvent; use pocketmine\event\block\BlockGrowEvent;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory; use pocketmine\item\ItemFactory;
use pocketmine\math\Vector3; use pocketmine\math\Facing;
use pocketmine\Server; use pocketmine\Server;
class MelonStem extends Crops{ class MelonStem extends Crops{
@ -58,7 +58,7 @@ class MelonStem extends Crops{
} }
} }
$side = $this->getSide(mt_rand(2, 5)); $side = $this->getSide(mt_rand(2, 5));
$d = $side->getSide(Vector3::SIDE_DOWN); $d = $side->getSide(Facing::DOWN);
if($side->getId() === self::AIR and ($d->getId() === self::FARMLAND or $d->getId() === self::GRASS or $d->getId() === self::DIRT)){ if($side->getId() === self::AIR and ($d->getId() === self::FARMLAND or $d->getId() === self::GRASS or $d->getId() === self::DIRT)){
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, BlockFactory::get(Block::MELON_BLOCK))); Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, BlockFactory::get(Block::MELON_BLOCK)));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){

View File

@ -26,7 +26,7 @@ namespace pocketmine\block;
use pocketmine\event\block\BlockSpreadEvent; use pocketmine\event\block\BlockSpreadEvent;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory; use pocketmine\item\ItemFactory;
use pocketmine\math\Vector3; use pocketmine\math\Facing;
use pocketmine\Server; use pocketmine\Server;
class Mycelium extends Solid{ class Mycelium extends Solid{
@ -66,7 +66,7 @@ class Mycelium extends Solid{
$z = mt_rand($this->z - 1, $this->z + 1); $z = mt_rand($this->z - 1, $this->z + 1);
$block = $this->getLevel()->getBlockAt($x, $y, $z); $block = $this->getLevel()->getBlockAt($x, $y, $z);
if($block->getId() === Block::DIRT){ if($block->getId() === Block::DIRT){
if($block->getSide(Vector3::SIDE_UP) instanceof Transparent){ if($block->getSide(Facing::UP) instanceof Transparent){
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($block, $this, BlockFactory::get(Block::MYCELIUM))); Server::getInstance()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($block, $this, BlockFactory::get(Block::MYCELIUM)));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($block, $ev->getNewState()); $this->getLevel()->setBlock($block, $ev->getNewState());

View File

@ -27,6 +27,7 @@ namespace pocketmine\block;
use pocketmine\event\block\BlockGrowEvent; use pocketmine\event\block\BlockGrowEvent;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory; use pocketmine\item\ItemFactory;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -44,7 +45,7 @@ class NetherWartPlant extends Flowable{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN); $down = $this->getSide(Facing::DOWN);
if($down->getId() === Block::SOUL_SAND){ if($down->getId() === Block::SOUL_SAND){
$this->getLevel()->setBlock($blockReplace, $this, false, true); $this->getLevel()->setBlock($blockReplace, $this, false, true);
@ -55,7 +56,7 @@ class NetherWartPlant extends Flowable{
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->getId() !== Block::SOUL_SAND){ if($this->getSide(Facing::DOWN)->getId() !== Block::SOUL_SAND){
$this->getLevel()->useBreakOn($this); $this->getLevel()->useBreakOn($this);
} }
} }

View File

@ -23,10 +23,6 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\math\Vector3;
use pocketmine\Player;
class Pumpkin extends Solid{ class Pumpkin extends Solid{
protected $id = self::PUMPKIN; protected $id = self::PUMPKIN;
@ -47,15 +43,6 @@ class Pumpkin extends Solid{
return "Pumpkin"; return "Pumpkin";
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($player instanceof Player){
$this->meta = ((int) $player->getDirection() + 1) % 4;
}
$this->getLevel()->setBlock($blockReplace, $this, true, true);
return true;
}
public function getVariantBitmask() : int{ public function getVariantBitmask() : int{
return 0; return 0;
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\block;
use pocketmine\event\block\BlockGrowEvent; use pocketmine\event\block\BlockGrowEvent;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory; use pocketmine\item\ItemFactory;
use pocketmine\math\Vector3; use pocketmine\math\Facing;
use pocketmine\Server; use pocketmine\Server;
class PumpkinStem extends Crops{ class PumpkinStem extends Crops{
@ -58,7 +58,7 @@ class PumpkinStem extends Crops{
} }
} }
$side = $this->getSide(mt_rand(2, 5)); $side = $this->getSide(mt_rand(2, 5));
$d = $side->getSide(Vector3::SIDE_DOWN); $d = $side->getSide(Facing::DOWN);
if($side->getId() === self::AIR and ($d->getId() === self::FARMLAND or $d->getId() === self::GRASS or $d->getId() === self::DIRT)){ if($side->getId() === self::AIR and ($d->getId() === self::FARMLAND or $d->getId() === self::GRASS or $d->getId() === self::DIRT)){
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, BlockFactory::get(Block::PUMPKIN))); Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, BlockFactory::get(Block::PUMPKIN)));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -55,7 +56,7 @@ class Rail extends Flowable{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if(!$blockReplace->getSide(Vector3::SIDE_DOWN)->isTransparent()){ if(!$blockReplace->getSide(Facing::DOWN)->isTransparent()){
return $this->getLevel()->setBlock($blockReplace, $this, true, true); return $this->getLevel()->setBlock($blockReplace, $this, true, true);
} }
@ -63,7 +64,7 @@ class Rail extends Flowable{
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){ if($this->getSide(Facing::DOWN)->isTransparent()){
$this->getLevel()->useBreakOn($this); $this->getLevel()->useBreakOn($this);
}else{ }else{
//TODO: Update rail connectivity //TODO: Update rail connectivity

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -44,13 +45,13 @@ class RedMushroom extends Flowable{
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){ if($this->getSide(Facing::DOWN)->isTransparent()){
$this->getLevel()->useBreakOn($this); $this->getLevel()->useBreakOn($this);
} }
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN); $down = $this->getSide(Facing::DOWN);
if(!$down->isTransparent()){ if(!$down->isTransparent()){
$this->getLevel()->setBlock($blockReplace, $this, true, true); $this->getLevel()->setBlock($blockReplace, $this, true, true);

View File

@ -25,6 +25,7 @@ namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\level\generator\object\Tree; use pocketmine\level\generator\object\Tree;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\utils\Random; use pocketmine\utils\Random;
@ -56,7 +57,7 @@ class Sapling extends Flowable{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN); $down = $this->getSide(Facing::DOWN);
if($down->getId() === self::GRASS or $down->getId() === self::DIRT or $down->getId() === self::FARMLAND){ if($down->getId() === self::GRASS or $down->getId() === self::DIRT or $down->getId() === self::FARMLAND){
$this->getLevel()->setBlock($blockReplace, $this, true, true); $this->getLevel()->setBlock($blockReplace, $this, true, true);
@ -80,7 +81,7 @@ class Sapling extends Flowable{
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){ if($this->getSide(Facing::DOWN)->isTransparent()){
$this->getLevel()->useBreakOn($this); $this->getLevel()->useBreakOn($this);
} }
} }

View File

@ -25,6 +25,7 @@ namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\tile\Sign as TileSign; use pocketmine\tile\Sign as TileSign;
@ -58,9 +59,9 @@ class SignPost extends Transparent{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($face !== Vector3::SIDE_DOWN){ if($face !== Facing::DOWN){
if($face === Vector3::SIDE_UP){ if($face === Facing::UP){
$this->meta = $player !== null ? (floor((($player->yaw + 180) * 16 / 360) + 0.5) & 0x0f) : 0; $this->meta = $player !== null ? (floor((($player->yaw + 180) * 16 / 360) + 0.5) & 0x0f) : 0;
$this->getLevel()->setBlock($blockReplace, $this, true); $this->getLevel()->setBlock($blockReplace, $this, true);
}else{ }else{
@ -77,7 +78,7 @@ class SignPost extends Transparent{
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){ if($this->getSide(Facing::DOWN)->getId() === self::AIR){
$this->getLevel()->useBreakOn($this); $this->getLevel()->useBreakOn($this);
} }
} }

View File

@ -26,6 +26,7 @@ namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory; use pocketmine\item\ItemFactory;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\tile\Skull as TileSkull; use pocketmine\tile\Skull as TileSkull;
@ -54,7 +55,7 @@ class Skull extends Flowable{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($face === Vector3::SIDE_DOWN){ if($face === Facing::DOWN){
return false; return false;
} }

View File

@ -25,6 +25,7 @@ namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -43,9 +44,9 @@ abstract class Slab extends Transparent{
if($blockReplace->getId() === $this->getId() and $blockReplace->getVariant() === $this->getVariant()){ if($blockReplace->getId() === $this->getId() and $blockReplace->getVariant() === $this->getVariant()){
if(($blockReplace->getDamage() & 0x08) !== 0){ //Trying to combine with top slab if(($blockReplace->getDamage() & 0x08) !== 0){ //Trying to combine with top slab
return $clickVector->y <= 0.5 or (!$isClickedBlock and $face === Vector3::SIDE_UP); return $clickVector->y <= 0.5 or (!$isClickedBlock and $face === Facing::UP);
}else{ }else{
return $clickVector->y >= 0.5 or (!$isClickedBlock and $face === Vector3::SIDE_DOWN); return $clickVector->y >= 0.5 or (!$isClickedBlock and $face === Facing::DOWN);
} }
} }
@ -54,7 +55,7 @@ abstract class Slab extends Transparent{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$this->meta &= 0x07; $this->meta &= 0x07;
if($face === Vector3::SIDE_DOWN){ if($face === Facing::DOWN){
if($blockClicked->getId() === $this->id and ($blockClicked->getDamage() & 0x08) === 0x08 and $blockClicked->getVariant() === $this->getVariant()){ if($blockClicked->getId() === $this->id and ($blockClicked->getDamage() & 0x08) === 0x08 and $blockClicked->getVariant() === $this->getVariant()){
$this->getLevel()->setBlock($blockClicked, BlockFactory::get($this->getDoubleSlabId(), $this->getVariant()), true); $this->getLevel()->setBlock($blockClicked, BlockFactory::get($this->getDoubleSlabId(), $this->getVariant()), true);
@ -66,7 +67,7 @@ abstract class Slab extends Transparent{
}else{ }else{
$this->meta |= 0x08; $this->meta |= 0x08;
} }
}elseif($face === Vector3::SIDE_UP){ }elseif($face === Facing::UP){
if($blockClicked->getId() === $this->id and ($blockClicked->getDamage() & 0x08) === 0 and $blockClicked->getVariant() === $this->getVariant()){ if($blockClicked->getId() === $this->id and ($blockClicked->getDamage() & 0x08) === 0 and $blockClicked->getVariant() === $this->getVariant()){
$this->getLevel()->setBlock($blockClicked, BlockFactory::get($this->getDoubleSlabId(), $this->getVariant()), true); $this->getLevel()->setBlock($blockClicked, BlockFactory::get($this->getDoubleSlabId(), $this->getVariant()), true);

View File

@ -26,6 +26,7 @@ namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory; use pocketmine\item\ItemFactory;
use pocketmine\item\TieredTool; use pocketmine\item\TieredTool;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -58,7 +59,7 @@ class SnowLayer extends Flowable{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($blockReplace->getSide(Vector3::SIDE_DOWN)->isSolid()){ if($blockReplace->getSide(Facing::DOWN)->isSolid()){
//TODO: fix placement //TODO: fix placement
$this->getLevel()->setBlock($blockReplace, $this, true); $this->getLevel()->setBlock($blockReplace, $this, true);
@ -69,7 +70,7 @@ class SnowLayer extends Flowable{
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
if(!$this->getSide(Vector3::SIDE_DOWN)->isSolid()){ if(!$this->getSide(Facing::DOWN)->isSolid()){
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), false, false); $this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), false, false);
} }
} }

View File

@ -25,6 +25,8 @@ namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Bearing;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -69,14 +71,16 @@ abstract class Stair extends Transparent{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$faces = [ static $faces = [
0 => 0, Bearing::SOUTH => 3, //north
1 => 2, Bearing::WEST => 0, //east
2 => 1, Bearing::NORTH => 2, //south
3 => 3 Bearing::EAST => 1 //west
]; ];
$this->meta = $faces[$player->getDirection()] & 0x03; if($player !== null){
if(($clickVector->y > 0.5 and $face !== Vector3::SIDE_UP) or $face === Vector3::SIDE_DOWN){ $this->meta = $faces[$player->getDirection()];
}
if(($clickVector->y > 0.5 and $face !== Facing::UP) or $face === Facing::DOWN){
$this->meta |= 0x04; //Upside-down stairs $this->meta |= 0x04; //Upside-down stairs
} }
$this->getLevel()->setBlock($blockReplace, $this, true, true); $this->getLevel()->setBlock($blockReplace, $this, true, true);

View File

@ -26,6 +26,7 @@ namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory; use pocketmine\item\ItemFactory;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\tile\Banner as TileBanner; use pocketmine\tile\Banner as TileBanner;
@ -58,8 +59,8 @@ class StandingBanner extends Transparent{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($face !== Vector3::SIDE_DOWN){ if($face !== Facing::DOWN){
if($face === Vector3::SIDE_UP and $player !== null){ if($face === Facing::UP and $player !== null){
$this->meta = floor((($player->yaw + 180) * 16 / 360) + 0.5) & 0x0f; $this->meta = floor((($player->yaw + 180) * 16 / 360) + 0.5) & 0x0f;
$this->getLevel()->setBlock($blockReplace, $this, true); $this->getLevel()->setBlock($blockReplace, $this, true);
}else{ }else{
@ -75,7 +76,7 @@ class StandingBanner extends Transparent{
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){ if($this->getSide(Facing::DOWN)->getId() === self::AIR){
$this->getLevel()->useBreakOn($this); $this->getLevel()->useBreakOn($this);
} }
} }

View File

@ -25,6 +25,7 @@ namespace pocketmine\block;
use pocketmine\event\block\BlockGrowEvent; use pocketmine\event\block\BlockGrowEvent;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\Server; use pocketmine\Server;
@ -45,7 +46,7 @@ class Sugarcane extends Flowable{
public function onActivate(Item $item, Player $player = null) : bool{ public function onActivate(Item $item, Player $player = null) : bool{
if($item->getId() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal if($item->getId() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal
if($this->getSide(Vector3::SIDE_DOWN)->getId() !== self::SUGARCANE_BLOCK){ if($this->getSide(Facing::DOWN)->getId() !== self::SUGARCANE_BLOCK){
for($y = 1; $y < 3; ++$y){ for($y = 1; $y < 3; ++$y){
$b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z); $b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z);
if($b->getId() === self::AIR){ if($b->getId() === self::AIR){
@ -69,7 +70,7 @@ class Sugarcane extends Flowable{
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
$down = $this->getSide(Vector3::SIDE_DOWN); $down = $this->getSide(Facing::DOWN);
if($down->isTransparent() and $down->getId() !== self::SUGARCANE_BLOCK){ if($down->isTransparent() and $down->getId() !== self::SUGARCANE_BLOCK){
$this->getLevel()->useBreakOn($this); $this->getLevel()->useBreakOn($this);
} }
@ -80,7 +81,7 @@ class Sugarcane extends Flowable{
} }
public function onRandomTick() : void{ public function onRandomTick() : void{
if($this->getSide(Vector3::SIDE_DOWN)->getId() !== self::SUGARCANE_BLOCK){ if($this->getSide(Facing::DOWN)->getId() !== self::SUGARCANE_BLOCK){
if($this->meta === 0x0F){ if($this->meta === 0x0F){
for($y = 1; $y < 3; ++$y){ for($y = 1; $y < 3; ++$y){
$b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z); $b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z);
@ -99,16 +100,16 @@ class Sugarcane extends Flowable{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN); $down = $this->getSide(Facing::DOWN);
if($down->getId() === self::SUGARCANE_BLOCK){ if($down->getId() === self::SUGARCANE_BLOCK){
$this->getLevel()->setBlock($blockReplace, BlockFactory::get(Block::SUGARCANE_BLOCK), true); $this->getLevel()->setBlock($blockReplace, BlockFactory::get(Block::SUGARCANE_BLOCK), true);
return true; return true;
}elseif($down->getId() === self::GRASS or $down->getId() === self::DIRT or $down->getId() === self::SAND){ }elseif($down->getId() === self::GRASS or $down->getId() === self::DIRT or $down->getId() === self::SAND){
$block0 = $down->getSide(Vector3::SIDE_NORTH); $block0 = $down->getSide(Facing::NORTH);
$block1 = $down->getSide(Vector3::SIDE_SOUTH); $block1 = $down->getSide(Facing::SOUTH);
$block2 = $down->getSide(Vector3::SIDE_WEST); $block2 = $down->getSide(Facing::WEST);
$block3 = $down->getSide(Vector3::SIDE_EAST); $block3 = $down->getSide(Facing::EAST);
if(($block0 instanceof Water) or ($block1 instanceof Water) or ($block2 instanceof Water) or ($block3 instanceof Water)){ if(($block0 instanceof Water) or ($block1 instanceof Water) or ($block2 instanceof Water) or ($block3 instanceof Water)){
$this->getLevel()->setBlock($blockReplace, BlockFactory::get(Block::SUGARCANE_BLOCK), true); $this->getLevel()->setBlock($blockReplace, BlockFactory::get(Block::SUGARCANE_BLOCK), true);

View File

@ -25,6 +25,7 @@ namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory; use pocketmine\item\ItemFactory;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -50,7 +51,7 @@ class TallGrass extends Flowable{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN); $down = $this->getSide(Facing::DOWN);
if($down->getId() === self::GRASS){ if($down->getId() === self::GRASS){
$this->getLevel()->setBlock($blockReplace, $this, true); $this->getLevel()->setBlock($blockReplace, $this, true);
@ -61,7 +62,7 @@ class TallGrass extends Flowable{
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){ //Replace with common break method if($this->getSide(Facing::DOWN)->isTransparent()){ //Replace with common break method
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true, true); $this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true, true);
} }
} }

View File

@ -24,7 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3; use pocketmine\math\Facing;
abstract class Thin extends Transparent{ abstract class Thin extends Transparent{
@ -32,12 +32,12 @@ abstract class Thin extends Transparent{
$width = 0.5 - 0.125 / 2; $width = 0.5 - 0.125 / 2;
return new AxisAlignedBB( return new AxisAlignedBB(
($this->canConnect($this->getSide(Vector3::SIDE_WEST)) ? 0 : $width), ($this->canConnect($this->getSide(Facing::WEST)) ? 0 : $width),
0, 0,
($this->canConnect($this->getSide(Vector3::SIDE_NORTH)) ? 0 : $width), ($this->canConnect($this->getSide(Facing::NORTH)) ? 0 : $width),
1 - ($this->canConnect($this->getSide(Vector3::SIDE_EAST)) ? 0 : $width), 1 - ($this->canConnect($this->getSide(Facing::EAST)) ? 0 : $width),
1, 1,
1 - ($this->canConnect($this->getSide(Vector3::SIDE_SOUTH)) ? 0 : $width) 1 - ($this->canConnect($this->getSide(Facing::SOUTH)) ? 0 : $width)
); );
} }
@ -47,8 +47,8 @@ abstract class Thin extends Transparent{
/** @var AxisAlignedBB[] $bbs */ /** @var AxisAlignedBB[] $bbs */
$bbs = []; $bbs = [];
$connectWest = $this->canConnect($this->getSide(Vector3::SIDE_WEST)); $connectWest = $this->canConnect($this->getSide(Facing::WEST));
$connectEast = $this->canConnect($this->getSide(Vector3::SIDE_EAST)); $connectEast = $this->canConnect($this->getSide(Facing::EAST));
if($connectWest or $connectEast){ if($connectWest or $connectEast){
//X axis (west/east) //X axis (west/east)
@ -62,8 +62,8 @@ abstract class Thin extends Transparent{
); );
} }
$connectNorth = $this->canConnect($this->getSide(Vector3::SIDE_NORTH)); $connectNorth = $this->canConnect($this->getSide(Facing::NORTH));
$connectSouth = $this->canConnect($this->getSide(Vector3::SIDE_SOUTH)); $connectSouth = $this->canConnect($this->getSide(Facing::SOUTH));
if($connectNorth or $connectSouth){ if($connectNorth or $connectSouth){
//Z axis (north/south) //Z axis (north/south)

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -44,32 +45,32 @@ class Torch extends Flowable{
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
$below = $this->getSide(Vector3::SIDE_DOWN); $below = $this->getSide(Facing::DOWN);
$side = $this->getDamage(); $side = $this->getDamage();
$faces = [ static $faces = [
0 => Vector3::SIDE_DOWN, 0 => Facing::DOWN,
1 => Vector3::SIDE_WEST, 1 => Facing::WEST,
2 => Vector3::SIDE_EAST, 2 => Facing::EAST,
3 => Vector3::SIDE_NORTH, 3 => Facing::NORTH,
4 => Vector3::SIDE_SOUTH, 4 => Facing::SOUTH,
5 => Vector3::SIDE_DOWN 5 => Facing::DOWN
]; ];
if($this->getSide($faces[$side])->isTransparent() and !($side === Vector3::SIDE_DOWN and ($below->getId() === self::FENCE or $below->getId() === self::COBBLESTONE_WALL))){ if($this->getSide($faces[$side])->isTransparent() and !($side === Facing::DOWN and ($below->getId() === self::FENCE or $below->getId() === self::COBBLESTONE_WALL))){
$this->getLevel()->useBreakOn($this); $this->getLevel()->useBreakOn($this);
} }
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$below = $this->getSide(Vector3::SIDE_DOWN); $below = $this->getSide(Facing::DOWN);
if(!$blockClicked->isTransparent() and $face !== Vector3::SIDE_DOWN){ if(!$blockClicked->isTransparent() and $face !== Facing::DOWN){
$faces = [ static $faces = [
Vector3::SIDE_UP => 5, Facing::UP => 5,
Vector3::SIDE_NORTH => 4, Facing::NORTH => 4,
Vector3::SIDE_SOUTH => 3, Facing::SOUTH => 3,
Vector3::SIDE_WEST => 2, Facing::WEST => 2,
Vector3::SIDE_EAST => 1 Facing::EAST => 1
]; ];
$this->meta = $faces[$face]; $this->meta = $faces[$face];
$this->getLevel()->setBlock($blockReplace, $this, true, true); $this->getLevel()->setBlock($blockReplace, $this, true, true);

View File

@ -26,6 +26,8 @@ namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\level\sound\DoorSound; use pocketmine\level\sound\DoorSound;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Bearing;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -81,16 +83,16 @@ class Trapdoor extends Transparent{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$directions = [ static $directions = [
0 => 1, Bearing::SOUTH => 2,
1 => 3, Bearing::WEST => 1,
2 => 0, Bearing::NORTH => 3,
3 => 2 Bearing::EAST => 0
]; ];
if($player !== null){ if($player !== null){
$this->meta = $directions[$player->getDirection() & 0x03]; $this->meta = $directions[$player->getDirection()];
} }
if(($clickVector->y > 0.5 and $face !== self::SIDE_UP) or $face === self::SIDE_DOWN){ if(($clickVector->y > 0.5 and $face !== Facing::UP) or $face === Facing::DOWN){
$this->meta |= self::MASK_UPPER; //top half of block $this->meta |= self::MASK_UPPER; //top half of block
} }
$this->getLevel()->setBlock($blockReplace, $this, true, true); $this->getLevel()->setBlock($blockReplace, $this, true, true);

View File

@ -26,6 +26,7 @@ namespace pocketmine\block;
use pocketmine\entity\Entity; use pocketmine\entity\Entity;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -111,7 +112,7 @@ class Vine extends Flowable{
//TODO: Missing NORTH check //TODO: Missing NORTH check
if(!$flag and $this->getSide(Vector3::SIDE_UP)->isSolid()){ if(!$flag and $this->getSide(Facing::UP)->isSolid()){
$minY = min($minY, 0.9375); $minY = min($minY, 0.9375);
$maxY = 1; $maxY = 1;
$minX = 0; $minX = 0;
@ -124,15 +125,15 @@ class Vine extends Flowable{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if(!$blockClicked->isSolid() or $face === Vector3::SIDE_UP or $face === Vector3::SIDE_DOWN){ if(!$blockClicked->isSolid() or $face === Facing::UP or $face === Facing::DOWN){
return false; return false;
} }
$faces = [ static $faces = [
Vector3::SIDE_NORTH => self::FLAG_SOUTH, Facing::NORTH => self::FLAG_SOUTH,
Vector3::SIDE_SOUTH => self::FLAG_NORTH, Facing::SOUTH => self::FLAG_NORTH,
Vector3::SIDE_WEST => self::FLAG_EAST, Facing::WEST => self::FLAG_EAST,
Vector3::SIDE_EAST => self::FLAG_WEST Facing::EAST => self::FLAG_WEST
]; ];
$this->meta = $faces[$face] ?? 0; $this->meta = $faces[$face] ?? 0;
@ -145,11 +146,11 @@ class Vine extends Flowable{
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
$sides = [ static $sides = [
self::FLAG_SOUTH => Vector3::SIDE_SOUTH, self::FLAG_SOUTH => Facing::SOUTH,
self::FLAG_WEST => Vector3::SIDE_WEST, self::FLAG_WEST => Facing::WEST,
self::FLAG_NORTH => Vector3::SIDE_NORTH, self::FLAG_NORTH => Facing::NORTH,
self::FLAG_EAST => Vector3::SIDE_EAST self::FLAG_EAST => Facing::EAST
]; ];
$meta = $this->meta; $meta = $this->meta;

View File

@ -25,6 +25,7 @@ namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -51,7 +52,7 @@ class WaterLily extends Flowable{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($blockClicked instanceof Water){ if($blockClicked instanceof Water){
$up = $blockClicked->getSide(Vector3::SIDE_UP); $up = $blockClicked->getSide(Facing::UP);
if($up->getId() === Block::AIR){ if($up->getId() === Block::AIR){
$this->getLevel()->setBlock($up, $this, true, true); $this->getLevel()->setBlock($up, $this, true, true);
return true; return true;
@ -62,7 +63,7 @@ class WaterLily extends Flowable{
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
if(!($this->getSide(Vector3::SIDE_DOWN) instanceof Water)){ if(!($this->getSide(Facing::DOWN) instanceof Water)){
$this->getLevel()->useBreakOn($this); $this->getLevel()->useBreakOn($this);
} }
} }

View File

@ -23,17 +23,17 @@ declare(strict_types=1);
namespace pocketmine\block\utils; namespace pocketmine\block\utils;
use pocketmine\math\Vector3; use pocketmine\math\Facing;
class PillarRotationHelper{ class PillarRotationHelper{
public static function getMetaFromFace(int $meta, int $face) : int{ public static function getMetaFromFace(int $meta, int $face) : int{
$faces = [ static $bits = [
Vector3::SIDE_DOWN => 0, Facing::AXIS_Y => 0,
Vector3::SIDE_NORTH => 0x08, Facing::AXIS_Z => 0x08,
Vector3::SIDE_WEST => 0x04 Facing::AXIS_X => 0x04
]; ];
return ($meta & 0x03) | $faces[$face & ~0x01]; return ($meta & 0x03) | $bits[Facing::axis($face)];
} }
} }

View File

@ -53,6 +53,8 @@ use pocketmine\level\Level;
use pocketmine\level\Location; use pocketmine\level\Location;
use pocketmine\level\Position; use pocketmine\level\Position;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Bearing;
use pocketmine\math\Facing;
use pocketmine\math\Vector2; use pocketmine\math\Vector2;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\metadata\Metadatable; use pocketmine\metadata\Metadatable;
@ -1208,66 +1210,66 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
if($westNonSolid){ if($westNonSolid){
$limit = $diffX; $limit = $diffX;
$direction = Vector3::SIDE_WEST; $direction = Facing::WEST;
} }
if($eastNonSolid and 1 - $diffX < $limit){ if($eastNonSolid and 1 - $diffX < $limit){
$limit = 1 - $diffX; $limit = 1 - $diffX;
$direction = Vector3::SIDE_EAST; $direction = Facing::EAST;
} }
if($downNonSolid and $diffY < $limit){ if($downNonSolid and $diffY < $limit){
$limit = $diffY; $limit = $diffY;
$direction = Vector3::SIDE_DOWN; $direction = Facing::DOWN;
} }
if($upNonSolid and 1 - $diffY < $limit){ if($upNonSolid and 1 - $diffY < $limit){
$limit = 1 - $diffY; $limit = 1 - $diffY;
$direction = Vector3::SIDE_UP; $direction = Facing::UP;
} }
if($northNonSolid and $diffZ < $limit){ if($northNonSolid and $diffZ < $limit){
$limit = $diffZ; $limit = $diffZ;
$direction = Vector3::SIDE_NORTH; $direction = Facing::NORTH;
} }
if($southNonSolid and 1 - $diffZ < $limit){ if($southNonSolid and 1 - $diffZ < $limit){
$direction = Vector3::SIDE_SOUTH; $direction = Facing::SOUTH;
} }
$force = lcg_value() * 0.2 + 0.1; $force = lcg_value() * 0.2 + 0.1;
if($direction === Vector3::SIDE_WEST){ if($direction === Facing::WEST){
$this->motion->x = -$force; $this->motion->x = -$force;
return true; return true;
} }
if($direction === Vector3::SIDE_EAST){ if($direction === Facing::EAST){
$this->motion->x = $force; $this->motion->x = $force;
return true; return true;
} }
if($direction === Vector3::SIDE_DOWN){ if($direction === Facing::DOWN){
$this->motion->y = -$force; $this->motion->y = -$force;
return true; return true;
} }
if($direction === Vector3::SIDE_UP){ if($direction === Facing::UP){
$this->motion->y = $force; $this->motion->y = $force;
return true; return true;
} }
if($direction === Vector3::SIDE_NORTH){ if($direction === Facing::NORTH){
$this->motion->z = -$force; $this->motion->z = -$force;
return true; return true;
} }
if($direction === Vector3::SIDE_SOUTH){ if($direction === Facing::SOUTH){
$this->motion->z = $force; $this->motion->z = $force;
return true; return true;
@ -1277,25 +1279,8 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
return false; return false;
} }
/** public function getDirection() : int{
* @return int|null return Bearing::fromAngle($this->yaw);
*/
public function getDirection() : ?int{
$rotation = ($this->yaw - 90) % 360;
if($rotation < 0){
$rotation += 360.0;
}
if((0 <= $rotation and $rotation < 45) or (315 <= $rotation and $rotation < 360)){
return 2; //North
}elseif(45 <= $rotation and $rotation < 135){
return 3; //East
}elseif(135 <= $rotation and $rotation < 225){
return 0; //South
}elseif(225 <= $rotation and $rotation < 315){
return 1; //West
}else{
return null;
}
} }
/** /**

View File

@ -32,6 +32,8 @@ use pocketmine\item\ItemFactory;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\level\particle\DestroyBlockParticle; use pocketmine\level\particle\DestroyBlockParticle;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Bearing;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\CompoundTag;
@ -110,29 +112,14 @@ class Painting extends Entity{
} }
protected function recalculateBoundingBox() : void{ protected function recalculateBoundingBox() : void{
static $directions = [ $facing = Bearing::toFacing($this->direction);
0 => Vector3::SIDE_SOUTH,
1 => Vector3::SIDE_WEST,
2 => Vector3::SIDE_NORTH,
3 => Vector3::SIDE_EAST
];
$facing = $directions[$this->direction];
$this->boundingBox->setBB(self::getPaintingBB($this->blockIn->getSide($facing), $facing, $this->getMotive())); $this->boundingBox->setBB(self::getPaintingBB($this->blockIn->getSide($facing), $facing, $this->getMotive()));
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
parent::onNearbyBlockChange(); parent::onNearbyBlockChange();
static $directions = [ $face = Bearing::toFacing($this->direction);
0 => Vector3::SIDE_SOUTH,
1 => Vector3::SIDE_WEST,
2 => Vector3::SIDE_NORTH,
3 => Vector3::SIDE_EAST
];
$face = $directions[$this->direction];
if(!self::canFit($this->level, $this->blockIn->getSide($face), $face, false, $this->getMotive())){ if(!self::canFit($this->level, $this->blockIn->getSide($face), $face, false, $this->getMotive())){
$this->kill(); $this->kill();
} }
@ -170,7 +157,7 @@ class Painting extends Entity{
return PaintingMotive::getMotiveByName($this->motive); return PaintingMotive::getMotiveByName($this->motive);
} }
public function getDirection() : ?int{ public function getDirection() : int{
return $this->direction; return $this->direction;
} }
@ -199,25 +186,25 @@ class Painting extends Entity{
$maxY = $minY + $height; $maxY = $minY + $height;
switch($facing){ switch($facing){
case Vector3::SIDE_NORTH: case Facing::NORTH:
$minZ = 1 - $thickness; $minZ = 1 - $thickness;
$maxZ = 1; $maxZ = 1;
$maxX = $horizontalStart + 1; $maxX = $horizontalStart + 1;
$minX = $maxX - $width; $minX = $maxX - $width;
break; break;
case Vector3::SIDE_SOUTH: case Facing::SOUTH:
$minZ = 0; $minZ = 0;
$maxZ = $thickness; $maxZ = $thickness;
$minX = -$horizontalStart; $minX = -$horizontalStart;
$maxX = $minX + $width; $maxX = $minX + $width;
break; break;
case Vector3::SIDE_WEST: case Facing::WEST:
$minX = 1 - $thickness; $minX = 1 - $thickness;
$maxX = 1; $maxX = 1;
$minZ = -$horizontalStart; $minZ = -$horizontalStart;
$maxZ = $minZ + $width; $maxZ = $minZ + $width;
break; break;
case Vector3::SIDE_EAST: case Facing::EAST:
$minX = 0; $minX = 0;
$maxX = $thickness; $maxX = $thickness;
$maxZ = $horizontalStart + 1; $maxZ = $horizontalStart + 1;
@ -253,30 +240,15 @@ class Painting extends Entity{
$horizontalStart = (int) (ceil($width / 2) - 1); $horizontalStart = (int) (ceil($width / 2) - 1);
$verticalStart = (int) (ceil($height / 2) - 1); $verticalStart = (int) (ceil($height / 2) - 1);
switch($facing){ $rotatedFace = Bearing::toFacing(Bearing::rotate(Bearing::fromFacing($facing), -1));
case Vector3::SIDE_NORTH:
$rotatedFace = Vector3::SIDE_WEST;
break;
case Vector3::SIDE_WEST:
$rotatedFace = Vector3::SIDE_SOUTH;
break;
case Vector3::SIDE_SOUTH:
$rotatedFace = Vector3::SIDE_EAST;
break;
case Vector3::SIDE_EAST:
$rotatedFace = Vector3::SIDE_NORTH;
break;
default:
return false;
}
$oppositeSide = Vector3::getOppositeSide($facing); $oppositeSide = Facing::opposite($facing);
$startPos = $blockIn->asVector3()->getSide(Vector3::getOppositeSide($rotatedFace), $horizontalStart)->getSide(Vector3::SIDE_DOWN, $verticalStart); $startPos = $blockIn->asVector3()->getSide(Facing::opposite($rotatedFace), $horizontalStart)->getSide(Facing::DOWN, $verticalStart);
for($w = 0; $w < $width; ++$w){ for($w = 0; $w < $width; ++$w){
for($h = 0; $h < $height; ++$h){ for($h = 0; $h < $height; ++$h){
$pos = $startPos->getSide($rotatedFace, $w)->getSide(Vector3::SIDE_UP, $h); $pos = $startPos->getSide($rotatedFace, $w)->getSide(Facing::UP, $h);
$block = $level->getBlockAt($pos->x, $pos->y, $pos->z); $block = $level->getBlockAt($pos->x, $pos->y, $pos->z);
if($block->isSolid() or !$block->getSide($oppositeSide)->isSolid()){ if($block->isSolid() or !$block->getSide($oppositeSide)->isSolid()){

View File

@ -27,6 +27,7 @@ use pocketmine\block\Block;
use pocketmine\entity\Entity; use pocketmine\entity\Entity;
use pocketmine\entity\object\Painting; use pocketmine\entity\object\Painting;
use pocketmine\entity\object\PaintingMotive; use pocketmine\entity\object\PaintingMotive;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\Player; use pocketmine\Player;
@ -71,10 +72,10 @@ class PaintingItem extends Item{
$motive = $motives[array_rand($motives)]; $motive = $motives[array_rand($motives)];
static $directions = [ static $directions = [
Vector3::SIDE_SOUTH => 0, Facing::SOUTH => 0,
Vector3::SIDE_WEST => 1, Facing::WEST => 1,
Vector3::SIDE_NORTH => 2, Facing::NORTH => 2,
Vector3::SIDE_EAST => 3 Facing::EAST => 3
]; ];
$direction = $directions[$face] ?? -1; $direction = $directions[$face] ?? -1;

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\tile; namespace pocketmine\tile;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\CompoundTag;
use pocketmine\Player; use pocketmine\Player;
@ -74,7 +75,7 @@ class Skull extends Spawnable{
$nbt->setByte(self::TAG_SKULL_TYPE, $item !== null ? $item->getDamage() : self::TYPE_SKELETON); $nbt->setByte(self::TAG_SKULL_TYPE, $item !== null ? $item->getDamage() : self::TYPE_SKELETON);
$rot = 0; $rot = 0;
if($face === Vector3::SIDE_UP and $player !== null){ if($face === Facing::UP and $player !== null){
$rot = floor(($player->yaw * 16 / 360) + 0.5) & 0x0F; $rot = floor(($player->yaw * 16 / 360) + 0.5) & 0x0F;
} }
$nbt->setByte(self::TAG_ROT, $rot); $nbt->setByte(self::TAG_ROT, $rot);