Skip to content

Commit

Permalink
add tinting for filled maps
Browse files Browse the repository at this point in the history
  • Loading branch information
KurtThiemann committed Mar 12, 2024
1 parent 37778d5 commit e7e28cd
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
6 changes: 6 additions & 0 deletions builtin/minecraft/models/item/rc_filled_map_base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "item/filled_map"
}
}
6 changes: 6 additions & 0 deletions builtin/minecraft/models/item/rc_filled_map_overlay.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "item/filled_map_markings"
}
}
2 changes: 2 additions & 0 deletions src/Output/ItemLibraryGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Aternos\Renderchest\Output\ItemStyle\EnchantedItemStyleGenerator;
use Aternos\Renderchest\Output\ItemStyle\InternalItemStyleGenerator;
use Aternos\Renderchest\Output\ItemStyle\ItemStyleGenerator;
use Aternos\Renderchest\Output\ItemStyle\MapItemStyleGenerator;
use Aternos\Renderchest\Output\ItemStyle\PotionItemStyleGenerator;
use Aternos\Renderchest\Resource\FolderResourceManager;
use Aternos\Renderchest\Resource\ResourceLocator;
Expand All @@ -31,6 +32,7 @@ class ItemLibraryGenerator
ArmorItemStyleGenerator::class,
PotionItemStyleGenerator::class,
ChargedProjectileItemStyleGenerator::class,
MapItemStyleGenerator::class,
EnchantedItemStyleGenerator::class,
DefaultItemStyleGenerator::class
];
Expand Down
70 changes: 70 additions & 0 deletions src/Output/ItemStyle/MapItemStyleGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?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 MapItemStyleGenerator extends ItemStyleGenerator
{
const DEFAULT_MAP_COLOR = "#46402e";
const BASE = "minecraft:rc_filled_map_base";
const OVERLAY = "minecraft:rc_filled_map_overlay";
const MASK = "minecraft:filled_map";

/**
* @inheritDoc
*/
public static function hasItemStyle(Item $item): bool
{
return $item->getLocator() === "minecraft:filled_map";
}

/**
* @inheritDoc
*/
public static function getGlobalStyles(ItemLibraryGenerator $generator): array
{
return [];
}

/**
* @param bool $fallback
* @return CSSEntry[]
*/
protected function getStyles(bool $fallback): array
{
$prefix = $this->item->getGenerator()->getPrefix();
return [
(new PropertyListEntry($this->getCssSelector()))
->setProperties([
"background-image" => $this->item->getGenerator()->getItemCSSUrl(static::BASE, $fallback),
"-webkit-mask-image" => $this->item->getGenerator()->getItemCSSUrl(static::MASK, $fallback),
"--" . $prefix . "layer-2-tint" => static::DEFAULT_MAP_COLOR
]),
(new PropertyListEntry($this->getCssSelector() . ":before"))
->setProperties([
"background-image" => $this->item->getGenerator()->getItemCSSUrl(static::OVERLAY, $fallback),
"-webkit-mask-image" => $this->item->getGenerator()->getItemCSSUrl(static::OVERLAY, $fallback),
])
];
}

/**
* @inheritDoc
*/
public function getItemStyles(): array
{
return $this->getStyles(false);
}

/**
* @inheritDoc
*/
public function getItemFallbackStyles(): array
{
return $this->getStyles(true);
}
}

0 comments on commit e7e28cd

Please sign in to comment.