-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add classes to display crossbow projectiles
- Loading branch information
1 parent
01dbe5a
commit 37778d5
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ vendor/ | |
assets/ | ||
renders/ | ||
test.php | ||
test.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/Output/ItemStyle/ChargedProjectileItemStyleGenerator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |