Fixed climbing blocks such as ladders and vines

Seems we can now climb ANY block if the climbing flag is true, and nothing if false. This commit adds local block checks to see if a climbable block exists at the entity's feet and if so, sets the flag.
This commit is contained in:
Dylan K. Taylor
2017-04-14 19:02:53 +01:00
parent f12a6eed29
commit 66924729ff
4 changed files with 66 additions and 5 deletions

View File

@ -454,6 +454,45 @@ abstract class Entity extends Location implements Metadatable{
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_IMMOBILE, $value);
}
/**
* Sets whether this entity is currently able to climb blocks. By default this is only true if the entity is climbing a ladder or vine or similar block.
*
* @return bool
*/
public function isClimbing() : bool{
return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_WALLCLIMBING);
}
/**
* Sets whether the entity can climb blocks. If true, the entity can climb anything, if false, they cannot climb anything (this includes ladders and vines).
*
* @param bool $value
*/
public function setClimbing(bool $value = true){
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_WALLCLIMBING, $value);
}
/**
* Checks blocks adjacent to the entity's feet to check if it is currently colliding with a climbable block.
*/
protected function checkClimbing(){
$climbing = false;
$block = $this->level->getBlock($this);
if($block->canClimb()){
$climbing = true;
}else{
for($i = 0; $i <= 5; ++$i){
if($block->getSide($i)->canClimb()){
$climbing = true;
break;
}
}
}
$this->setClimbing($climbing);
}
/**
* @return Effect[]
*/
@ -1434,6 +1473,7 @@ abstract class Entity extends Location implements Metadatable{
$this->checkChunks();
$this->checkGroundState($movX, $movY, $movZ, $dx, $dy, $dz);
$this->checkClimbing();
$this->updateFallState($dy, $this->onGround);
if($movX != $dx){