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

Implement Saddle & Horse Armor #6307

Open
wants to merge 13 commits into
base: minor-next
Choose a base branch
from
13 changes: 10 additions & 3 deletions src/block/WaterCauldron.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -128,21 +129,27 @@ 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
pandaa-be marked this conversation as resolved.
Show resolved Hide resolved
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);
$world->setBlock($this->position, $this->withFillLevel($this->getFillLevel() - self::DYE_ARMOR_USE_AMOUNT));
$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());
}
Expand Down
5 changes: 5 additions & 0 deletions src/data/bedrock/item/ItemSerializerDeserializerRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
77 changes: 77 additions & 0 deletions src/item/HorseArmor.php
pandaa-be marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?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\color\Color;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\utils\Binary;

class HorseArmor extends Item{

public const TAG_CUSTOM_COLOR = "customColor"; //TAG_Int

protected ?Color $customColor = null;

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

/**
* Returns the dyed colour of this armour piece. This generally only applies to leather armour.
*/
public function getCustomColor() : ?Color{
return $this->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);
}
}
}
7 changes: 6 additions & 1 deletion src/item/ItemTypeIds.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 5 additions & 0 deletions src/item/StringToItemParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
14 changes: 14 additions & 0 deletions src/item/VanillaItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -356,6 +361,7 @@ public static function getAll() : array{

protected static function setup() : void{
self::registerArmorItems();
self::registerHorseArmorItems();
self::registerSpawnEggs();
self::registerTierToolItems();
self::registerSmithingTemplates();
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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"));
Expand Down