mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-08 20:58:34 +00:00
Merge pull request #2225 from PEMapModder/falling-sand
Update FallingBlock to new Anvil formats, possible fix for #2189
This commit is contained in:
commit
db8ac0b9cb
@ -29,6 +29,7 @@ use pocketmine\nbt\tag\Compound;
|
|||||||
use pocketmine\nbt\tag\Double;
|
use pocketmine\nbt\tag\Double;
|
||||||
use pocketmine\nbt\tag\Enum;
|
use pocketmine\nbt\tag\Enum;
|
||||||
use pocketmine\nbt\tag\Float;
|
use pocketmine\nbt\tag\Float;
|
||||||
|
use pocketmine\nbt\tag\Int;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
|
|
||||||
abstract class Fallable extends Solid{
|
abstract class Fallable extends Solid{
|
||||||
@ -60,7 +61,8 @@ abstract class Fallable extends Solid{
|
|||||||
new Float("", 0),
|
new Float("", 0),
|
||||||
new Float("", 0)
|
new Float("", 0)
|
||||||
]),
|
]),
|
||||||
"Tile" => new Byte("Tile", $this->getID())
|
"TileID" => new Int("TileID", $this->getID()),
|
||||||
|
"Data" => new Byte("Data", $this->getDamage()),
|
||||||
]));
|
]));
|
||||||
|
|
||||||
$fall->spawnToAll();
|
$fall->spawnToAll();
|
||||||
|
@ -28,6 +28,7 @@ use pocketmine\event\entity\EntityDamageEvent;
|
|||||||
use pocketmine\event\entity\EntityRegainHealthEvent;
|
use pocketmine\event\entity\EntityRegainHealthEvent;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\nbt\tag\Byte;
|
use pocketmine\nbt\tag\Byte;
|
||||||
|
use pocketmine\nbt\tag\Int;
|
||||||
use pocketmine\nbt\tag\String;
|
use pocketmine\nbt\tag\String;
|
||||||
use pocketmine\network\protocol\AddEntityPacket;
|
use pocketmine\network\protocol\AddEntityPacket;
|
||||||
use pocketmine\network\protocol\SetEntityMotionPacket;
|
use pocketmine\network\protocol\SetEntityMotionPacket;
|
||||||
@ -44,13 +45,18 @@ class FallingBlock extends Entity{
|
|||||||
protected $gravity = 0.04;
|
protected $gravity = 0.04;
|
||||||
protected $drag = 0.02;
|
protected $drag = 0.02;
|
||||||
protected $blockId = 0;
|
protected $blockId = 0;
|
||||||
|
protected $damage;
|
||||||
|
|
||||||
public $canCollide = false;
|
public $canCollide = false;
|
||||||
|
|
||||||
protected function initEntity(){
|
protected function initEntity(){
|
||||||
$this->namedtag->id = new String("id", "FallingSand");
|
$this->namedtag->id = new String("id", "FallingSand");
|
||||||
if(isset($this->namedtag->Tile)){
|
if(isset($this->namedtag->TileID)){
|
||||||
|
$this->blockId = $this->namedtag["TileID"];
|
||||||
|
}
|
||||||
|
elseif(isset($this->namedtag->Tile)){
|
||||||
$this->blockId = $this->namedtag["Tile"];
|
$this->blockId = $this->namedtag["Tile"];
|
||||||
|
$this->namedtag["TileID"] = new Int("TileID", $this->blockId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->blockId === 0){
|
if($this->blockId === 0){
|
||||||
@ -106,9 +112,9 @@ class FallingBlock extends Entity{
|
|||||||
$this->kill();
|
$this->kill();
|
||||||
$block = $this->level->getBlock($pos);
|
$block = $this->level->getBlock($pos);
|
||||||
if(!$block->isFullBlock){
|
if(!$block->isFullBlock){
|
||||||
$this->getLevel()->dropItem($this, Item::get($this->getBlock(), 0, 1));
|
$this->getLevel()->dropItem($this, Item::get($this->getBlock(), $this->getDamage(), 1));
|
||||||
}else{
|
}else{
|
||||||
$this->server->getPluginManager()->callEvent($ev = new EntityBlockChangeEvent($this, $block, Block::get($this->getBlock(), 0)));
|
$this->server->getPluginManager()->callEvent($ev = new EntityBlockChangeEvent($this, $block, Block::get($this->getBlock(), $this->getDamage())));
|
||||||
if(!$ev->isCancelled()){
|
if(!$ev->isCancelled()){
|
||||||
$this->getLevel()->setBlock($pos, $ev->getTo(), true);
|
$this->getLevel()->setBlock($pos, $ev->getTo(), true);
|
||||||
}
|
}
|
||||||
@ -125,9 +131,13 @@ class FallingBlock extends Entity{
|
|||||||
public function getBlock(){
|
public function getBlock(){
|
||||||
return $this->blockId;
|
return $this->blockId;
|
||||||
}
|
}
|
||||||
|
public function getDamage(){
|
||||||
|
return $this->damage;
|
||||||
|
}
|
||||||
|
|
||||||
public function saveNBT(){
|
public function saveNBT(){
|
||||||
$this->namedtag->Tile = new Byte("Tile", $this->blockId);
|
$this->namedtag->TileID = new Int("TileID", $this->blockId);
|
||||||
|
$this->namedtag->Data = new Byte("Data", $this->damage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){
|
public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user