mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-20 07:39:42 +00:00
Separate facing/bearing handling from Vector3, deobfusticate a ton of @shoghicp old code
This commit is contained in:
@@ -53,6 +53,8 @@ use pocketmine\level\Level;
|
||||
use pocketmine\level\Location;
|
||||
use pocketmine\level\Position;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
use pocketmine\math\Bearing;
|
||||
use pocketmine\math\Facing;
|
||||
use pocketmine\math\Vector2;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\metadata\Metadatable;
|
||||
@@ -1208,66 +1210,66 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
||||
|
||||
if($westNonSolid){
|
||||
$limit = $diffX;
|
||||
$direction = Vector3::SIDE_WEST;
|
||||
$direction = Facing::WEST;
|
||||
}
|
||||
|
||||
if($eastNonSolid and 1 - $diffX < $limit){
|
||||
$limit = 1 - $diffX;
|
||||
$direction = Vector3::SIDE_EAST;
|
||||
$direction = Facing::EAST;
|
||||
}
|
||||
|
||||
if($downNonSolid and $diffY < $limit){
|
||||
$limit = $diffY;
|
||||
$direction = Vector3::SIDE_DOWN;
|
||||
$direction = Facing::DOWN;
|
||||
}
|
||||
|
||||
if($upNonSolid and 1 - $diffY < $limit){
|
||||
$limit = 1 - $diffY;
|
||||
$direction = Vector3::SIDE_UP;
|
||||
$direction = Facing::UP;
|
||||
}
|
||||
|
||||
if($northNonSolid and $diffZ < $limit){
|
||||
$limit = $diffZ;
|
||||
$direction = Vector3::SIDE_NORTH;
|
||||
$direction = Facing::NORTH;
|
||||
}
|
||||
|
||||
if($southNonSolid and 1 - $diffZ < $limit){
|
||||
$direction = Vector3::SIDE_SOUTH;
|
||||
$direction = Facing::SOUTH;
|
||||
}
|
||||
|
||||
$force = lcg_value() * 0.2 + 0.1;
|
||||
|
||||
if($direction === Vector3::SIDE_WEST){
|
||||
if($direction === Facing::WEST){
|
||||
$this->motion->x = -$force;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if($direction === Vector3::SIDE_EAST){
|
||||
if($direction === Facing::EAST){
|
||||
$this->motion->x = $force;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if($direction === Vector3::SIDE_DOWN){
|
||||
if($direction === Facing::DOWN){
|
||||
$this->motion->y = -$force;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if($direction === Vector3::SIDE_UP){
|
||||
if($direction === Facing::UP){
|
||||
$this->motion->y = $force;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if($direction === Vector3::SIDE_NORTH){
|
||||
if($direction === Facing::NORTH){
|
||||
$this->motion->z = -$force;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if($direction === Vector3::SIDE_SOUTH){
|
||||
if($direction === Facing::SOUTH){
|
||||
$this->motion->z = $force;
|
||||
|
||||
return true;
|
||||
@@ -1277,25 +1279,8 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
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;
|
||||
}
|
||||
public function getDirection() : int{
|
||||
return Bearing::fromAngle($this->yaw);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -32,6 +32,8 @@ use pocketmine\item\ItemFactory;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\level\particle\DestroyBlockParticle;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
use pocketmine\math\Bearing;
|
||||
use pocketmine\math\Facing;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\nbt\tag\ByteTag;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
@@ -110,29 +112,14 @@ class Painting extends Entity{
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox() : void{
|
||||
static $directions = [
|
||||
0 => Vector3::SIDE_SOUTH,
|
||||
1 => Vector3::SIDE_WEST,
|
||||
2 => Vector3::SIDE_NORTH,
|
||||
3 => Vector3::SIDE_EAST
|
||||
];
|
||||
|
||||
$facing = $directions[$this->direction];
|
||||
|
||||
$facing = Bearing::toFacing($this->direction);
|
||||
$this->boundingBox->setBB(self::getPaintingBB($this->blockIn->getSide($facing), $facing, $this->getMotive()));
|
||||
}
|
||||
|
||||
public function onNearbyBlockChange() : void{
|
||||
parent::onNearbyBlockChange();
|
||||
|
||||
static $directions = [
|
||||
0 => Vector3::SIDE_SOUTH,
|
||||
1 => Vector3::SIDE_WEST,
|
||||
2 => Vector3::SIDE_NORTH,
|
||||
3 => Vector3::SIDE_EAST
|
||||
];
|
||||
|
||||
$face = $directions[$this->direction];
|
||||
$face = Bearing::toFacing($this->direction);
|
||||
if(!self::canFit($this->level, $this->blockIn->getSide($face), $face, false, $this->getMotive())){
|
||||
$this->kill();
|
||||
}
|
||||
@@ -170,7 +157,7 @@ class Painting extends Entity{
|
||||
return PaintingMotive::getMotiveByName($this->motive);
|
||||
}
|
||||
|
||||
public function getDirection() : ?int{
|
||||
public function getDirection() : int{
|
||||
return $this->direction;
|
||||
}
|
||||
|
||||
@@ -199,25 +186,25 @@ class Painting extends Entity{
|
||||
$maxY = $minY + $height;
|
||||
|
||||
switch($facing){
|
||||
case Vector3::SIDE_NORTH:
|
||||
case Facing::NORTH:
|
||||
$minZ = 1 - $thickness;
|
||||
$maxZ = 1;
|
||||
$maxX = $horizontalStart + 1;
|
||||
$minX = $maxX - $width;
|
||||
break;
|
||||
case Vector3::SIDE_SOUTH:
|
||||
case Facing::SOUTH:
|
||||
$minZ = 0;
|
||||
$maxZ = $thickness;
|
||||
$minX = -$horizontalStart;
|
||||
$maxX = $minX + $width;
|
||||
break;
|
||||
case Vector3::SIDE_WEST:
|
||||
case Facing::WEST:
|
||||
$minX = 1 - $thickness;
|
||||
$maxX = 1;
|
||||
$minZ = -$horizontalStart;
|
||||
$maxZ = $minZ + $width;
|
||||
break;
|
||||
case Vector3::SIDE_EAST:
|
||||
case Facing::EAST:
|
||||
$minX = 0;
|
||||
$maxX = $thickness;
|
||||
$maxZ = $horizontalStart + 1;
|
||||
@@ -253,30 +240,15 @@ class Painting extends Entity{
|
||||
$horizontalStart = (int) (ceil($width / 2) - 1);
|
||||
$verticalStart = (int) (ceil($height / 2) - 1);
|
||||
|
||||
switch($facing){
|
||||
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;
|
||||
}
|
||||
$rotatedFace = Bearing::toFacing(Bearing::rotate(Bearing::fromFacing($facing), -1));
|
||||
|
||||
$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($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);
|
||||
if($block->isSolid() or !$block->getSide($oppositeSide)->isSolid()){
|
||||
|
Reference in New Issue
Block a user