mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-07 18:41:47 +00:00
implement updating properly for multi-face vines
This commit is contained in:
parent
6569fdbe04
commit
9413f155ce
@ -31,7 +31,7 @@ use pocketmine\math\AxisAlignedBB;
|
|||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
|
|
||||||
class Vine extends Transparent{
|
class Vine extends Flowable{
|
||||||
const FLAG_SOUTH = 0x01;
|
const FLAG_SOUTH = 0x01;
|
||||||
const FLAG_WEST = 0x02;
|
const FLAG_WEST = 0x02;
|
||||||
const FLAG_NORTH = 0x04;
|
const FLAG_NORTH = 0x04;
|
||||||
@ -43,10 +43,6 @@ class Vine extends Transparent{
|
|||||||
$this->meta = $meta;
|
$this->meta = $meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isSolid() : bool{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getName() : string{
|
public function getName() : string{
|
||||||
return "Vines";
|
return "Vines";
|
||||||
}
|
}
|
||||||
@ -71,6 +67,10 @@ class Vine extends Transparent{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function canBeReplaced() : bool{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public function onEntityCollide(Entity $entity) : void{
|
public function onEntityCollide(Entity $entity) : void{
|
||||||
$entity->resetFallDistance();
|
$entity->resetFallDistance();
|
||||||
}
|
}
|
||||||
@ -137,42 +137,56 @@ class Vine extends Transparent{
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
|
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
|
||||||
//TODO: multiple sides
|
if(!$blockClicked->isSolid() or $face === Vector3::SIDE_UP or $face === Vector3::SIDE_DOWN){
|
||||||
if($blockClicked->isSolid()){
|
|
||||||
$faces = [
|
|
||||||
2 => self::FLAG_SOUTH,
|
|
||||||
3 => self::FLAG_NORTH,
|
|
||||||
4 => self::FLAG_EAST,
|
|
||||||
5 => self::FLAG_WEST
|
|
||||||
];
|
|
||||||
if(isset($faces[$face])){
|
|
||||||
$this->meta = $faces[$face];
|
|
||||||
$this->getLevel()->setBlock($blockReplace, $this, true, true);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$faces = [
|
||||||
|
Vector3::SIDE_NORTH => self::FLAG_SOUTH,
|
||||||
|
Vector3::SIDE_SOUTH => self::FLAG_NORTH,
|
||||||
|
Vector3::SIDE_WEST => self::FLAG_EAST,
|
||||||
|
Vector3::SIDE_EAST => self::FLAG_WEST
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->meta = $faces[$face] ?? 0;
|
||||||
|
if($blockReplace->getId() === $this->getId()){
|
||||||
|
$this->meta |= $blockReplace->meta;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->getLevel()->setBlock($blockReplace, $this, true, true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public function onUpdate(int $type){
|
public function onUpdate(int $type){
|
||||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
$sides = [
|
$sides = [
|
||||||
1 => 3,
|
self::FLAG_SOUTH => Vector3::SIDE_SOUTH,
|
||||||
2 => 4,
|
self::FLAG_WEST => Vector3::SIDE_WEST,
|
||||||
4 => 2,
|
self::FLAG_NORTH => Vector3::SIDE_NORTH,
|
||||||
8 => 5
|
self::FLAG_EAST => Vector3::SIDE_EAST
|
||||||
];
|
];
|
||||||
|
|
||||||
if(!isset($sides[$this->meta])){
|
$meta = $this->meta;
|
||||||
return false; //TODO: remove this once placing on multiple sides is supported (these are bitflags, not actual meta values
|
|
||||||
|
foreach($sides as $flag => $side){
|
||||||
|
if(($meta & $flag) === 0){
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$this->getSide($sides[$this->meta])->isSolid()){ //Replace with common break method
|
if(!$this->getSide($side)->isSolid()){
|
||||||
|
$meta &= ~$flag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($meta !== $this->meta){
|
||||||
|
if($meta === 0){
|
||||||
$this->level->useBreakOn($this);
|
$this->level->useBreakOn($this);
|
||||||
|
}else{
|
||||||
|
$this->meta = $meta;
|
||||||
|
$this->level->setBlock($this, $this);
|
||||||
|
}
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_NORMAL;
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
}
|
}
|
||||||
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
|
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user