Skip to content

Commit

Permalink
add classes to display crossbow projectiles
Browse files Browse the repository at this point in the history
  • Loading branch information
KurtThiemann committed Mar 12, 2024
1 parent 01dbe5a commit 37778d5
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ vendor/
assets/
renders/
test.php
test.html
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<div class="rc-item rc-minecraft_crossbow rc-projectile-minecraft_tipped_arrow" style="width: 64px; height: 64px"></div>
```

#### 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).
Expand Down
2 changes: 2 additions & 0 deletions src/Output/ItemLibraryGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,6 +30,7 @@ class ItemLibraryGenerator
DecoratedPotItemStyleGenerator::class,
ArmorItemStyleGenerator::class,
PotionItemStyleGenerator::class,
ChargedProjectileItemStyleGenerator::class,
EnchantedItemStyleGenerator::class,
DefaultItemStyleGenerator::class
];
Expand Down
83 changes: 83 additions & 0 deletions src/Output/ItemStyle/ChargedProjectileItemStyleGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

namespace Aternos\Renderchest\Output\ItemStyle;

use Aternos\Renderchest\Output\CSS\CSSEntry;
use Aternos\Renderchest\Output\CSS\PropertyListEntry;
use Aternos\Renderchest\Output\Item;
use Aternos\Renderchest\Output\ItemLibraryGenerator;

class ChargedProjectileItemStyleGenerator extends ItemStyleGenerator
{
const PROJECTILES = [
"arrow" => "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);
}
}

0 comments on commit 37778d5

Please sign in to comment.