mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 16:59:44 +00:00
Use Block objects more instead of legacy ID/meta crap
This commit is contained in:
parent
7399e9036a
commit
d8ea8fa0f0
@ -29,7 +29,6 @@ use pocketmine\block\Fallable;
|
||||
use pocketmine\entity\Entity;
|
||||
use pocketmine\event\entity\EntityBlockChangeEvent;
|
||||
use pocketmine\event\entity\EntityDamageEvent;
|
||||
use pocketmine\item\ItemFactory;
|
||||
use pocketmine\level\Position;
|
||||
use pocketmine\nbt\tag\ByteTag;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
@ -111,7 +110,7 @@ class FallingBlock extends Entity{
|
||||
$block = $this->level->getBlock($pos);
|
||||
if($block->getId() > 0 and $block->isTransparent() and !$block->canBeReplaced()){
|
||||
//FIXME: anvils are supposed to destroy torches
|
||||
$this->getLevel()->dropItem($this, ItemFactory::get($this->getBlock(), $this->getDamage()));
|
||||
$this->getLevel()->dropItem($this, $this->block->getItem());
|
||||
}else{
|
||||
$ev = new EntityBlockChangeEvent($this, $block, $blockTarget ?? $this->block);
|
||||
$ev->call();
|
||||
@ -126,12 +125,8 @@ class FallingBlock extends Entity{
|
||||
return $hasUpdate;
|
||||
}
|
||||
|
||||
public function getBlock() : int{
|
||||
return $this->block->getId();
|
||||
}
|
||||
|
||||
public function getDamage() : int{
|
||||
return $this->block->getDamage();
|
||||
public function getBlock() : Block{
|
||||
return $this->block;
|
||||
}
|
||||
|
||||
public function saveNBT() : CompoundTag{
|
||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\entity\projectile;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\entity\Entity;
|
||||
use pocketmine\entity\Living;
|
||||
use pocketmine\event\entity\EntityCombustByEntityEvent;
|
||||
@ -34,6 +35,7 @@ use pocketmine\event\entity\ProjectileHitBlockEvent;
|
||||
use pocketmine\event\entity\ProjectileHitEntityEvent;
|
||||
use pocketmine\event\entity\ProjectileHitEvent;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\level\Position;
|
||||
use pocketmine\math\RayTraceResult;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\math\VoxelRayTrace;
|
||||
@ -49,12 +51,8 @@ abstract class Projectile extends Entity{
|
||||
/** @var float */
|
||||
protected $damage = 0.0;
|
||||
|
||||
/** @var Vector3|null */
|
||||
/** @var Block|null */
|
||||
protected $blockHit;
|
||||
/** @var int|null */
|
||||
protected $blockHitId;
|
||||
/** @var int|null */
|
||||
protected $blockHitData;
|
||||
|
||||
public function __construct(Level $level, CompoundTag $nbt, ?Entity $shootingEntity = null){
|
||||
parent::__construct($level, $nbt);
|
||||
@ -77,12 +75,12 @@ abstract class Projectile extends Entity{
|
||||
$this->damage = $nbt->getDouble("damage", $this->damage);
|
||||
|
||||
do{
|
||||
$blockHit = null;
|
||||
$blockPos = null;
|
||||
$blockId = null;
|
||||
$blockData = null;
|
||||
|
||||
if($nbt->hasTag("tileX", IntTag::class) and $nbt->hasTag("tileY", IntTag::class) and $nbt->hasTag("tileZ", IntTag::class)){
|
||||
$blockHit = new Vector3($nbt->getInt("tileX"), $nbt->getInt("tileY"), $nbt->getInt("tileZ"));
|
||||
$blockPos = new Position($nbt->getInt("tileX"), $nbt->getInt("tileY"), $nbt->getInt("tileZ"), $this->level);
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
@ -99,9 +97,7 @@ abstract class Projectile extends Entity{
|
||||
break;
|
||||
}
|
||||
|
||||
$this->blockHit = $blockHit;
|
||||
$this->blockHitId = $blockId;
|
||||
$this->blockHitData = $blockData;
|
||||
$this->blockHit = BlockFactory::get($blockId, $blockData, $blockPos);
|
||||
}while(false);
|
||||
}
|
||||
|
||||
@ -151,8 +147,8 @@ abstract class Projectile extends Entity{
|
||||
$nbt->setInt("tileZ", $this->blockHit->z);
|
||||
|
||||
//we intentionally use different ones to PC because we don't have stringy IDs
|
||||
$nbt->setInt("blockId", $this->blockHitId);
|
||||
$nbt->setByte("blockData", $this->blockHitData);
|
||||
$nbt->setInt("blockId", $this->blockHit->getId());
|
||||
$nbt->setByte("blockData", $this->blockHit->getDamage());
|
||||
}
|
||||
|
||||
return $nbt;
|
||||
@ -163,11 +159,8 @@ abstract class Projectile extends Entity{
|
||||
}
|
||||
|
||||
public function onNearbyBlockChange() : void{
|
||||
if($this->blockHit !== null){
|
||||
$blockIn = $this->level->getBlockAt($this->blockHit->x, $this->blockHit->y, $this->blockHit->z);
|
||||
if($blockIn->getId() !== $this->blockHitId or $blockIn->getDamage() !== $this->blockHitData){
|
||||
$this->blockHit = $this->blockHitId = $this->blockHitData = null;
|
||||
}
|
||||
if($this->blockHit !== null and !$this->blockHit->isSameState($this->level->getBlock($this->blockHit))){
|
||||
$this->blockHit = null;
|
||||
}
|
||||
|
||||
parent::onNearbyBlockChange();
|
||||
@ -257,7 +250,7 @@ abstract class Projectile extends Entity{
|
||||
$this->motion->x = $this->motion->y = $this->motion->z = 0;
|
||||
}else{
|
||||
$this->isCollided = $this->onGround = false;
|
||||
$this->blockHit = $this->blockHitId = $this->blockHitData = null;
|
||||
$this->blockHit = null;
|
||||
|
||||
//recompute angles...
|
||||
$f = sqrt(($this->motion->x ** 2) + ($this->motion->z ** 2));
|
||||
@ -334,8 +327,6 @@ abstract class Projectile extends Entity{
|
||||
* @param RayTraceResult $hitResult
|
||||
*/
|
||||
protected function onHitBlock(Block $blockHit, RayTraceResult $hitResult) : void{
|
||||
$this->blockHit = $blockHit->asVector3();
|
||||
$this->blockHitId = $blockHit->getId();
|
||||
$this->blockHitData = $blockHit->getDamage();
|
||||
$this->blockHit = clone $blockHit;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user