Skip to content

Instantly share code, notes, and snippets.

@alejandroliu
Created June 15, 2015 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alejandroliu/7927c31d463748a24142 to your computer and use it in GitHub Desktop.
Save alejandroliu/7927c31d463748a24142 to your computer and use it in GitHub Desktop.
Fix lingering tile entities
<?php
/**
* Fixes flying tile entities when teleporting worlds.
*
* @name teleportFix
* @main aliuly\hack\teleportFix
* @version 1.0.0
* @api 1.12.0
* @description Fixes flying tile entities when teleporting worlds.
* @author aliuly
*/
namespace aliuly\hack{
use pocketmine\plugin\PluginBase;
use pocketmine\event\Listener;
use pocketmine\event\entity\EntityTeleportEvent;
use pocketmine\network\protocol\UpdateBlockPacket;
use pocketmine\Player;
class teleportFix extends PluginBase implements Listener{
public function onEnable(){
$this->getServer()->getPluginManager()->registerEvents($this, $this);
}
/**
* @priority MONITOR
*/
public function onTeleport(EntityTeleportEvent $ev){
if ($ev->isCancelled()) return;
$pl = $ev->getEntity();
if (!($pl instanceof Player)) return;
$from = $ev->getFrom()->getLevel();
$to = $ev->getTo()->getLevel();
if (!$from) return;
if (!$to) return;
if ($from === $to) return;
//TODO HACK: removes tile entities that linger whenever
// to a different world
$pk = new UpdateBlockPacket();
foreach($from->getTiles() as $tile){
$pk->records[] = [$tile->x, $tile->z, $tile->y, 0, 0, UpdateBlockPacket::FLAG_NONE];
}
if(count($pk->records)) $pl->dataPacket($pk);
}
}
}
@TonyDroidd
Copy link

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment