Skip to content

Commit 37778d5

Browse files
committed
add classes to display crossbow projectiles
1 parent 01dbe5a commit 37778d5

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ vendor/
33
assets/
44
renders/
55
test.php
6+
test.html

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ Decorated pots can be displayed by adding `rc-pot-1-[material-1]` and `rc-pot-2-
9696
```
9797
Only the first and third material are required because the other sides of the pot are not visible.
9898

99+
#### Crossbow projectiles
100+
Crossbow projectiles can be displayed by adding `rc-projectile-[material]` classes.
101+
```html
102+
<div class="rc-item rc-minecraft_crossbow rc-projectile-minecraft_tipped_arrow" style="width: 64px; height: 64px"></div>
103+
```
104+
99105
#### Dynamic tinting
100106
Icons can consist of two layers, which can be separately tinted using CSS.
101107
This is necessary whenever colors can change dynamically based on item properties (e.g. dyed leather armor or potions).

src/Output/ItemLibraryGenerator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Aternos\Renderchest\Output\CSS\MediaQueryEntry;
77
use Aternos\Renderchest\Output\CSS\StyleSheet;
88
use Aternos\Renderchest\Output\ItemStyle\ArmorItemStyleGenerator;
9+
use Aternos\Renderchest\Output\ItemStyle\ChargedProjectileItemStyleGenerator;
910
use Aternos\Renderchest\Output\ItemStyle\DecoratedPotItemStyleGenerator;
1011
use Aternos\Renderchest\Output\ItemStyle\DefaultItemStyleGenerator;
1112
use Aternos\Renderchest\Output\ItemStyle\EnchantedItemStyleGenerator;
@@ -29,6 +30,7 @@ class ItemLibraryGenerator
2930
DecoratedPotItemStyleGenerator::class,
3031
ArmorItemStyleGenerator::class,
3132
PotionItemStyleGenerator::class,
33+
ChargedProjectileItemStyleGenerator::class,
3234
EnchantedItemStyleGenerator::class,
3335
DefaultItemStyleGenerator::class
3436
];
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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

Comments
 (0)