diff --git a/src/block/WaterCauldron.php b/src/block/WaterCauldron.php index e470aa6cb8..00987eabb2 100644 --- a/src/block/WaterCauldron.php +++ b/src/block/WaterCauldron.php @@ -30,6 +30,7 @@ use pocketmine\item\Armor; use pocketmine\item\Banner; use pocketmine\item\Dye; +use pocketmine\item\HorseArmor; use pocketmine\item\Item; use pocketmine\item\ItemTypeIds; use pocketmine\item\Potion; @@ -128,13 +129,14 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player }else{ $this->mix($item, VanillaItems::GLASS_BOTTLE(), $returnedItems); } - }elseif($item instanceof Armor){ + }elseif($item instanceof Armor || $item instanceof HorseArmor){ if($this->customWaterColor !== null){ if(match($item->getTypeId()){ //TODO: a DyeableArmor class would probably be a better idea, since not all types of armor are dyeable ItemTypeIds::LEATHER_CAP, ItemTypeIds::LEATHER_TUNIC, ItemTypeIds::LEATHER_PANTS, - ItemTypeIds::LEATHER_BOOTS => true, + ItemTypeIds::LEATHER_BOOTS, + ItemTypeIds::LEATHER_HORSE_ARMOR => true, default => false } && $item->getCustomColor()?->toRGBA() !== $this->customWaterColor->toRGBA()){ $item->setCustomColor($this->customWaterColor); @@ -142,7 +144,12 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $world->addSound($this->position->add(0.5, 0.5, 0.5), new CauldronDyeItemSound()); } }elseif($item->getCustomColor() !== null){ - $item->clearCustomColor(); + if($item instanceof HorseArmor){ + $item->setCustomColor(null); + }else{ + $item->clearCustomColor(); + } + $world->setBlock($this->position, $this->withFillLevel($this->getFillLevel() - self::CLEAN_ARMOR_USE_AMOUNT)); $world->addSound($this->position->add(0.5, 0.5, 0.5), new CauldronCleanItemSound()); } diff --git a/src/data/bedrock/item/ItemSerializerDeserializerRegistrar.php b/src/data/bedrock/item/ItemSerializerDeserializerRegistrar.php index 7a720559ea..29a730e146 100644 --- a/src/data/bedrock/item/ItemSerializerDeserializerRegistrar.php +++ b/src/data/bedrock/item/ItemSerializerDeserializerRegistrar.php @@ -214,6 +214,7 @@ private function register1to1ItemMappings() : void{ $this->map1to1Item(Ids::DIAMOND_CHESTPLATE, Items::DIAMOND_CHESTPLATE()); $this->map1to1Item(Ids::DIAMOND_HELMET, Items::DIAMOND_HELMET()); $this->map1to1Item(Ids::DIAMOND_HOE, Items::DIAMOND_HOE()); + $this->map1to1Item(Ids::DIAMOND_HORSE_ARMOR, Items::DIAMOND_HORSE_ARMOR()); $this->map1to1Item(Ids::DIAMOND_LEGGINGS, Items::DIAMOND_LEGGINGS()); $this->map1to1Item(Ids::DIAMOND_PICKAXE, Items::DIAMOND_PICKAXE()); $this->map1to1Item(Ids::DIAMOND_SHOVEL, Items::DIAMOND_SHOVEL()); @@ -251,6 +252,7 @@ private function register1to1ItemMappings() : void{ $this->map1to1Item(Ids::GOLDEN_CHESTPLATE, Items::GOLDEN_CHESTPLATE()); $this->map1to1Item(Ids::GOLDEN_HELMET, Items::GOLDEN_HELMET()); $this->map1to1Item(Ids::GOLDEN_HOE, Items::GOLDEN_HOE()); + $this->map1to1Item(Ids::GOLDEN_HORSE_ARMOR, Items::GOLDEN_HORSE_ARMOR()); $this->map1to1Item(Ids::GOLDEN_LEGGINGS, Items::GOLDEN_LEGGINGS()); $this->map1to1Item(Ids::GOLDEN_PICKAXE, Items::GOLDEN_PICKAXE()); $this->map1to1Item(Ids::GOLDEN_SHOVEL, Items::GOLDEN_SHOVEL()); @@ -266,6 +268,7 @@ private function register1to1ItemMappings() : void{ $this->map1to1Item(Ids::IRON_CHESTPLATE, Items::IRON_CHESTPLATE()); $this->map1to1Item(Ids::IRON_HELMET, Items::IRON_HELMET()); $this->map1to1Item(Ids::IRON_HOE, Items::IRON_HOE()); + $this->map1to1Item(Ids::IRON_HORSE_ARMOR, Items::IRON_HORSE_ARMOR()); $this->map1to1Item(Ids::IRON_INGOT, Items::IRON_INGOT()); $this->map1to1Item(Ids::IRON_LEGGINGS, Items::IRON_LEGGINGS()); $this->map1to1Item(Ids::IRON_NUGGET, Items::IRON_NUGGET()); @@ -280,6 +283,7 @@ private function register1to1ItemMappings() : void{ $this->map1to1Item(Ids::LEATHER_BOOTS, Items::LEATHER_BOOTS()); $this->map1to1Item(Ids::LEATHER_CHESTPLATE, Items::LEATHER_TUNIC()); $this->map1to1Item(Ids::LEATHER_HELMET, Items::LEATHER_CAP()); + $this->map1to1Item(Ids::LEATHER_HORSE_ARMOR, Items::LEATHER_HORSE_ARMOR()); $this->map1to1Item(Ids::LEATHER_LEGGINGS, Items::LEATHER_PANTS()); $this->map1to1Item(Ids::MAGMA_CREAM, Items::MAGMA_CREAM()); $this->map1to1Item(Ids::MANGROVE_BOAT, Items::MANGROVE_BOAT()); @@ -348,6 +352,7 @@ private function register1to1ItemMappings() : void{ $this->map1to1Item(Ids::REDSTONE, Items::REDSTONE_DUST()); $this->map1to1Item(Ids::RIB_ARMOR_TRIM_SMITHING_TEMPLATE, Items::RIB_ARMOR_TRIM_SMITHING_TEMPLATE()); $this->map1to1Item(Ids::ROTTEN_FLESH, Items::ROTTEN_FLESH()); + $this->map1to1Item(Ids::SADDLE, Items::SADDLE()); $this->map1to1Item(Ids::SALMON, Items::RAW_SALMON()); $this->map1to1Item(Ids::TURTLE_SCUTE, Items::SCUTE()); $this->map1to1Item(Ids::SENTRY_ARMOR_TRIM_SMITHING_TEMPLATE, Items::SENTRY_ARMOR_TRIM_SMITHING_TEMPLATE()); diff --git a/src/item/HorseArmor.php b/src/item/HorseArmor.php new file mode 100644 index 0000000000..60c20a1d1e --- /dev/null +++ b/src/item/HorseArmor.php @@ -0,0 +1,77 @@ +customColor; + } + + /** + * Sets the dyed colour of this armour piece. This generally only applies to leather armour. + * + * @return $this + */ + public function setCustomColor(?Color $color) : self{ + if($this->getTypeId() === ItemTypeIds::LEATHER_HORSE_ARMOR){ + $this->customColor = $color; + } + return $this; + } + + protected function deserializeCompoundTag(CompoundTag $tag) : void{ + parent::deserializeCompoundTag($tag); + if(($colorTag = $tag->getTag(self::TAG_CUSTOM_COLOR)) instanceof IntTag){ + $this->customColor = Color::fromARGB(Binary::unsignInt($colorTag->getValue())); + }else{ + $this->customColor = null; + } + } + + protected function serializeCompoundTag(CompoundTag $tag) : void{ + parent::serializeCompoundTag($tag); + if($this->customColor !== null){ + $tag->setInt(self::TAG_CUSTOM_COLOR, Binary::signInt($this->customColor->toARGB())); + }else{ + $tag->removeTag(self::TAG_CUSTOM_COLOR); + } + } +} diff --git a/src/item/ItemTypeIds.php b/src/item/ItemTypeIds.php index 66eebed744..e4d2155cba 100644 --- a/src/item/ItemTypeIds.php +++ b/src/item/ItemTypeIds.php @@ -324,8 +324,13 @@ private function __construct(){ public const SPIRE_ARMOR_TRIM_SMITHING_TEMPLATE = 20285; public const PITCHER_POD = 20286; public const NAME_TAG = 20287; + public const SADDLE = 20288; + public const LEATHER_HORSE_ARMOR = 20289; + public const IRON_HORSE_ARMOR = 20290; + public const DIAMOND_HORSE_ARMOR = 20291; + public const GOLDEN_HORSE_ARMOR = 20292; - public const FIRST_UNUSED_ITEM_ID = 20288; + public const FIRST_UNUSED_ITEM_ID = 20293; private static int $nextDynamicId = self::FIRST_UNUSED_ITEM_ID; diff --git a/src/item/StringToItemParser.php b/src/item/StringToItemParser.php index 91fd2ab4a4..08ececce9e 100644 --- a/src/item/StringToItemParser.php +++ b/src/item/StringToItemParser.php @@ -1286,6 +1286,7 @@ private static function registerItems(self $result) : void{ $result->register("diamond_boots", fn() => Items::DIAMOND_BOOTS()); $result->register("diamond_chestplate", fn() => Items::DIAMOND_CHESTPLATE()); $result->register("diamond_helmet", fn() => Items::DIAMOND_HELMET()); + $result->register("diamond_horse_armor", fn() => Items::DIAMOND_HORSE_ARMOR()); $result->register("diamond_hoe", fn() => Items::DIAMOND_HOE()); $result->register("diamond_leggings", fn() => Items::DIAMOND_LEGGINGS()); $result->register("diamond_pickaxe", fn() => Items::DIAMOND_PICKAXE()); @@ -1325,6 +1326,7 @@ private static function registerItems(self $result) : void{ $result->register("gold_boots", fn() => Items::GOLDEN_BOOTS()); $result->register("gold_chestplate", fn() => Items::GOLDEN_CHESTPLATE()); $result->register("gold_helmet", fn() => Items::GOLDEN_HELMET()); + $result->register("golden_horse_armor", fn() => Items::GOLDEN_HORSE_ARMOR()); $result->register("gold_hoe", fn() => Items::GOLDEN_HOE()); $result->register("gold_ingot", fn() => Items::GOLD_INGOT()); $result->register("gold_leggings", fn() => Items::GOLDEN_LEGGINGS()); @@ -1354,6 +1356,7 @@ private static function registerItems(self $result) : void{ $result->register("iron_boots", fn() => Items::IRON_BOOTS()); $result->register("iron_chestplate", fn() => Items::IRON_CHESTPLATE()); $result->register("iron_helmet", fn() => Items::IRON_HELMET()); + $result->register("iron_horse_armor", fn() => Items::IRON_HORSE_ARMOR()); $result->register("iron_hoe", fn() => Items::IRON_HOE()); $result->register("iron_ingot", fn() => Items::IRON_INGOT()); $result->register("iron_leggings", fn() => Items::IRON_LEGGINGS()); @@ -1369,6 +1372,7 @@ private static function registerItems(self $result) : void{ $result->register("leather_cap", fn() => Items::LEATHER_CAP()); $result->register("leather_chestplate", fn() => Items::LEATHER_TUNIC()); $result->register("leather_helmet", fn() => Items::LEATHER_CAP()); + $result->register("leather_horse_armor", fn() => Items::LEATHER_HORSE_ARMOR()); $result->register("leather_leggings", fn() => Items::LEATHER_PANTS()); $result->register("leather_pants", fn() => Items::LEATHER_PANTS()); $result->register("leather_tunic", fn() => Items::LEATHER_TUNIC()); @@ -1455,6 +1459,7 @@ private static function registerItems(self $result) : void{ $result->register("redstone_dust", fn() => Items::REDSTONE_DUST()); $result->register("rib_armor_trim_smithing_template", fn() => Items::RIB_ARMOR_TRIM_SMITHING_TEMPLATE()); $result->register("rotten_flesh", fn() => Items::ROTTEN_FLESH()); + $result->register("saddle", fn() => Items::SADDLE()); $result->register("salmon", fn() => Items::RAW_SALMON()); $result->register("scute", fn() => Items::SCUTE()); $result->register("sentry_armor_trim_smithing_template", fn() => Items::SENTRY_ARMOR_TRIM_SMITHING_TEMPLATE()); diff --git a/src/item/VanillaItems.php b/src/item/VanillaItems.php index bbd0dfc01b..d98cd344ff 100644 --- a/src/item/VanillaItems.php +++ b/src/item/VanillaItems.php @@ -142,6 +142,7 @@ * @method static Armor DIAMOND_CHESTPLATE() * @method static Armor DIAMOND_HELMET() * @method static Hoe DIAMOND_HOE() + * @method static HorseArmor DIAMOND_HORSE_ARMOR() * @method static Armor DIAMOND_LEGGINGS() * @method static Pickaxe DIAMOND_PICKAXE() * @method static Shovel DIAMOND_SHOVEL() @@ -178,6 +179,7 @@ * @method static Armor GOLDEN_CHESTPLATE() * @method static Armor GOLDEN_HELMET() * @method static Hoe GOLDEN_HOE() + * @method static HorseArmor GOLDEN_HORSE_ARMOR() * @method static Armor GOLDEN_LEGGINGS() * @method static Pickaxe GOLDEN_PICKAXE() * @method static Shovel GOLDEN_SHOVEL() @@ -195,6 +197,7 @@ * @method static Armor IRON_CHESTPLATE() * @method static Armor IRON_HELMET() * @method static Hoe IRON_HOE() + * @method static HorseArmor IRON_HORSE_ARMOR() * @method static Item IRON_INGOT() * @method static Armor IRON_LEGGINGS() * @method static Item IRON_NUGGET() @@ -208,6 +211,7 @@ * @method static Item LEATHER() * @method static Armor LEATHER_BOOTS() * @method static Armor LEATHER_CAP() + * @method static HorseArmor LEATHER_HORSE_ARMOR() * @method static Armor LEATHER_PANTS() * @method static Armor LEATHER_TUNIC() * @method static Item MAGMA_CREAM() @@ -283,6 +287,7 @@ * @method static Redstone REDSTONE_DUST() * @method static Item RIB_ARMOR_TRIM_SMITHING_TEMPLATE() * @method static RottenFlesh ROTTEN_FLESH() + * @method static Item SADDLE() * @method static Item SCUTE() * @method static Item SENTRY_ARMOR_TRIM_SMITHING_TEMPLATE() * @method static Item SHAPER_ARMOR_TRIM_SMITHING_TEMPLATE() @@ -356,6 +361,7 @@ public static function getAll() : array{ protected static function setup() : void{ self::registerArmorItems(); + self::registerHorseArmorItems(); self::registerSpawnEggs(); self::registerTierToolItems(); self::registerSmithingTemplates(); @@ -546,6 +552,7 @@ public function isFireProof() : bool{ return true; } self::register("record_ward", new Record(new IID(Ids::RECORD_WARD), RecordType::DISK_WARD, "Record Ward")); self::register("redstone_dust", new Redstone(new IID(Ids::REDSTONE_DUST), "Redstone")); self::register("rotten_flesh", new RottenFlesh(new IID(Ids::ROTTEN_FLESH), "Rotten Flesh")); + self::register("saddle", new Item(new IID(Ids::SADDLE), "Saddle")); self::register("scute", new Item(new IID(Ids::SCUTE), "Scute")); self::register("shears", new Shears(new IID(Ids::SHEARS), "Shears", [EnchantmentTags::SHEARS])); self::register("shulker_shell", new Item(new IID(Ids::SHULKER_SHELL), "Shulker Shell")); @@ -666,6 +673,13 @@ private static function registerArmorItems() : void{ self::register("netherite_leggings", new Armor(new IID(Ids::NETHERITE_LEGGINGS), "Netherite Leggings", new ArmorTypeInfo(6, 556, ArmorInventory::SLOT_LEGS, 3, true, material: ArmorMaterials::NETHERITE()), [EnchantmentTags::LEGGINGS])); } + private static function registerHorseArmorItems() : void{ + self::register("leather_horse_armor", new HorseArmor(new IID(Ids::LEATHER_HORSE_ARMOR), "Leather Horse Armor")); + self::register("iron_horse_armor", new HorseArmor(new IID(Ids::IRON_HORSE_ARMOR), "Iron Horse Armor")); + self::register("diamond_horse_armor", new HorseArmor(new IID(Ids::DIAMOND_HORSE_ARMOR), "Diamond Horse Armor")); + self::register("golden_horse_armor", new HorseArmor(new IID(Ids::GOLDEN_HORSE_ARMOR), "Golden Horse Armor")); + } + private static function registerSmithingTemplates() : void{ self::register("netherite_upgrade_smithing_template", new Item(new IID(Ids::NETHERITE_UPGRADE_SMITHING_TEMPLATE), "Netherite Upgrade Smithing Template")); self::register("coast_armor_trim_smithing_template", new Item(new IID(Ids::COAST_ARMOR_TRIM_SMITHING_TEMPLATE), "Coast Armor Trim Smithing Template"));