|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Aternos\Renderchest\Output\ItemStyle; |
| 4 | + |
| 5 | +use Aternos\Renderchest\Output\CSS\CSSEntry; |
| 6 | +use Aternos\Renderchest\Output\CSS\PropertyListEntry; |
| 7 | +use Aternos\Renderchest\Output\Item; |
| 8 | +use Aternos\Renderchest\Output\ItemLibraryGenerator; |
| 9 | + |
| 10 | +class ChargedProjectileItemStyleGenerator extends ItemStyleGenerator |
| 11 | +{ |
| 12 | + const PROJECTILES = [ |
| 13 | + "arrow" => "arrow", |
| 14 | + "spectral_arrow" => "arrow", |
| 15 | + "tipped_arrow" => "arrow", |
| 16 | + "firework_rocket" => "firework" |
| 17 | + ]; |
| 18 | + |
| 19 | + /** |
| 20 | + * @inheritDoc |
| 21 | + */ |
| 22 | + public static function hasItemStyle(Item $item): bool |
| 23 | + { |
| 24 | + return $item->getLocator() === "minecraft:crossbow"; |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * @inheritDoc |
| 29 | + */ |
| 30 | + public static function getGlobalStyles(ItemLibraryGenerator $generator): array |
| 31 | + { |
| 32 | + return []; |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * @param bool $fallback |
| 37 | + * @return CSSEntry[] |
| 38 | + */ |
| 39 | + protected function generateStyles(bool $fallback = false): array |
| 40 | + { |
| 41 | + $prefix = $this->item->getGenerator()->getPrefix(); |
| 42 | + $styles = [ |
| 43 | + (new PropertyListEntry($this->getCssSelector())) |
| 44 | + ->setProperties([ |
| 45 | + "background-image" => $this->item->getGenerator()->getItemCSSUrl($this->item->getLocator(), $fallback), |
| 46 | + "-webkit-mask-image" => "none" |
| 47 | + ]), |
| 48 | + (new PropertyListEntry($this->getCssSelector() . "." . $prefix . "enchanted")) |
| 49 | + ->setProperties([ |
| 50 | + "-webkit-mask-image" => $this->item->getGenerator()->getItemCSSUrl($this->item->getLocator()), |
| 51 | + ]) |
| 52 | + ]; |
| 53 | + |
| 54 | + foreach (static::PROJECTILES as $projectile => $texture) { |
| 55 | + $styles[] = (new PropertyListEntry($this->getCssSelector() . "." . $prefix . "projectile-minecraft_" . $projectile)) |
| 56 | + ->setProperties([ |
| 57 | + "background-image" => $this->item->getGenerator()->getItemCSSUrl($this->item->getLocator() . "_" . $texture, $fallback), |
| 58 | + "-webkit-mask-image" => "none" |
| 59 | + ]); |
| 60 | + $styles[] = (new PropertyListEntry($this->getCssSelector() . "." . $prefix . "enchanted" . "." . $prefix . "projectile-minecraft_" . $projectile)) |
| 61 | + ->setProperties([ |
| 62 | + "-webkit-mask-image" => $this->item->getGenerator()->getItemCSSUrl($this->item->getLocator() . "_" . $texture, $fallback) |
| 63 | + ]); |
| 64 | + } |
| 65 | + return $styles; |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * @inheritDoc |
| 70 | + */ |
| 71 | + public function getItemStyles(): array |
| 72 | + { |
| 73 | + return $this->generateStyles(); |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * @inheritDoc |
| 78 | + */ |
| 79 | + public function getItemFallbackStyles(): array |
| 80 | + { |
| 81 | + return $this->generateStyles(true); |
| 82 | + } |
| 83 | +} |
0 commit comments