mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-11 05:55:33 +00:00
Implemented dragon egg
This commit is contained in:
parent
2d51622b12
commit
53af7f5da8
@ -114,6 +114,7 @@ class BlockFactory{
|
||||
self::register(new DoublePlant(new BID(Block::DOUBLE_PLANT, 5), "Peony"));
|
||||
self::register(new DoubleTallGrass(new BID(Block::DOUBLE_PLANT, 2), "Double Tallgrass"));
|
||||
self::register(new DoubleTallGrass(new BID(Block::DOUBLE_PLANT, 3), "Large Fern"));
|
||||
self::register(new DragonEgg(new BID(Block::DRAGON_EGG), "Dragon Egg"));
|
||||
self::register(new Emerald(new BID(Block::EMERALD_BLOCK), "Emerald Block"));
|
||||
self::register(new EmeraldOre(new BID(Block::EMERALD_ORE), "Emerald Ore"));
|
||||
self::register(new EnchantingTable(new BID(Block::ENCHANTING_TABLE, 0, null, \pocketmine\tile\EnchantTable::class), "Enchanting Table"));
|
||||
|
87
src/pocketmine/block/DragonEgg.php
Normal file
87
src/pocketmine/block/DragonEgg.php
Normal file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\Fallable;
|
||||
use pocketmine\block\utils\FallableTrait;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\TieredTool;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\level\particle\DragonEggTeleportParticle;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\Player;
|
||||
use function max;
|
||||
use function min;
|
||||
use function mt_rand;
|
||||
|
||||
class DragonEgg extends Transparent implements Fallable{
|
||||
use FallableTrait;
|
||||
|
||||
public function getHardness() : float{
|
||||
return 3;
|
||||
}
|
||||
|
||||
public function getToolType() : int{
|
||||
return BlockToolType::TYPE_PICKAXE;
|
||||
}
|
||||
|
||||
public function getToolHarvestLevel() : int{
|
||||
return TieredTool::TIER_WOODEN;
|
||||
}
|
||||
|
||||
public function getLightLevel() : int{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function tickFalling() : ?Block{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||
$this->teleport();
|
||||
return true;
|
||||
}
|
||||
|
||||
public function onAttack(Item $item, int $face, ?Player $player = null) : bool{
|
||||
$this->teleport();
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function teleport() : void{
|
||||
for($tries = 0; $tries < 16; ++$tries){
|
||||
$block = $this->level->getBlockAt(
|
||||
$this->x + mt_rand(-16, 16),
|
||||
max(0, min(Level::Y_MAX - 1, $this->y + mt_rand(-8, 8))),
|
||||
$this->z + mt_rand(-16, 16)
|
||||
);
|
||||
if($block instanceof Air){
|
||||
$this->level->addParticle($this, new DragonEggTeleportParticle($this->x - $block->x, $this->y - $block->y, $this->z - $block->z));
|
||||
//TODO: add events
|
||||
$this->level->setBlock($this, BlockFactory::get(Block::AIR));
|
||||
$this->level->setBlock($block, $this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
66
src/pocketmine/level/particle/DragonEggTeleportParticle.php
Normal file
66
src/pocketmine/level/particle/DragonEggTeleportParticle.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\level\particle;
|
||||
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\network\mcpe\protocol\LevelEventPacket;
|
||||
use function abs;
|
||||
|
||||
class DragonEggTeleportParticle implements Particle{
|
||||
|
||||
/** @var int */
|
||||
private $xDiff;
|
||||
/** @var int */
|
||||
private $yDiff;
|
||||
/** @var int */
|
||||
private $zDiff;
|
||||
|
||||
public function __construct(int $xDiff, int $yDiff, int $zDiff){
|
||||
$this->xDiff = self::boundOrThrow($xDiff);
|
||||
$this->yDiff = self::boundOrThrow($yDiff);
|
||||
$this->zDiff = self::boundOrThrow($zDiff);
|
||||
}
|
||||
|
||||
private static function boundOrThrow(int $v) : int{
|
||||
if($v < -255 or $v > 255){
|
||||
throw new \InvalidArgumentException("Value must be between -255 and 255");
|
||||
}
|
||||
return $v;
|
||||
}
|
||||
|
||||
public function encode(Vector3 $pos){
|
||||
$pk = new LevelEventPacket();
|
||||
$pk->evid = LevelEventPacket::EVENT_PARTICLE_DRAGON_EGG_TELEPORT;
|
||||
$pk->position = $pos;
|
||||
$pk->data =
|
||||
($this->zDiff < 0 ? 1 << 26 : 0) |
|
||||
($this->yDiff < 0 ? 1 << 25 : 0) |
|
||||
($this->xDiff < 0 ? 1 << 24 : 0) |
|
||||
(abs($this->xDiff) << 16) |
|
||||
(abs($this->yDiff) << 8) |
|
||||
abs($this->zDiff);
|
||||
|
||||
return $pk;
|
||||
}
|
||||
}
|
@ -81,6 +81,7 @@ class LevelEventPacket extends DataPacket implements ClientboundPacket{
|
||||
|
||||
public const EVENT_PARTICLE_BLOCK_FORCE_FIELD = 2008;
|
||||
public const EVENT_PARTICLE_PROJECTILE_HIT = 2009;
|
||||
public const EVENT_PARTICLE_DRAGON_EGG_TELEPORT = 2010;
|
||||
|
||||
public const EVENT_PARTICLE_ENDERMAN_TELEPORT = 2013;
|
||||
public const EVENT_PARTICLE_PUNCH_BLOCK = 2014;
|
||||
|
Loading…
x
Reference in New Issue
Block a user