From 9b58d355162bc01c9c7b81e4e6bb65b2d64eb415 Mon Sep 17 00:00:00 2001 From: IvanCraft623 <57236932+IvanCraft623@users.noreply.github.com> Date: Thu, 14 Nov 2024 08:57:07 -0500 Subject: [PATCH] Implement Goat horns (#5232) Co-authored-by: ipad54 <63200545+ipad54@users.noreply.github.com> Co-authored-by: Dylan T. --- src/data/bedrock/GoatHornTypeIdMap.php | 48 +++++++++++++ src/data/bedrock/GoatHornTypeIds.php | 35 +++++++++ .../ItemSerializerDeserializerRegistrar.php | 10 +++ src/item/GoatHorn.php | 71 +++++++++++++++++++ src/item/GoatHornType.php | 36 ++++++++++ src/item/ItemTypeIds.php | 3 +- src/item/StringToItemParser.php | 8 +++ src/item/VanillaItems.php | 2 + src/world/sound/GoatHornSound.php | 46 ++++++++++++ 9 files changed, 258 insertions(+), 1 deletion(-) create mode 100644 src/data/bedrock/GoatHornTypeIdMap.php create mode 100644 src/data/bedrock/GoatHornTypeIds.php create mode 100644 src/item/GoatHorn.php create mode 100644 src/item/GoatHornType.php create mode 100644 src/world/sound/GoatHornSound.php diff --git a/src/data/bedrock/GoatHornTypeIdMap.php b/src/data/bedrock/GoatHornTypeIdMap.php new file mode 100644 index 000000000..0510a09ce --- /dev/null +++ b/src/data/bedrock/GoatHornTypeIdMap.php @@ -0,0 +1,48 @@ + */ + 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); + } + } +} diff --git a/src/data/bedrock/GoatHornTypeIds.php b/src/data/bedrock/GoatHornTypeIds.php new file mode 100644 index 000000000..048d246fe --- /dev/null +++ b/src/data/bedrock/GoatHornTypeIds.php @@ -0,0 +1,35 @@ + 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(), diff --git a/src/item/GoatHorn.php b/src/item/GoatHorn.php new file mode 100644 index 000000000..088701e39 --- /dev/null +++ b/src/item/GoatHorn.php @@ -0,0 +1,71 @@ +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 getCooldownTag() : ?string{ + return ItemCooldownTags::GOAT_HORN; + } + + 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; + } +} diff --git a/src/item/GoatHornType.php b/src/item/GoatHornType.php new file mode 100644 index 000000000..6c0c3b2f7 --- /dev/null +++ b/src/item/GoatHornType.php @@ -0,0 +1,36 @@ +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; @@ -1341,6 +1348,7 @@ final class StringToItemParser extends StringToTParser{ $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()); diff --git a/src/item/VanillaItems.php b/src/item/VanillaItems.php index 5115ee48a..c5ab59447 100644 --- a/src/item/VanillaItems.php +++ b/src/item/VanillaItems.php @@ -171,6 +171,7 @@ use function strtolower; * @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() @@ -468,6 +469,7 @@ final class VanillaItems{ 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")); diff --git a/src/world/sound/GoatHornSound.php b/src/world/sound/GoatHornSound.php new file mode 100644 index 000000000..3987db3da --- /dev/null +++ b/src/world/sound/GoatHornSound.php @@ -0,0 +1,46 @@ +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)]; + } +}