mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
implemented multi AABB collision checks for fences and walls
fixes anti-cheat getting triggered when falling down between a square of fences fixes not being able to shoot arrows between a square of fences
This commit is contained in:
parent
3eb73ab468
commit
061a9444cc
@ -27,7 +27,7 @@ use pocketmine\item\Tool;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
use pocketmine\math\Vector3;
|
||||
|
||||
class CobblestoneWall extends Transparent{
|
||||
class CobblestoneWall extends Fence{
|
||||
const NONE_MOSSY_WALL = 0;
|
||||
const MOSSY_WALL = 1;
|
||||
|
||||
@ -37,10 +37,6 @@ class CobblestoneWall extends Transparent{
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function isSolid() : bool{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getToolType() : int{
|
||||
return Tool::TYPE_PICKAXE;
|
||||
}
|
||||
@ -57,38 +53,8 @@ class CobblestoneWall extends Transparent{
|
||||
return "Cobblestone Wall";
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox() : ?AxisAlignedBB{
|
||||
|
||||
$north = $this->canConnect($this->getSide(Vector3::SIDE_NORTH));
|
||||
$south = $this->canConnect($this->getSide(Vector3::SIDE_SOUTH));
|
||||
$west = $this->canConnect($this->getSide(Vector3::SIDE_WEST));
|
||||
$east = $this->canConnect($this->getSide(Vector3::SIDE_EAST));
|
||||
|
||||
$n = $north ? 0 : 0.25;
|
||||
$s = $south ? 1 : 0.75;
|
||||
$w = $west ? 0 : 0.25;
|
||||
$e = $east ? 1 : 0.75;
|
||||
|
||||
if($north and $south and !$west and !$east){
|
||||
$w = 0.3125;
|
||||
$e = 0.6875;
|
||||
}elseif(!$north and !$south and $west and $east){
|
||||
$n = 0.3125;
|
||||
$s = 0.6875;
|
||||
}
|
||||
|
||||
return new AxisAlignedBB(
|
||||
$this->x + $w,
|
||||
$this->y,
|
||||
$this->z + $n,
|
||||
$this->x + $e,
|
||||
$this->y + 1.5,
|
||||
$this->z + $s
|
||||
);
|
||||
}
|
||||
|
||||
public function canConnect(Block $block){
|
||||
return ($block->getId() !== self::COBBLESTONE_WALL and $block->getId() !== self::FENCE_GATE) ? $block->isSolid() and !$block->isTransparent() : true;
|
||||
public function getThickness() : float{
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,8 +32,12 @@ abstract class Fence extends Transparent{
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getThickness() : float{
|
||||
return 0.25;
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox() : ?AxisAlignedBB{
|
||||
$width = 0.375;
|
||||
$width = 0.5 - $this->getThickness() / 2;
|
||||
|
||||
return new AxisAlignedBB(
|
||||
$this->x + ($this->canConnect($this->getSide(Vector3::SIDE_WEST)) ? 0 : $width),
|
||||
@ -45,6 +49,80 @@ abstract class Fence extends Transparent{
|
||||
);
|
||||
}
|
||||
|
||||
protected function recalculateCollisionBoxes() : array{
|
||||
$inset = 0.5 - $this->getThickness() / 2;
|
||||
|
||||
$bbs = [
|
||||
new AxisAlignedBB( //centre post AABB
|
||||
$this->x + $inset,
|
||||
$this->y,
|
||||
$this->z + $inset,
|
||||
$this->x + 1 - $inset,
|
||||
$this->y + 1.5,
|
||||
$this->z + 1 - $inset
|
||||
)
|
||||
];
|
||||
|
||||
if($this->canConnect($this->getSide(Vector3::SIDE_WEST))){
|
||||
//western side connected part from start X to post (negative X)
|
||||
//
|
||||
// -#
|
||||
//
|
||||
$bbs[] = new AxisAlignedBB(
|
||||
$this->x,
|
||||
$this->y,
|
||||
$this->z + $inset,
|
||||
$this->x + $inset, //don't overlap with centre post
|
||||
$this->y + 1.5,
|
||||
$this->z + 1 - $inset
|
||||
);
|
||||
}
|
||||
if($this->canConnect($this->getSide(Vector3::SIDE_EAST))){
|
||||
//eastern side connected part from post to end X (positive X)
|
||||
//
|
||||
// #-
|
||||
//
|
||||
$bbs[] = new AxisAlignedBB(
|
||||
$this->x + 1 - $inset,
|
||||
$this->y,
|
||||
$this->z + $inset,
|
||||
$this->x + 1,
|
||||
$this->y + 1.5,
|
||||
$this->z + 1 - $inset
|
||||
);
|
||||
}
|
||||
if($this->canConnect($this->getSide(Vector3::SIDE_NORTH))){
|
||||
//northern side connected part from start Z to post (negative Z)
|
||||
// |
|
||||
// #
|
||||
//
|
||||
$bbs[] = new AxisAlignedBB(
|
||||
$this->x + $inset,
|
||||
$this->y,
|
||||
$this->z,
|
||||
$this->x + 1 - $inset,
|
||||
$this->y + 1.5,
|
||||
$this->z + $inset
|
||||
);
|
||||
}
|
||||
if($this->canConnect($this->getSide(Vector3::SIDE_SOUTH))){
|
||||
//southern side connected part from post to end Z (positive Z)
|
||||
//
|
||||
// #
|
||||
// |
|
||||
$bbs[] = new AxisAlignedBB(
|
||||
$this->x + $inset,
|
||||
$this->y,
|
||||
$this->z + 1 - $inset,
|
||||
$this->x + 1 - $inset,
|
||||
$this->y + 1.5,
|
||||
$this->z + 1
|
||||
);
|
||||
}
|
||||
|
||||
return $bbs;
|
||||
}
|
||||
|
||||
public function canConnect(Block $block){
|
||||
return $block instanceof static or $block instanceof FenceGate or ($block->isSolid() and !$block->isTransparent());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user