From 37778d57ca67cbdf39c6913c02ba2171f7fffdf1 Mon Sep 17 00:00:00 2001 From: Kurt Thiemann Date: Tue, 12 Mar 2024 12:39:35 +0100 Subject: [PATCH] add classes to display crossbow projectiles --- .gitignore | 1 + README.md | 6 ++ src/Output/ItemLibraryGenerator.php | 2 + .../ChargedProjectileItemStyleGenerator.php | 83 +++++++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 src/Output/ItemStyle/ChargedProjectileItemStyleGenerator.php diff --git a/.gitignore b/.gitignore index f39f265..99054d1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ vendor/ assets/ renders/ test.php +test.html diff --git a/README.md b/README.md index fbd9dfc..80bfb68 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,12 @@ Decorated pots can be displayed by adding `rc-pot-1-[material-1]` and `rc-pot-2- ``` Only the first and third material are required because the other sides of the pot are not visible. +#### Crossbow projectiles +Crossbow projectiles can be displayed by adding `rc-projectile-[material]` classes. +```html +
+``` + #### Dynamic tinting Icons can consist of two layers, which can be separately tinted using CSS. This is necessary whenever colors can change dynamically based on item properties (e.g. dyed leather armor or potions). diff --git a/src/Output/ItemLibraryGenerator.php b/src/Output/ItemLibraryGenerator.php index dd7b547..0c3e970 100644 --- a/src/Output/ItemLibraryGenerator.php +++ b/src/Output/ItemLibraryGenerator.php @@ -6,6 +6,7 @@ use Aternos\Renderchest\Output\CSS\MediaQueryEntry; use Aternos\Renderchest\Output\CSS\StyleSheet; use Aternos\Renderchest\Output\ItemStyle\ArmorItemStyleGenerator; +use Aternos\Renderchest\Output\ItemStyle\ChargedProjectileItemStyleGenerator; use Aternos\Renderchest\Output\ItemStyle\DecoratedPotItemStyleGenerator; use Aternos\Renderchest\Output\ItemStyle\DefaultItemStyleGenerator; use Aternos\Renderchest\Output\ItemStyle\EnchantedItemStyleGenerator; @@ -29,6 +30,7 @@ class ItemLibraryGenerator DecoratedPotItemStyleGenerator::class, ArmorItemStyleGenerator::class, PotionItemStyleGenerator::class, + ChargedProjectileItemStyleGenerator::class, EnchantedItemStyleGenerator::class, DefaultItemStyleGenerator::class ]; diff --git a/src/Output/ItemStyle/ChargedProjectileItemStyleGenerator.php b/src/Output/ItemStyle/ChargedProjectileItemStyleGenerator.php new file mode 100644 index 0000000..7388f9b --- /dev/null +++ b/src/Output/ItemStyle/ChargedProjectileItemStyleGenerator.php @@ -0,0 +1,83 @@ + "arrow", + "spectral_arrow" => "arrow", + "tipped_arrow" => "arrow", + "firework_rocket" => "firework" + ]; + + /** + * @inheritDoc + */ + public static function hasItemStyle(Item $item): bool + { + return $item->getLocator() === "minecraft:crossbow"; + } + + /** + * @inheritDoc + */ + public static function getGlobalStyles(ItemLibraryGenerator $generator): array + { + return []; + } + + /** + * @param bool $fallback + * @return CSSEntry[] + */ + protected function generateStyles(bool $fallback = false): array + { + $prefix = $this->item->getGenerator()->getPrefix(); + $styles = [ + (new PropertyListEntry($this->getCssSelector())) + ->setProperties([ + "background-image" => $this->item->getGenerator()->getItemCSSUrl($this->item->getLocator(), $fallback), + "-webkit-mask-image" => "none" + ]), + (new PropertyListEntry($this->getCssSelector() . "." . $prefix . "enchanted")) + ->setProperties([ + "-webkit-mask-image" => $this->item->getGenerator()->getItemCSSUrl($this->item->getLocator()), + ]) + ]; + + foreach (static::PROJECTILES as $projectile => $texture) { + $styles[] = (new PropertyListEntry($this->getCssSelector() . "." . $prefix . "projectile-minecraft_" . $projectile)) + ->setProperties([ + "background-image" => $this->item->getGenerator()->getItemCSSUrl($this->item->getLocator() . "_" . $texture, $fallback), + "-webkit-mask-image" => "none" + ]); + $styles[] = (new PropertyListEntry($this->getCssSelector() . "." . $prefix . "enchanted" . "." . $prefix . "projectile-minecraft_" . $projectile)) + ->setProperties([ + "-webkit-mask-image" => $this->item->getGenerator()->getItemCSSUrl($this->item->getLocator() . "_" . $texture, $fallback) + ]); + } + return $styles; + } + + /** + * @inheritDoc + */ + public function getItemStyles(): array + { + return $this->generateStyles(); + } + + /** + * @inheritDoc + */ + public function getItemFallbackStyles(): array + { + return $this->generateStyles(true); + } +}