Illager banners finally working

closes #2951
This commit is contained in:
Dylan K. Taylor
2025-08-24 15:31:10 +01:00
parent 7c521b456e
commit 8f9478e82f
13 changed files with 260 additions and 12 deletions

View File

@@ -55,6 +55,7 @@ use pocketmine\block\Farmland;
use pocketmine\block\FillableCauldron;
use pocketmine\block\Fire;
use pocketmine\block\FloorCoralFan;
use pocketmine\block\OminousFloorBanner;
use pocketmine\block\Froglight;
use pocketmine\block\FrostedIce;
use pocketmine\block\GlazedTerracotta;
@@ -103,6 +104,7 @@ use pocketmine\block\utils\MushroomBlockType;
use pocketmine\block\utils\PoweredByRedstone;
use pocketmine\block\VanillaBlocks as Blocks;
use pocketmine\block\Vine;
use pocketmine\block\OminousWallBanner;
use pocketmine\data\bedrock\block\BlockLegacyMetadata;
use pocketmine\data\bedrock\block\BlockStateDeserializeException;
use pocketmine\data\bedrock\block\BlockStateNames as StateNames;
@@ -154,7 +156,7 @@ final class VanillaBlockMappings{
self::registerChemistryMappings($reg, $commonProperties);
self::register1to1CustomMappings($reg, $commonProperties);
self::registerSplitMappings($reg);
self::registerSplitMappings($reg, $commonProperties);
}
private static function registerSimpleIdOnlyMappings(BlockSerializerDeserializerRegistrar $reg) : void{
@@ -1476,7 +1478,7 @@ final class VanillaBlockMappings{
* These currently can't be registered in a unified way, and due to their small number it may not be worth the
* effort to implement a unified way to deal with them
*/
private static function registerSplitMappings(BlockSerializerDeserializerRegistrar $reg) : void{
private static function registerSplitMappings(BlockSerializerDeserializerRegistrar $reg, CommonProperties $commonProperties) : void{
//big dripleaf - split into head / stem variants, as stems don't have tilt or leaf state
$reg->serializer->map(Blocks::BIG_DRIPLEAF_HEAD(), function(BigDripleafHead $block) : Writer{
return Writer::create(Ids::BIG_DRIPLEAF)
@@ -1557,5 +1559,18 @@ final class VanillaBlockMappings{
->setAge(min($growth - PitcherCrop::MAX_AGE - 1, DoublePitcherCrop::MAX_AGE))
->setTop($top);
});
//these only exist within PM (mapped from tile properties) as they don't support the same properties as a
//normal banner
$reg->serializer->map(Blocks::OMINOUS_BANNER(), function(OminousFloorBanner $block) use ($commonProperties) : Writer{
$writer = Writer::create(Ids::STANDING_BANNER);
$commonProperties->floorSignLikeRotation->serialize($block, $writer);
return $writer;
});
$reg->serializer->map(Blocks::OMINOUS_WALL_BANNER(), function(OminousWallBanner $block) use ($commonProperties) : Writer{
$writer = Writer::create(Ids::WALL_BANNER);
$commonProperties->horizontalFacingClassic->serialize($block, $writer);
return $writer;
});
}
}

View File

@@ -26,6 +26,7 @@ namespace pocketmine\data\bedrock\item;
use pocketmine\block\Bed;
use pocketmine\block\Block;
use pocketmine\block\CopperDoor;
use pocketmine\block\tile\Banner as TileBanner;
use pocketmine\block\utils\CopperOxidation;
use pocketmine\block\utils\DyeColor;
use pocketmine\block\VanillaBlocks as Blocks;
@@ -46,6 +47,7 @@ use pocketmine\item\Potion;
use pocketmine\item\SplashPotion;
use pocketmine\item\SuspiciousStew;
use pocketmine\item\VanillaItems as Items;
use pocketmine\nbt\tag\CompoundTag;
final class ItemSerializerDeserializerRegistrar{
@@ -487,14 +489,6 @@ final class ItemSerializerDeserializerRegistrar{
* in a unified manner.
*/
private function register1to1ItemWithMetaMappings() : void{
$this->map1to1ItemWithMeta(
Ids::BANNER,
Items::BANNER(),
function(Banner $item, int $meta) : void{
$item->setColor(DyeColorIdMap::getInstance()->fromInvertedId($meta) ?? throw new ItemTypeDeserializeException("Unknown banner meta $meta"));
},
fn(Banner $item) => DyeColorIdMap::getInstance()->toInvertedId($item->getColor())
);
$this->map1to1ItemWithMeta(
Ids::GOAT_HORN,
Items::GOAT_HORN(),
@@ -550,6 +544,21 @@ final class ItemSerializerDeserializerRegistrar{
$this->deserializer?->map($id, fn() => Items::DYE()->setColor($color));
}
$this->serializer?->map(Items::DYE(), fn(Dye $item) => new Data(DyeColorIdMap::getInstance()->toItemId($item->getColor())));
$this->deserializer?->map(Ids::BANNER, function(Data $data) : Item{
$type = $data->getTag()?->getInt(TileBanner::TAG_TYPE) ?? TileBanner::TYPE_NORMAL;
if($type === TileBanner::TYPE_OMINOUS){
return Items::OMINOUS_BANNER();
}
$color = DyeColorIdMap::getInstance()->fromInvertedId($data->getMeta()) ?? throw new ItemTypeDeserializeException("Unknown banner meta " . $data->getMeta());
return Items::BANNER()->setColor($color);
});
$this->serializer?->map(Items::OMINOUS_BANNER(), fn() => new Data(Ids::BANNER, tag: CompoundTag::create()
->setInt(TileBanner::TAG_TYPE, TileBanner::TYPE_OMINOUS))
);
$this->serializer?->map(Items::BANNER(), function(Banner $item) : Data{
return new Data(Ids::BANNER, DyeColorIdMap::getInstance()->toInvertedId($item->getColor()));
});
}
/**