From e7e28cd3f6c236068455f80fc6c199d57f9ea823 Mon Sep 17 00:00:00 2001 From: Kurt Thiemann Date: Tue, 12 Mar 2024 13:04:44 +0100 Subject: [PATCH] add tinting for filled maps --- .../models/item/rc_filled_map_base.json | 6 ++ .../models/item/rc_filled_map_overlay.json | 6 ++ src/Output/ItemLibraryGenerator.php | 2 + .../ItemStyle/MapItemStyleGenerator.php | 70 +++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 builtin/minecraft/models/item/rc_filled_map_base.json create mode 100644 builtin/minecraft/models/item/rc_filled_map_overlay.json create mode 100644 src/Output/ItemStyle/MapItemStyleGenerator.php diff --git a/builtin/minecraft/models/item/rc_filled_map_base.json b/builtin/minecraft/models/item/rc_filled_map_base.json new file mode 100644 index 0000000..7154d8f --- /dev/null +++ b/builtin/minecraft/models/item/rc_filled_map_base.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "item/filled_map" + } +} diff --git a/builtin/minecraft/models/item/rc_filled_map_overlay.json b/builtin/minecraft/models/item/rc_filled_map_overlay.json new file mode 100644 index 0000000..e6fdb5b --- /dev/null +++ b/builtin/minecraft/models/item/rc_filled_map_overlay.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "item/filled_map_markings" + } +} diff --git a/src/Output/ItemLibraryGenerator.php b/src/Output/ItemLibraryGenerator.php index 0c3e970..43c59c6 100644 --- a/src/Output/ItemLibraryGenerator.php +++ b/src/Output/ItemLibraryGenerator.php @@ -12,6 +12,7 @@ use Aternos\Renderchest\Output\ItemStyle\EnchantedItemStyleGenerator; use Aternos\Renderchest\Output\ItemStyle\InternalItemStyleGenerator; use Aternos\Renderchest\Output\ItemStyle\ItemStyleGenerator; +use Aternos\Renderchest\Output\ItemStyle\MapItemStyleGenerator; use Aternos\Renderchest\Output\ItemStyle\PotionItemStyleGenerator; use Aternos\Renderchest\Resource\FolderResourceManager; use Aternos\Renderchest\Resource\ResourceLocator; @@ -31,6 +32,7 @@ class ItemLibraryGenerator ArmorItemStyleGenerator::class, PotionItemStyleGenerator::class, ChargedProjectileItemStyleGenerator::class, + MapItemStyleGenerator::class, EnchantedItemStyleGenerator::class, DefaultItemStyleGenerator::class ]; diff --git a/src/Output/ItemStyle/MapItemStyleGenerator.php b/src/Output/ItemStyle/MapItemStyleGenerator.php new file mode 100644 index 0000000..a11aaf6 --- /dev/null +++ b/src/Output/ItemStyle/MapItemStyleGenerator.php @@ -0,0 +1,70 @@ +getLocator() === "minecraft:filled_map"; + } + + /** + * @inheritDoc + */ + public static function getGlobalStyles(ItemLibraryGenerator $generator): array + { + return []; + } + + /** + * @param bool $fallback + * @return CSSEntry[] + */ + protected function getStyles(bool $fallback): array + { + $prefix = $this->item->getGenerator()->getPrefix(); + return [ + (new PropertyListEntry($this->getCssSelector())) + ->setProperties([ + "background-image" => $this->item->getGenerator()->getItemCSSUrl(static::BASE, $fallback), + "-webkit-mask-image" => $this->item->getGenerator()->getItemCSSUrl(static::MASK, $fallback), + "--" . $prefix . "layer-2-tint" => static::DEFAULT_MAP_COLOR + ]), + (new PropertyListEntry($this->getCssSelector() . ":before")) + ->setProperties([ + "background-image" => $this->item->getGenerator()->getItemCSSUrl(static::OVERLAY, $fallback), + "-webkit-mask-image" => $this->item->getGenerator()->getItemCSSUrl(static::OVERLAY, $fallback), + ]) + ]; + } + + /** + * @inheritDoc + */ + public function getItemStyles(): array + { + return $this->getStyles(false); + } + + /** + * @inheritDoc + */ + public function getItemFallbackStyles(): array + { + return $this->getStyles(true); + } +}