Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented End Crystal #4715

Open
wants to merge 24 commits into
base: minor-next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ private function register1to1ItemMappings() : void{
$this->map1to1Item(Ids::EGG, Items::EGG());
$this->map1to1Item(Ids::EMERALD, Items::EMERALD());
$this->map1to1Item(Ids::ENCHANTED_GOLDEN_APPLE, Items::ENCHANTED_GOLDEN_APPLE());
$this->map1to1Item(Ids::END_CRYSTAL, Items::END_CRYSTAL());
$this->map1to1Item(Ids::ENDER_PEARL, Items::ENDER_PEARL());
$this->map1to1Item(Ids::EXPERIENCE_BOTTLE, Items::EXPERIENCE_BOTTLE());
$this->map1to1Item(Ids::FEATHER, Items::FEATHER());
Expand Down
5 changes: 5 additions & 0 deletions src/entity/EntityFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use pocketmine\data\bedrock\PotionTypeIds;
use pocketmine\data\SavedDataLoadingException;
use pocketmine\entity\EntityDataHelper as Helper;
use pocketmine\entity\object\EnderCrystal;
use pocketmine\entity\object\ExperienceOrb;
use pocketmine\entity\object\FallingBlock;
use pocketmine\entity\object\ItemEntity;
Expand Down Expand Up @@ -92,6 +93,10 @@ public function __construct(){
return new Egg(Helper::parseLocation($nbt, $world), null, $nbt);
}, ['Egg', 'minecraft:egg']);

$this->register(EnderCrystal::class, function(World $world, CompoundTag $nbt) : EnderCrystal{
return new EnderCrystal(EntityDataHelper::parseLocation($nbt, $world), $nbt);
}, ['EnderCrystal', 'minecraft:ender_crystal']);

$this->register(EnderPearl::class, function(World $world, CompoundTag $nbt) : EnderPearl{
return new EnderPearl(Helper::parseLocation($nbt, $world), null, $nbt);
}, ['ThrownEnderpearl', 'minecraft:ender_pearl']);
Expand Down
109 changes: 109 additions & 0 deletions src/entity/object/EnderCrystal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?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\entity\object;

use pocketmine\entity\Entity;
use pocketmine\entity\EntitySizeInfo;
use pocketmine\entity\Explosive;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityPreExplodeEvent;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags;
use pocketmine\world\Explosion;
use pocketmine\world\Position;

class EnderCrystal extends Entity implements Explosive{
ipad54 marked this conversation as resolved.
Show resolved Hide resolved
private const TAG_SHOWBASE = "ShowBottom"; //TAG_Byte

public static function getNetworkTypeId() : string{ return EntityIds::ENDER_CRYSTAL; }

protected bool $showBase = false;

protected function getInitialSizeInfo() : EntitySizeInfo{ return new EntitySizeInfo(2.0, 2.0); }

protected function getInitialDragMultiplier() : float{ return 1.0; }

protected function getInitialGravity() : float{ return 0.0; }

public function isFireProof() : bool{
return true;
}

public function showBase() : bool{
return $this->showBase;
}

public function setShowBase(bool $showBase) : void{
$this->showBase = $showBase;
$this->networkPropertiesDirty = true;
}

public function attack(EntityDamageEvent $source) : void{
parent::attack($source);
if(
$source->getCause() !== EntityDamageEvent::CAUSE_VOID &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Java code suggests that explosion causes should be added to this (end crystals don't explode when destroyed by other end crystals).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(end crystals don't explode when destroyed by other end crystals).

They do it in bedrock

!$this->isFlaggedForDespawn() &&
!$source->isCancelled()
){
$this->flagForDespawn();
$this->explode();
}
}

protected function initEntity(CompoundTag $nbt) : void{
parent::initEntity($nbt);

$this->setMaxHealth(1);
$this->setHealth(1);

$this->setShowBase($nbt->getByte(self::TAG_SHOWBASE, 0) === 1);
}

public function saveNBT() : CompoundTag{
$nbt = parent::saveNBT();

$nbt->setByte(self::TAG_SHOWBASE, $this->showBase ? 1 : 0);
return $nbt;
}

public function explode() : void{
$ev = new EntityPreExplodeEvent($this, 6);
$ev->call();
if(!$ev->isCancelled()){
$explosion = new Explosion(Position::fromObject($this->location->add(0, $this->size->getHeight() / 2, 0), $this->getWorld()), $ev->getRadius(), $this);
ipad54 marked this conversation as resolved.
Show resolved Hide resolved
if($ev->isBlockBreaking()){
$explosion->explodeA();
}
$explosion->explodeB();
}
}

protected function syncNetworkData(EntityMetadataCollection $properties) : void{
parent::syncNetworkData($properties);

$properties->setGenericFlag(EntityMetadataFlags::SHOWBASE, $this->showBase);
}
}
3 changes: 2 additions & 1 deletion src/entity/projectile/Projectile.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use pocketmine\entity\Entity;
use pocketmine\entity\Living;
use pocketmine\entity\Location;
use pocketmine\entity\object\EnderCrystal;
use pocketmine\event\entity\EntityCombustByEntityEvent;
use pocketmine\event\entity\EntityDamageByChildEntityEvent;
use pocketmine\event\entity\EntityDamageByEntityEvent;
Expand Down Expand Up @@ -96,7 +97,7 @@ protected function initEntity(CompoundTag $nbt) : void{
}

public function canCollideWith(Entity $entity) : bool{
return $entity instanceof Living && !$this->onGround;
return ($entity instanceof Living || $entity instanceof EnderCrystal) && !$this->onGround;
}

public function canBeCollidedWith() : bool{
Expand Down
59 changes: 59 additions & 0 deletions src/item/EndCrystal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?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\item;

use pocketmine\block\Block;
use pocketmine\block\BlockTypeIds;
use pocketmine\entity\Location;
use pocketmine\entity\object\EnderCrystal;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
use function count;

class EndCrystal extends Item{

public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{
ipad54 marked this conversation as resolved.
Show resolved Hide resolved
if($blockClicked->getTypeId() === BlockTypeIds::OBSIDIAN || $blockClicked->getTypeId() === BlockTypeIds::BEDROCK){
$pos = $blockClicked->getPosition();
$world = $pos->getWorld();
$bb = AxisAlignedBB::one()
ipad54 marked this conversation as resolved.
Show resolved Hide resolved
->offset($pos->getX(), $pos->getY(), $pos->getZ())
->extend(Facing::UP, 1);
if(
count($world->getNearbyEntities($bb)) === 0 &&
ipad54 marked this conversation as resolved.
Show resolved Hide resolved
$world->getBlock($pos->up())->getTypeId() === BlockTypeIds::AIR &&
$world->getBlock($pos->up(2))->getTypeId() === BlockTypeIds::AIR
ipad54 marked this conversation as resolved.
Show resolved Hide resolved
){
$crystal = new EnderCrystal(Location::fromObject($pos->add(0.5, 1, 0.5), $world));
$crystal->spawnToAll();

$this->pop();
return ItemUseResult::SUCCESS();
}
}
return ItemUseResult::NONE();
}
}
3 changes: 2 additions & 1 deletion src/item/ItemTypeIds.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,9 @@ private function __construct(){
public const MANGROVE_BOAT = 20264;
public const GLOW_BERRIES = 20265;
public const CHERRY_SIGN = 20266;
public const END_CRYSTAL = 20267;

public const FIRST_UNUSED_ITEM_ID = 20267;
public const FIRST_UNUSED_ITEM_ID = 20268;

private static int $nextDynamicId = self::FIRST_UNUSED_ITEM_ID;

Expand Down
1 change: 1 addition & 0 deletions src/item/StringToItemParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,7 @@ private static function registerItems(self $result) : void{
$result->register("emerald", fn() => Items::EMERALD());
$result->register("enchanted_golden_apple", fn() => Items::ENCHANTED_GOLDEN_APPLE());
$result->register("enchanting_bottle", fn() => Items::EXPERIENCE_BOTTLE());
$result->register("end_crystal", fn() => VanillaItems::END_CRYSTAL());
$result->register("ender_pearl", fn() => Items::ENDER_PEARL());
$result->register("experience_bottle", fn() => Items::EXPERIENCE_BOTTLE());
$result->register("eye_drops", fn() => Items::MEDICINE()->setType(MedicineType::EYE_DROPS()));
Expand Down
2 changes: 2 additions & 0 deletions src/item/VanillaItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
* @method static Item EMERALD()
* @method static GoldenAppleEnchanted ENCHANTED_GOLDEN_APPLE()
* @method static EnderPearl ENDER_PEARL()
* @method static EndCrystal END_CRYSTAL()
* @method static ExperienceBottle EXPERIENCE_BOTTLE()
* @method static Item FEATHER()
* @method static Item FERMENTED_SPIDER_EYE()
Expand Down Expand Up @@ -430,6 +431,7 @@ protected static function setup() : void{
self::register("egg", new Egg(new IID(Ids::EGG), "Egg"));
self::register("emerald", new Item(new IID(Ids::EMERALD), "Emerald"));
self::register("enchanted_golden_apple", new GoldenAppleEnchanted(new IID(Ids::ENCHANTED_GOLDEN_APPLE), "Enchanted Golden Apple"));
self::register("end_crystal", new EndCrystal(new IID(Ids::END_CRYSTAL), "End Crystal"));
self::register("ender_pearl", new EnderPearl(new IID(Ids::ENDER_PEARL), "Ender Pearl"));
self::register("experience_bottle", new ExperienceBottle(new IID(Ids::EXPERIENCE_BOTTLE), "Bottle o' Enchanting"));
self::register("feather", new Item(new IID(Ids::FEATHER), "Feather"));
Expand Down