Chest: constrain pair positions to immediately horizontally adjacent blocks

under normal circumstances a chest will never pair with a chest which isn't directly next to it anyway.
This commit is contained in:
Dylan K. Taylor 2019-06-07 17:24:59 +01:00
parent cc6296b019
commit a2274429ab

View File

@ -29,6 +29,7 @@ use pocketmine\math\Vector3;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\world\World;
use function abs;
class Chest extends Spawnable implements Container, Nameable{
use NameableTrait {
@ -59,8 +60,17 @@ class Chest extends Spawnable implements Container, Nameable{
public function readSaveData(CompoundTag $nbt) : void{
if($nbt->hasTag(self::TAG_PAIRX, IntTag::class) and $nbt->hasTag(self::TAG_PAIRZ, IntTag::class)){
$this->pairX = $nbt->getInt(self::TAG_PAIRX);
$this->pairZ = $nbt->getInt(self::TAG_PAIRZ);
$pairX = $nbt->getInt(self::TAG_PAIRX);
$pairZ = $nbt->getInt(self::TAG_PAIRZ);
if(
($this->x === $pairX and abs($this->z - $pairZ) === 1) or
($this->z === $pairZ and abs($this->x - $pairX) === 1)
){
$this->pairX = $pairX;
$this->pairZ = $pairZ;
}else{
$this->pairX = $this->pairZ = null;
}
}
$this->loadName($nbt);
$this->loadItems($nbt);