Skip to content

Commit

Permalink
add pmmp#4715
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshy3282 committed Oct 1, 2024
1 parent 79e11b4 commit 155cef8
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ A fork of PocketMine-MP implementing items, blocks, stale PRs, and other feature

**Do not ask for support for this version of PocketMine in their main Discord server. Any questions can be directed to Joshy3282 on Discord. Additionally, please do not bug any actual PocketMine developers about this either.**

Additions
> Blocks: azalea, flowering azalea, target, moss block, moss carpet, scaffolding\
> Items: end crystal\
> https://github.com/pmmp/PocketMine-MP/pull/4652
> https://github.com/pmmp/PocketMine-MP/pull/4677
> https://github.com/pmmp/PocketMine-MP/pull/4687
> https://github.com/pmmp/PocketMine-MP/pull/4715

## What is this?
PocketMine-MP is a highly customisable server software for Minecraft: Bedrock Edition, built from scratch in PHP, with over 10 years of history.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ private function register1to1ItemMappings() : void{
$this->map1to1Item(Ids::EMERALD, Items::EMERALD());
$this->map1to1Item(Ids::ENCHANTED_BOOK, Items::ENCHANTED_BOOK());
$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::EYE_ARMOR_TRIM_SMITHING_TEMPLATE, Items::EYE_ARMOR_TRIM_SMITHING_TEMPLATE());
Expand Down
3 changes: 3 additions & 0 deletions src/entity/EntityFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ public function __construct(){
return new Egg(Helper::parseLocation($nbt, $world), null, $nbt);
}, ['Egg', 'minecraft:egg']);

$this->register(EndCrystal::class, function(World $world, CompoundTag $nbt) : EndCrystal {
return new EndCrystal(Helper::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
127 changes: 127 additions & 0 deletions src/entity/object/EndCrystal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php

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\math\Vector3;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\network\mcpe\protocol\types\BlockPosition;
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\network\mcpe\protocol\types\entity\EntityMetadataProperties;
use pocketmine\world\Explosion;

class EndCrystal extends Entity implements Explosive{
private const TAG_SHOWBASE = "ShowBottom"; //TAG_Byte

private const TAG_BLOCKTARGET_X = "BlockTargetX"; //TAG_Int
private const TAG_BLOCKTARGET_Y = "BlockTargetY"; //TAG_Int
private const TAG_BLOCKTARGET_Z = "BlockTargetZ"; //TAG_Int

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

protected bool $showBase = false;
protected ?Vector3 $beamTarget = null;

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 getBeamTarget() : ?Vector3{
return $this->beamTarget;
}

public function setBeamTarget(?Vector3 $beamTarget) : void{
$this->beamTarget = $beamTarget;
$this->networkPropertiesDirty = true;
}

public function attack(EntityDamageEvent $source) : void{
parent::attack($source);
if (
$source->getCause() !== EntityDamageEvent::CAUSE_VOID &&
!$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);

if (
($beamXTag = $nbt->getTag(self::TAG_BLOCKTARGET_X)) instanceof IntTag &&
($beamYTag = $nbt->getTag(self::TAG_BLOCKTARGET_Y)) instanceof IntTag &&
($beamZTag = $nbt->getTag(self::TAG_BLOCKTARGET_Z)) instanceof IntTag
) {
$this->setBeamTarget(new Vector3($beamXTag->getValue(), $beamYTag->getValue(), $beamZTag->getValue()));
}
}

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

$nbt->setByte(self::TAG_SHOWBASE, $this->showBase ? 1 : 0);
if ($this->beamTarget !== null) {
$nbt->setInt(self::TAG_BLOCKTARGET_X, $this->beamTarget->getFloorX());
$nbt->setInt(self::TAG_BLOCKTARGET_Y, $this->beamTarget->getFloorY());
$nbt->setInt(self::TAG_BLOCKTARGET_Z, $this->beamTarget->getFloorZ());
}
return $nbt;
}

public function explode() : void{
$ev = new EntityPreExplodeEvent($this, 6);
$ev->call();
if (!$ev->isCancelled()) {
$explosion = new Explosion($this->getPosition(), $ev->getRadius(), $this);
if ($ev->isBlockBreaking()) {
$explosion->explodeA();
}
$explosion->explodeB();
}
}

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

$properties->setGenericFlag(EntityMetadataFlags::SHOWBASE, $this->showBase);
$properties->setBlockPos(EntityMetadataProperties::BLOCK_TARGET, BlockPosition::fromVector3($this->beamTarget ?? Vector3::zero()));
}
}
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\EndCrystal;
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 EndCrystal) && !$this->onGround;
}

public function canBeCollidedWith() : bool{
Expand Down
38 changes: 38 additions & 0 deletions src/item/EndCrystal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace pocketmine\item;

use pocketmine\block\Block;
use pocketmine\block\BlockTypeIds;
use pocketmine\entity\Location;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
use pocketmine\entity\object\EndCrystal as EntityEndCrystal;

class EndCrystal extends Item{

public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{
if ($blockClicked->getTypeId() === BlockTypeIds::OBSIDIAN || $blockClicked->getTypeId() === BlockTypeIds::BEDROCK) {
$pos = $blockClicked->getPosition();
$world = $pos->getWorld();
$bb = AxisAlignedBB::one()
->offset($pos->getX(), $pos->getY(), $pos->getZ())
->extend(Facing::UP, 1);
if (
count($world->getNearbyEntities($bb)) === 0 &&
$blockClicked->getSide(Facing::UP)->getTypeId() === BlockTypeIds::AIR &&
$blockClicked->getSide(Facing::UP, 2)->getTypeId() === BlockTypeIds::AIR
) {
$crystal = new EntityEndCrystal(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 @@ -324,8 +324,9 @@ private function __construct(){
public const SPIRE_ARMOR_TRIM_SMITHING_TEMPLATE = 20285;
public const PITCHER_POD = 20286;
public const NAME_TAG = 20287;
public const END_CRYSTAL = 20288;

public const FIRST_UNUSED_ITEM_ID = 20288;
public const FIRST_UNUSED_ITEM_ID = 20289;

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 @@ -1312,6 +1312,7 @@ private static function registerItems(self $result) : void{
$result->register("enchanted_book", fn() => Items::ENCHANTED_BOOK());
$result->register("enchanted_golden_apple", fn() => Items::ENCHANTED_GOLDEN_APPLE());
$result->register("enchanting_bottle", fn() => Items::EXPERIENCE_BOTTLE());
$result->register("end_crystal", fn() => Items::END_CRYSTAL());
$result->register("ender_pearl", fn() => Items::ENDER_PEARL());
$result->register("experience_bottle", fn() => Items::EXPERIENCE_BOTTLE());
$result->register("eye_armor_trim_smithing_template", fn() => Items::EYE_ARMOR_TRIM_SMITHING_TEMPLATE());
Expand Down
2 changes: 2 additions & 0 deletions src/item/VanillaItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
* @method static EnchantedBook ENCHANTED_BOOK()
* @method static GoldenAppleEnchanted ENCHANTED_GOLDEN_APPLE()
* @method static EnderPearl ENDER_PEARL()
* @method static EndCrystal END_CRYSTAL()
* @method static ExperienceBottle EXPERIENCE_BOTTLE()
* @method static Item EYE_ARMOR_TRIM_SMITHING_TEMPLATE()
* @method static Item FEATHER()
Expand Down Expand Up @@ -454,6 +455,7 @@ protected static function setup() : void{
self::register("emerald", new Item(new IID(Ids::EMERALD), "Emerald"));
self::register("enchanted_book", new EnchantedBook(new IID(Ids::ENCHANTED_BOOK), "Enchanted Book", [EnchantmentTags::ALL]));
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

0 comments on commit 155cef8

Please sign in to comment.