|
|
|
|
@@ -5,25 +5,37 @@ import './ItemIcon.css';
|
|
|
|
|
// All textures are proxied & cached through our server
|
|
|
|
|
const TEXTURE_PROXY_BASE = '/api/texture';
|
|
|
|
|
|
|
|
|
|
// Some items have texture names that differ from their registry name
|
|
|
|
|
// Items whose texture file name differs from their registry name
|
|
|
|
|
const TEXTURE_ALIASES = {
|
|
|
|
|
// Crops / seeds
|
|
|
|
|
wheat_seeds: 'wheat_seeds',
|
|
|
|
|
melon_seeds: 'melon_seeds',
|
|
|
|
|
pumpkin_seeds: 'pumpkin_seeds',
|
|
|
|
|
beetroot_seeds: 'beetroot_seeds',
|
|
|
|
|
// Potions and such
|
|
|
|
|
experience_bottle: 'experience_bottle',
|
|
|
|
|
// Renamed textures
|
|
|
|
|
golden_apple: 'golden_apple',
|
|
|
|
|
enchanted_golden_apple: 'enchanted_golden_apple',
|
|
|
|
|
// Redstone components
|
|
|
|
|
redstone: 'redstone_dust',
|
|
|
|
|
repeater: 'repeater',
|
|
|
|
|
comparator: 'comparator',
|
|
|
|
|
// Misc items with different texture names
|
|
|
|
|
map: 'map',
|
|
|
|
|
filled_map: 'filled_map',
|
|
|
|
|
// Renamed items in 1.20+
|
|
|
|
|
grass: 'short_grass',
|
|
|
|
|
scute: 'turtle_scute',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// CC:Tweaked texture paths (registry name → actual file in the CC repo)
|
|
|
|
|
const CC_TEXTURE_MAP = {
|
|
|
|
|
turtle_normal: 'block/turtle_normal_front',
|
|
|
|
|
turtle_advanced: 'block/turtle_advanced_front',
|
|
|
|
|
computer_normal: 'block/computer_normal_front',
|
|
|
|
|
computer_advanced: 'block/computer_advanced_front',
|
|
|
|
|
computer_command: 'block/computer_command_front',
|
|
|
|
|
monitor_normal: 'block/monitor_normal_0',
|
|
|
|
|
monitor_advanced: 'block/monitor_advanced_0',
|
|
|
|
|
wired_modem: 'block/wired_modem_face',
|
|
|
|
|
wired_modem_full: 'block/wired_modem_face',
|
|
|
|
|
wireless_modem_normal: 'block/wireless_modem_normal_face',
|
|
|
|
|
wireless_modem_advanced: 'block/wireless_modem_advanced_face',
|
|
|
|
|
speaker: 'block/speaker_front',
|
|
|
|
|
disk_drive: 'block/disk_drive_front',
|
|
|
|
|
printer: 'block/printer_front_empty',
|
|
|
|
|
cable: 'block/cable_core',
|
|
|
|
|
// CC item textures
|
|
|
|
|
pocket_computer_normal: 'item/pocket_computer_normal',
|
|
|
|
|
pocket_computer_advanced: 'item/pocket_computer_advanced',
|
|
|
|
|
disk: 'item/disk_frame',
|
|
|
|
|
printed_book: 'item/printed_book',
|
|
|
|
|
printed_page: 'item/printed_page',
|
|
|
|
|
printed_pages: 'item/printed_pages',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Items whose texture lives in the block/ folder instead of item/
|
|
|
|
|
@@ -39,10 +51,7 @@ const BLOCK_TEXTURES = new Set([
|
|
|
|
|
'cobblestone', 'mossy_cobblestone', 'obsidian', 'crying_obsidian',
|
|
|
|
|
'netherrack', 'soul_sand', 'soul_soil', 'basalt', 'polished_basalt', 'smooth_basalt',
|
|
|
|
|
'glowstone', 'glass', 'tinted_glass',
|
|
|
|
|
'oak_slab', 'spruce_slab', 'birch_slab', 'jungle_slab', 'acacia_slab', 'dark_oak_slab',
|
|
|
|
|
'stone_slab', 'cobblestone_slab', 'brick_slab', 'stone_brick_slab',
|
|
|
|
|
'oak_stairs', 'spruce_stairs', 'birch_stairs', 'jungle_stairs', 'acacia_stairs',
|
|
|
|
|
'stone_stairs', 'cobblestone_stairs', 'brick_stairs', 'stone_brick_stairs',
|
|
|
|
|
|
|
|
|
|
'bricks', 'stone_bricks', 'mossy_stone_bricks', 'cracked_stone_bricks',
|
|
|
|
|
'chiseled_stone_bricks', 'deepslate_bricks', 'nether_bricks', 'red_nether_bricks',
|
|
|
|
|
'bookshelf', 'clay', 'pumpkin', 'carved_pumpkin', 'jack_o_lantern', 'melon',
|
|
|
|
|
@@ -72,14 +81,24 @@ const BLOCK_TEXTURES = new Set([
|
|
|
|
|
'light_gray_terracotta', 'cyan_terracotta', 'purple_terracotta', 'blue_terracotta',
|
|
|
|
|
'brown_terracotta', 'green_terracotta', 'red_terracotta', 'black_terracotta',
|
|
|
|
|
'white_glazed_terracotta', 'orange_glazed_terracotta', 'magenta_glazed_terracotta',
|
|
|
|
|
'light_blue_glazed_terracotta', 'yellow_glazed_terracotta', 'lime_glazed_terracotta',
|
|
|
|
|
'pink_glazed_terracotta', 'gray_glazed_terracotta', 'light_gray_glazed_terracotta',
|
|
|
|
|
'cyan_glazed_terracotta', 'purple_glazed_terracotta', 'blue_glazed_terracotta',
|
|
|
|
|
'brown_glazed_terracotta', 'green_glazed_terracotta', 'red_glazed_terracotta',
|
|
|
|
|
'black_glazed_terracotta',
|
|
|
|
|
'white_stained_glass', 'orange_stained_glass', 'magenta_stained_glass',
|
|
|
|
|
'light_blue_stained_glass', 'yellow_stained_glass', 'lime_stained_glass',
|
|
|
|
|
'pink_stained_glass', 'gray_stained_glass', 'light_gray_stained_glass',
|
|
|
|
|
'cyan_stained_glass', 'purple_stained_glass', 'blue_stained_glass',
|
|
|
|
|
'brown_stained_glass', 'green_stained_glass', 'red_stained_glass',
|
|
|
|
|
'black_stained_glass',
|
|
|
|
|
'crafting_table', 'furnace', 'blast_furnace', 'smoker', 'smithing_table',
|
|
|
|
|
'fletching_table', 'cartography_table', 'loom', 'stonecutter', 'grindstone',
|
|
|
|
|
'anvil', 'chipped_anvil', 'damaged_anvil', 'enchanting_table',
|
|
|
|
|
'brewing_stand', 'cauldron', 'composter', 'barrel', 'chest', 'trapped_chest',
|
|
|
|
|
'ender_chest', 'shulker_box', 'dispenser', 'dropper', 'hopper', 'observer',
|
|
|
|
|
'brewing_stand', 'cauldron', 'composter', 'barrel',
|
|
|
|
|
'shulker_box', 'dispenser', 'dropper', 'hopper', 'observer',
|
|
|
|
|
'piston', 'sticky_piston', 'redstone_lamp', 'target', 'lever',
|
|
|
|
|
'beacon', 'conduit', 'bell', 'lodestone', 'respawn_anchor',
|
|
|
|
|
'beacon', 'conduit', 'lodestone', 'respawn_anchor',
|
|
|
|
|
'cactus', 'sugar_cane', 'bamboo',
|
|
|
|
|
'mushroom_stem', 'brown_mushroom_block', 'red_mushroom_block',
|
|
|
|
|
'oak_leaves', 'spruce_leaves', 'birch_leaves', 'jungle_leaves',
|
|
|
|
|
@@ -131,8 +150,8 @@ const BLOCK_TEXTURE_SUFFIXES = {
|
|
|
|
|
dispenser: '_front',
|
|
|
|
|
dropper: '_front',
|
|
|
|
|
observer: '_front',
|
|
|
|
|
piston: '_front',
|
|
|
|
|
sticky_piston: '_front',
|
|
|
|
|
piston: '_top',
|
|
|
|
|
sticky_piston: '_top',
|
|
|
|
|
barrel: '_top',
|
|
|
|
|
crafting_table: '_top',
|
|
|
|
|
cartography_table: '_top',
|
|
|
|
|
@@ -154,42 +173,99 @@ const BLOCK_TEXTURE_SUFFIXES = {
|
|
|
|
|
polished_basalt: '_side',
|
|
|
|
|
quartz_pillar: '_side',
|
|
|
|
|
purpur_pillar: '_side',
|
|
|
|
|
tnt: '_side',
|
|
|
|
|
composter: '_side',
|
|
|
|
|
enchanting_table: '_top',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Resolve derivative blocks (stairs, slabs, fences, walls, buttons) to parent block texture
|
|
|
|
|
const WOOD_TYPES = new Set([
|
|
|
|
|
'oak', 'spruce', 'birch', 'jungle', 'acacia', 'dark_oak',
|
|
|
|
|
'mangrove', 'cherry', 'bamboo', 'crimson', 'warped',
|
|
|
|
|
]);
|
|
|
|
|
const STONE_ALIASES = {
|
|
|
|
|
brick: 'bricks', stone_brick: 'stone_bricks', mossy_stone_brick: 'mossy_stone_bricks',
|
|
|
|
|
nether_brick: 'nether_bricks', red_nether_brick: 'red_nether_bricks',
|
|
|
|
|
end_stone_brick: 'end_stone_bricks', deepslate_brick: 'deepslate_bricks',
|
|
|
|
|
deepslate_tile: 'deepslate_tiles', polished_blackstone_brick: 'polished_blackstone_bricks',
|
|
|
|
|
mud_brick: 'mud_bricks', quartz: 'quartz_block', purpur: 'purpur_block',
|
|
|
|
|
smooth_stone: 'smooth_stone',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function resolveDerivativeTexture(name) {
|
|
|
|
|
const suffixes = ['_stairs', '_slab', '_fence_gate', '_fence', '_wall', '_button', '_pressure_plate'];
|
|
|
|
|
for (const suffix of suffixes) {
|
|
|
|
|
if (!name.endsWith(suffix)) continue;
|
|
|
|
|
const base = name.slice(0, -suffix.length);
|
|
|
|
|
if (BLOCK_TEXTURES.has(base)) return base;
|
|
|
|
|
if (WOOD_TYPES.has(base)) return `${base}_planks`;
|
|
|
|
|
if (STONE_ALIASES[base]) return STONE_ALIASES[base];
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Attempt multiple texture URLs in order.
|
|
|
|
|
* For vanilla: item/{name}.png → block/{name}.png
|
|
|
|
|
* For mods: mod repo item/ → mod repo block/ → vanilla fallback
|
|
|
|
|
* Generate texture URLs to try in order.
|
|
|
|
|
* - CC:Tweaked → curated texture map (1 request)
|
|
|
|
|
* - Create → item/ then block/ (2 requests max)
|
|
|
|
|
* - Unknown mods → empty (instant emoji, no wasted requests)
|
|
|
|
|
* - Vanilla derivatives → parent block texture (1 request)
|
|
|
|
|
* - Vanilla → block/ or item/ with fallback
|
|
|
|
|
*/
|
|
|
|
|
function getTextureUrls(fullItemName) {
|
|
|
|
|
// Parse namespace and short name
|
|
|
|
|
const colonIdx = (fullItemName || '').indexOf(':');
|
|
|
|
|
const namespace = colonIdx >= 0 ? fullItemName.substring(0, colonIdx) : 'minecraft';
|
|
|
|
|
const shortName = colonIdx >= 0 ? fullItemName.substring(colonIdx + 1) : fullItemName;
|
|
|
|
|
const alias = TEXTURE_ALIASES[shortName] || shortName;
|
|
|
|
|
const urls = [];
|
|
|
|
|
|
|
|
|
|
// For non-minecraft mods, try mod-specific URLs first
|
|
|
|
|
if (namespace !== 'minecraft') {
|
|
|
|
|
const knownMods = ['computercraft', 'create'];
|
|
|
|
|
if (knownMods.includes(namespace)) {
|
|
|
|
|
urls.push(`${TEXTURE_PROXY_BASE}/${namespace}/item/${shortName}.png`);
|
|
|
|
|
urls.push(`${TEXTURE_PROXY_BASE}/${namespace}/block/${shortName}.png`);
|
|
|
|
|
urls.push(`${TEXTURE_PROXY_BASE}/${namespace}/block/${shortName}_front.png`);
|
|
|
|
|
urls.push(`${TEXTURE_PROXY_BASE}/${namespace}/block/${shortName}_side.png`);
|
|
|
|
|
// CC:Tweaked → use curated texture map
|
|
|
|
|
if (namespace === 'computercraft') {
|
|
|
|
|
const mapped = CC_TEXTURE_MAP[shortName];
|
|
|
|
|
if (mapped) {
|
|
|
|
|
urls.push(`${TEXTURE_PROXY_BASE}/computercraft/${mapped}.png`);
|
|
|
|
|
} else {
|
|
|
|
|
urls.push(`${TEXTURE_PROXY_BASE}/computercraft/item/${shortName}.png`);
|
|
|
|
|
urls.push(`${TEXTURE_PROXY_BASE}/computercraft/block/${shortName}.png`);
|
|
|
|
|
}
|
|
|
|
|
return urls;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Vanilla texture URLs (through proxy)
|
|
|
|
|
if (BLOCK_TEXTURES.has(shortName)) {
|
|
|
|
|
const suffix = BLOCK_TEXTURE_SUFFIXES[shortName] || '';
|
|
|
|
|
// Create mod → item/ then block/
|
|
|
|
|
if (namespace === 'create') {
|
|
|
|
|
urls.push(`${TEXTURE_PROXY_BASE}/create/item/${shortName}.png`);
|
|
|
|
|
urls.push(`${TEXTURE_PROXY_BASE}/create/block/${shortName}.png`);
|
|
|
|
|
return urls;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Unknown mod namespace → no textures available, instant emoji fallback
|
|
|
|
|
if (namespace !== 'minecraft') {
|
|
|
|
|
return urls;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// === Vanilla (minecraft) ===
|
|
|
|
|
const alias = TEXTURE_ALIASES[shortName] || shortName;
|
|
|
|
|
|
|
|
|
|
// Derivative blocks (stairs, slabs, fences, walls, buttons) → parent texture
|
|
|
|
|
const parent = resolveDerivativeTexture(alias);
|
|
|
|
|
if (parent) {
|
|
|
|
|
const suffix = BLOCK_TEXTURE_SUFFIXES[parent] || '';
|
|
|
|
|
urls.push(`${TEXTURE_PROXY_BASE}/minecraft/block/${parent}${suffix}.png`);
|
|
|
|
|
return urls;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Known block → try block/ first (with suffix if applicable)
|
|
|
|
|
if (BLOCK_TEXTURES.has(alias)) {
|
|
|
|
|
const suffix = BLOCK_TEXTURE_SUFFIXES[alias] || '';
|
|
|
|
|
urls.push(`${TEXTURE_PROXY_BASE}/minecraft/block/${alias}${suffix}.png`);
|
|
|
|
|
if (suffix) urls.push(`${TEXTURE_PROXY_BASE}/minecraft/block/${alias}.png`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Try item/ texture
|
|
|
|
|
urls.push(`${TEXTURE_PROXY_BASE}/minecraft/item/${alias}.png`);
|
|
|
|
|
|
|
|
|
|
if (!BLOCK_TEXTURES.has(shortName)) {
|
|
|
|
|
// If not a known block, also try block/ as last resort
|
|
|
|
|
if (!BLOCK_TEXTURES.has(alias)) {
|
|
|
|
|
urls.push(`${TEXTURE_PROXY_BASE}/minecraft/block/${alias}.png`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|