Skip to content
This repository was archived by the owner on Feb 3, 2023. It is now read-only.

Commit 1059eef

Browse files
committed
Added EndCrystal
1 parent 19d8ac9 commit 1059eef

File tree

4 files changed

+141
-1
lines changed

4 files changed

+141
-1
lines changed

src/pocketmine/entity/Entity.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
use pocketmine\entity\hostile\Stray;
4444
use pocketmine\entity\hostile\Zombie;
4545
use pocketmine\entity\object\ArmorStand;
46+
use pocketmine\entity\object\EnderCrystal;
4647
use pocketmine\entity\object\ExperienceOrb;
4748
use pocketmine\entity\object\FallingBlock;
4849
use pocketmine\entity\object\FireworksRocket;
@@ -409,6 +410,7 @@ public static function init() : void{
409410
Entity::registerEntity(FireworksRocket::class, false, ['FireworksRocket', 'minecraft:fireworks_rocket']);
410411
Entity::registerEntity(Slime::class, false, ['Slime', 'minecraft:slime']);
411412
Entity::registerEntity(MagmaCube::class, false, ['MagmaCube', 'minecraft:magma_cube']);
413+
Entity::registerEntity(EnderCrystal::class, false, ['EnderCrystal', 'minecraft:ender_crystal']);
412414

413415
Entity::registerEntity(Human::class, true);
414416

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
/*
4+
* _ _
5+
* /\ | | |
6+
* / \ | | |_ __ _ _ _
7+
* / /\ \ | | __/ _` | | | |
8+
* / ____ \| | || (_| | |_| |
9+
* /_/ \_|_|\__\__,_|\__, |
10+
* __/ |
11+
* |___/
12+
*
13+
* This program is free software: you can redistribute it and/or modify
14+
* it under the terms of the GNU Lesser General Public License as published by
15+
* the Free Software Foundation, either version 3 of the License, or
16+
* (at your option) any later version.
17+
*
18+
* @author TuranicTeam
19+
* @link https://github.com/TuranicTeam/Altay
20+
*
21+
*/
22+
23+
declare(strict_types=1);
24+
25+
namespace pocketmine\entity\object;
26+
27+
use pocketmine\block\Block;
28+
use pocketmine\block\Fire;
29+
use pocketmine\entity\Entity;
30+
use pocketmine\event\entity\EntityDamageEvent;
31+
use pocketmine\level\Explosion;
32+
use pocketmine\level\GameRules;
33+
use pocketmine\level\generator\end\End;
34+
35+
class EnderCrystal extends Entity{
36+
public const NETWORK_ID = self::ENDER_CRYSTAL;
37+
38+
public $height = 0.98;
39+
public $width = 0.98;
40+
41+
public $gravity = 0;
42+
public $drag = 0;
43+
44+
public function onMovementUpdate() : void{
45+
// NOOP
46+
}
47+
48+
public function onUpdate(int $currentTick) : bool{
49+
if($this->level->getProvider()->getPath() === End::class){
50+
if($this->level->getBlock($this)->getId() !== Block::FIRE){
51+
$this->level->setBlock($this, new Fire());
52+
}
53+
}
54+
55+
return parent::onUpdate($currentTick);
56+
}
57+
58+
public function attack(EntityDamageEvent $source) : void{
59+
parent::attack($source);
60+
61+
if(!$source->isCancelled() and $source->getCause() !== EntityDamageEvent::CAUSE_FIRE and $source->getCause() !== EntityDamageEvent::CAUSE_FIRE_TICK){
62+
$this->flagForDespawn();
63+
64+
if($this->level->getGameRules()->getBool(GameRules::RULE_TNT_EXPLODES)){
65+
$exp = new Explosion($this, 6, $this);
66+
67+
$exp->explodeA();
68+
$exp->explodeB();
69+
}
70+
}
71+
}
72+
73+
public function canBeCollidedWith() : bool{
74+
return false;
75+
}
76+
77+
public function setShowBase(bool $value) : void{
78+
$this->setGenericFlag(self::DATA_FLAG_SHOWBASE, $value);
79+
}
80+
81+
public function showBase() : bool{
82+
return $this->getGenericFlag(self::DATA_FLAG_SHOWBASE);
83+
}
84+
}

src/pocketmine/item/EndCrystal.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/*
4+
* _ _
5+
* /\ | | |
6+
* / \ | | |_ __ _ _ _
7+
* / /\ \ | | __/ _` | | | |
8+
* / ____ \| | || (_| | |_| |
9+
* /_/ \_|_|\__\__,_|\__, |
10+
* __/ |
11+
* |___/
12+
*
13+
* This program is free software: you can redistribute it and/or modify
14+
* it under the terms of the GNU Lesser General Public License as published by
15+
* the Free Software Foundation, either version 3 of the License, or
16+
* (at your option) any later version.
17+
*
18+
* @author TuranicTeam
19+
* @link https://github.com/TuranicTeam/Altay
20+
*
21+
*/
22+
23+
declare(strict_types=1);
24+
25+
namespace pocketmine\item;
26+
27+
use pocketmine\block\Block;
28+
use pocketmine\block\Obsidian;
29+
use pocketmine\entity\Entity;
30+
use pocketmine\entity\object\EnderCrystal;
31+
use pocketmine\math\Vector3;
32+
use pocketmine\Player;
33+
34+
class EndCrystal extends Item{
35+
36+
public function __construct(int $meta = 0){
37+
parent::__construct(self::END_CRYSTAL, $meta, "End Crystal");
38+
}
39+
40+
public function onActivate(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector) : bool{
41+
if($player->level->getBlock($blockReplace->down()) instanceof Obsidian){
42+
$crystal = new EnderCrystal($player->level, Entity::createBaseNBT($blockReplace->add(0.5, 0.5, 0.5)));
43+
$crystal->spawnToAll();
44+
45+
if($player->isSurvival()){
46+
$this->pop();
47+
}
48+
49+
return true;
50+
}
51+
52+
return false;
53+
}
54+
}

src/pocketmine/item/ItemFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public static function init(){
219219
self::registerItem(new RawMutton());
220220
self::registerItem(new CookedMutton());
221221
self::registerItem(new ArmorStand());
222-
//TODO: END_CRYSTAL
222+
self::registerItem(new EndCrystal());
223223
self::registerItem(new ItemBlock(Block::SPRUCE_DOOR_BLOCK, 0, Item::SPRUCE_DOOR));
224224
self::registerItem(new ItemBlock(Block::BIRCH_DOOR_BLOCK, 0, Item::BIRCH_DOOR));
225225
self::registerItem(new ItemBlock(Block::JUNGLE_DOOR_BLOCK, 0, Item::JUNGLE_DOOR));

0 commit comments

Comments
 (0)