mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 16:51:42 +00:00
Fixed vine block update crashes, close #1032
The meta->side array was the wrong way round (keys & values inverted).
This commit is contained in:
parent
cc1d1b0f45
commit
1f630e57f2
@ -26,9 +26,14 @@ use pocketmine\item\Item;
|
||||
use pocketmine\item\Tool;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\Player;
|
||||
|
||||
class Vine extends Transparent{
|
||||
const FLAG_SOUTH = 0x01;
|
||||
const FLAG_WEST = 0x02;
|
||||
const FLAG_NORTH = 0x04;
|
||||
const FLAG_EAST = 0x08;
|
||||
|
||||
protected $id = self::VINE;
|
||||
|
||||
@ -75,7 +80,7 @@ class Vine extends Transparent{
|
||||
|
||||
$flag = $this->meta > 0;
|
||||
|
||||
if(($this->meta & 0x02) > 0){
|
||||
if(($this->meta & self::FLAG_WEST) > 0){
|
||||
$f4 = max($f4, 0.0625);
|
||||
$f1 = 0;
|
||||
$f2 = 0;
|
||||
@ -85,7 +90,7 @@ class Vine extends Transparent{
|
||||
$flag = true;
|
||||
}
|
||||
|
||||
if(($this->meta & 0x08) > 0){
|
||||
if(($this->meta & self::FLAG_EAST) > 0){
|
||||
$f1 = min($f1, 0.9375);
|
||||
$f4 = 1;
|
||||
$f2 = 0;
|
||||
@ -95,7 +100,7 @@ class Vine extends Transparent{
|
||||
$flag = true;
|
||||
}
|
||||
|
||||
if(($this->meta & 0x01) > 0){
|
||||
if(($this->meta & self::FLAG_SOUTH) > 0){
|
||||
$f3 = min($f3, 0.9375);
|
||||
$f6 = 1;
|
||||
$f1 = 0;
|
||||
@ -105,7 +110,7 @@ class Vine extends Transparent{
|
||||
$flag = true;
|
||||
}
|
||||
|
||||
if(!$flag and $this->getSide(1)->isSolid()){
|
||||
if(!$flag and $this->getSide(Vector3::SIDE_UP)->isSolid()){
|
||||
$f2 = min($f2, 0.9375);
|
||||
$f5 = 1;
|
||||
$f1 = 0;
|
||||
@ -126,12 +131,13 @@ class Vine extends Transparent{
|
||||
|
||||
|
||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||
//TODO: multiple sides
|
||||
if($target->isSolid()){
|
||||
$faces = [
|
||||
2 => 1,
|
||||
3 => 4,
|
||||
4 => 8,
|
||||
5 => 2,
|
||||
2 => self::FLAG_SOUTH,
|
||||
3 => self::FLAG_NORTH,
|
||||
4 => self::FLAG_EAST,
|
||||
5 => self::FLAG_WEST,
|
||||
];
|
||||
if(isset($faces[$face])){
|
||||
$this->meta = $faces[$face];
|
||||
@ -147,11 +153,16 @@ class Vine extends Transparent{
|
||||
public function onUpdate($type){
|
||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||
$sides = [
|
||||
1 => 3,
|
||||
2 => 4,
|
||||
3 => 1,
|
||||
4 => 2,
|
||||
5 => 8
|
||||
8 => 5
|
||||
];
|
||||
|
||||
if(!isset($sides[$this->meta])){
|
||||
return false; //TODO: remove this once placing on multiple sides is supported (these are bitflags, not actual meta values
|
||||
}
|
||||
|
||||
if(!$this->getSide($sides[$this->meta])->isSolid()){ //Replace with common break method
|
||||
$this->level->useBreakOn($this);
|
||||
return Level::BLOCK_UPDATE_NORMAL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user