Skip to content

Commit

Permalink
add pmmp#5232
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshy3282 committed Oct 1, 2024
1 parent cf62b4f commit 72c0da9
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Additions
> https://github.com/pmmp/PocketMine-MP/pull/4742
> https://github.com/pmmp/PocketMine-MP/pull/5095
> https://github.com/pmmp/PocketMine-MP/pull/5122
> https://github.com/pmmp/PocketMine-MP/pull/5232

## What is this?
Expand Down
27 changes: 27 additions & 0 deletions src/data/bedrock/GoatHornTypeIdMap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace pocketmine\data\bedrock;

use pocketmine\item\GoatHornType;
use pocketmine\utils\SingletonTrait;

final class GoatHornTypeIdMap{
use SingletonTrait;
/** @phpstan-use IntSaveIdMapTrait<GoatHornType> */
use IntSaveIdMapTrait;

private function __construct(){
foreach(GoatHornType::cases() as $case){
$this->register(match($case){
GoatHornType::PONDER => GoatHornTypeIds::PONDER,
GoatHornType::SING => GoatHornTypeIds::SING,
GoatHornType::SEEK => GoatHornTypeIds::SEEK,
GoatHornType::FEEL => GoatHornTypeIds::FEEL,
GoatHornType::ADMIRE => GoatHornTypeIds::ADMIRE,
GoatHornType::CALL => GoatHornTypeIds::CALL,
GoatHornType::YEARN => GoatHornTypeIds::YEARN,
GoatHornType::DREAM => GoatHornTypeIds::DREAM
}, $case);
}
}
}
14 changes: 14 additions & 0 deletions src/data/bedrock/GoatHornTypeIds.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace pocketmine\data\bedrock;

final class GoatHornTypeIds{
public const PONDER = 0;
public const SING = 1;
public const SEEK = 2;
public const FEEL = 3;
public const ADMIRE = 4;
public const CALL = 5;
public const YEARN = 6;
public const DREAM = 7;
}
10 changes: 10 additions & 0 deletions src/data/bedrock/item/ItemSerializerDeserializerRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use pocketmine\block\VanillaBlocks as Blocks;
use pocketmine\data\bedrock\CompoundTypeIds;
use pocketmine\data\bedrock\DyeColorIdMap;
use pocketmine\data\bedrock\GoatHornTypeIdMap;
use pocketmine\data\bedrock\item\ItemTypeNames as Ids;
use pocketmine\data\bedrock\item\SavedItemData as Data;
use pocketmine\data\bedrock\MedicineTypeIdMap;
Expand All @@ -38,6 +39,7 @@
use pocketmine\data\bedrock\SuspiciousStewTypeIdMap;
use pocketmine\item\Banner;
use pocketmine\item\Dye;
use pocketmine\item\GoatHorn;
use pocketmine\item\Item;
use pocketmine\item\Medicine;
use pocketmine\item\Potion;
Expand Down Expand Up @@ -489,6 +491,14 @@ function(Banner $item, int $meta) : void{
},
fn(Banner $item) => DyeColorIdMap::getInstance()->toInvertedId($item->getColor())
);
$this->map1to1ItemWithMeta(
Ids::GOAT_HORN,
Items::GOAT_HORN(),
function(GoatHorn $item, int $meta): void {
$item->setHornType(GoatHornTypeIdMap::getInstance()->fromId($meta) ?? throw new ItemTypeDeserializeException("Unknown goat horn type ID $meta"));
},
fn(GoatHorn $item) => GoatHornTypeIdMap::getInstance()->toId($item->getHornType())
);
$this->map1to1ItemWithMeta(
Ids::MEDICINE,
Items::MEDICINE(),
Expand Down
47 changes: 47 additions & 0 deletions src/item/GoatHorn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace pocketmine\item;

use pocketmine\data\runtime\RuntimeDataDescriber;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
use pocketmine\world\sound\GoatHornSound;

class GoatHorn extends Item implements Releasable{

private GoatHornType $goatHornType = GoatHornType::PONDER;

protected function describeState(RuntimeDataDescriber $w) : void{
$w->enum($this->goatHornType);
}

public function getHornType() : GoatHornType{
return $this->goatHornType;
}

/** @return $this */
public function setHornType(GoatHornType $type) : self{
$this->goatHornType = $type;
return $this;
}

public function getMaxStackSize() : int{
return 1;
}

public function getCooldownTicks() : int{
return 140;
}

public function canStartUsingItem(Player $player) : bool{
return true;
}

public function onClickAir(Player $player, Vector3 $directionVector, array &$returnedItems) : ItemUseResult{
$position = $player->getPosition();
$position->getWorld()->addSound($position, new GoatHornSound($this->goatHornType));

return ItemUseResult::SUCCESS;
}

}
15 changes: 15 additions & 0 deletions src/item/GoatHornType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace pocketmine\item;

enum GoatHornType{

case PONDER;
case SING;
case SEEK;
case FEEL;
case ADMIRE;
case CALL;
case YEARN;
case DREAM;
}
3 changes: 2 additions & 1 deletion src/item/ItemTypeIds.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,9 @@ private function __construct(){
public const PITCHER_POD = 20286;
public const NAME_TAG = 20287;
public const END_CRYSTAL = 20288;
public const GOAT_HORN = 20289;

public const FIRST_UNUSED_ITEM_ID = 20289;
public const FIRST_UNUSED_ITEM_ID = 20290;

private static int $nextDynamicId = self::FIRST_UNUSED_ITEM_ID;

Expand Down
6 changes: 6 additions & 0 deletions src/item/StringToItemParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,11 @@ private static function registerDynamicItems(self $result) : void{

$result->register($prefix("dye"), fn() => Items::DYE()->setColor($color));
}
foreach(GoatHornType::cases() as $goatHornType) {
$prefix = fn(string $name) => strtolower($goatHornType->name) . "_" . $name;

$result->register($prefix("goat_horn"), fn() => Items::GOAT_HORN()->setHornType($goatHornType));
}
foreach(SuspiciousStewType::cases() as $suspiciousStewType){
$prefix = fn(string $name) => strtolower($suspiciousStewType->name) . "_" . $name;

Expand Down Expand Up @@ -1332,6 +1337,7 @@ private static function registerItems(self $result) : void{
$result->register("glow_berries", fn() => Items::GLOW_BERRIES());
$result->register("glow_ink_sac", fn() => Items::GLOW_INK_SAC());
$result->register("glowstone_dust", fn() => Items::GLOWSTONE_DUST());
$result->register("goat_horn", fn() => Items::GOAT_HORN());
$result->register("gold_axe", fn() => Items::GOLDEN_AXE());
$result->register("gold_boots", fn() => Items::GOLDEN_BOOTS());
$result->register("gold_chestplate", fn() => Items::GOLDEN_CHESTPLATE());
Expand Down
2 changes: 2 additions & 0 deletions src/item/VanillaItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
* @method static Item GLOWSTONE_DUST()
* @method static GlowBerries GLOW_BERRIES()
* @method static Item GLOW_INK_SAC()
* @method static GoatHorn GOAT_HORN()
* @method static GoldenApple GOLDEN_APPLE()
* @method static Axe GOLDEN_AXE()
* @method static Armor GOLDEN_BOOTS()
Expand Down Expand Up @@ -470,6 +471,7 @@ protected static function setup() : void{
self::register("glow_berries", new GlowBerries(new IID(Ids::GLOW_BERRIES), "Glow Berries"));
self::register("glow_ink_sac", new Item(new IID(Ids::GLOW_INK_SAC), "Glow Ink Sac"));
self::register("glowstone_dust", new Item(new IID(Ids::GLOWSTONE_DUST), "Glowstone Dust"));
self::register("goat_horn", new GoatHorn(new IID(Ids::GOAT_HORN), "Goat Horn"));
self::register("gold_ingot", new Item(new IID(Ids::GOLD_INGOT), "Gold Ingot"));
self::register("gold_nugget", new Item(new IID(Ids::GOLD_NUGGET), "Gold Nugget"));
self::register("golden_apple", new GoldenApple(new IID(Ids::GOLDEN_APPLE), "Golden Apple"));
Expand Down
26 changes: 26 additions & 0 deletions src/world/sound/GoatHornSound.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace pocketmine\world\sound;

use pocketmine\item\GoatHornType;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
use pocketmine\network\mcpe\protocol\types\LevelSoundEvent;

class GoatHornSound implements Sound{
public function __construct(private GoatHornType $goatHornType){
}

public function encode(Vector3 $pos) : array{
return [LevelSoundEventPacket::nonActorSound(match ($this->goatHornType) {
GoatHornType::PONDER => LevelSoundEvent::HORN_CALL0,
GoatHornType::SING => LevelSoundEvent::HORN_CALL1,
GoatHornType::SEEK => LevelSoundEvent::HORN_CALL2,
GoatHornType::FEEL => LevelSoundEvent::HORN_CALL3,
GoatHornType::ADMIRE => LevelSoundEvent::HORN_CALL4,
GoatHornType::CALL => LevelSoundEvent::HORN_CALL5,
GoatHornType::YEARN => LevelSoundEvent::HORN_CALL6,
GoatHornType::DREAM => LevelSoundEvent::HORN_CALL7
}, $pos, false)];
}
}

0 comments on commit 72c0da9

Please sign in to comment.