Last active
January 20, 2018 20:17
-
-
Save BEcraft/81efec106e39876a9f6201aa690cc9fe to your computer and use it in GitHub Desktop.
PocketMine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @name EggProjectile | |
* @author BEcraft | |
* @api 3.0.0 | |
* @main BEcraft\EggProjectile\Loader | |
* @version 1.0 | |
*/ | |
namespace BEcraft\EggProjectile; | |
//paintball | |
//dont matter about the name xD | |
use pocketmine\plugin\PluginBase; | |
use pocketmine\event\Listener; | |
use pocketmine\block\Block; | |
use pocketmine\entity\Snowball; | |
use pocketmine\item\Item; | |
use pocketmine\Player; | |
use pocketmine\math\Vector3; | |
use pocketmine\nbt\tag\CompoundTag; | |
use pocketmine\nbt\tag\ByteTag; | |
use pocketmine\nbt\tag\DoubleTag; | |
use pocketmine\nbt\tag\FloatTag; | |
use pocketmine\nbt\tag\ListTag; | |
use pocketmine\nbt\tag\IntTag; | |
use pocketmine\entity\Entity; | |
use pocketmine\entity\FallingSand; | |
use pocketmine\event\entity\ProjectileHitEvent; | |
class Loader extends PluginBase implements Listener{ | |
public function onEnable(){ | |
$this->getServer()->getPluginManager()->registerEvents($this, $this); | |
} | |
public function onHit(ProjectileHitEvent $event){ | |
if(($snowball = $event->getEntity()) instanceof Snowball){ | |
if(($player = $snowball->getOwningEntity()) instanceof Player and $player->getInventory()->contains(Item::get(Block::TNT, 0))){ | |
$block = $player->getLevel()->getBlock(new Vector3($snowball->getX(), $snowball->getY(), $snowball->getZ())); | |
$blocks = []; | |
if($block->getId() === Block::AIR){ | |
for($i = 0; $i < 6; ++$i){ | |
if(($block = $block->getSide($i))->getId() !== Block::AIR){ | |
break; | |
} | |
} | |
} | |
if($block->getId() === Block::AIR){ | |
return false; | |
} | |
for($x = $block->getX()-1; $x < $block->getX()+1; ++$x){ | |
for($y = $block->getY()-1; $y < $block->getY()+1; ++$y){ | |
for($z = $block->getZ()-1; $z < $block->getZ()+1; ++$z){ | |
if(($newBlock = $player->getLevel()->getBlock(new Vector3($x, $y, $z)))->getId() !== Block::BEDROCK){ | |
array_push($blocks, $newBlock); | |
} | |
} | |
} | |
} | |
if(!empty($blocks)){ | |
unset($block); | |
foreach($blocks as $block){ | |
$player->getLevel()->setBlock(new Vector3($block->getX(), $block->getY(), $block->getZ()), Block::get(Block::AIR, 0)); | |
DataManager::createFakeBlock($block); | |
} | |
unset($blocks); | |
} | |
} | |
} | |
} | |
} | |
class DataManager{ | |
public static function createFakeBlock(Block $block){ | |
$nbt = new CompoundTag(); | |
$nbt->Pos = new ListTag("Pos", [new DoubleTag("", $block->getX()), new DoubleTag("", $block->getY()), new DoubleTag("", $block->getZ())]); | |
$nbt->Motion = new ListTag("Motion", [new DoubleTag("", -sin(mt_rand(1, 360)/60*M_PI)), new DoubleTag("", -sin(-50/100*M_PI)), new DoubleTag("", cos(mt_rand(1, 360)/60*M_PI))]); | |
$nbt->Rotation = new ListTag("Rotation", [new FloatTag("", 0.0), new FloatTag("", 0.0)]); | |
$nbt->TileID = new IntTag("TileID", $block->getId()); | |
$nbt->Data = new ByteTag("Data", $block->getDamage()); | |
$block = Entity::createEntity("FallingSand", $block->level, $nbt); | |
$block->spawnToAll(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment