Refactor texture URL handling: replace CDN links with proxy-based URLs for mod and vanilla textures

This commit is contained in:
MayaTheShy
2026-03-21 19:30:13 -04:00
parent ba8acc1c27
commit 898353e8c6

View File

@@ -2,14 +2,8 @@ import React, { useState } from 'react';
import { getItemEmoji } from '../utils/itemUtils';
import './ItemIcon.css';
// Minecraft assets CDN - actual game textures (16x16 pixel art)
const MC_ASSETS_BASE = 'https://cdn.jsdelivr.net/gh/InventivetalentDev/minecraft-assets@1.21.4/assets/minecraft/textures';
// Mod texture CDN bases (GitHub raw URLs for known mod repos)
const MOD_TEXTURE_BASES = {
computercraft: 'https://raw.githubusercontent.com/cc-tweaked/CC-Tweaked/mc-1.20.x/projects/common/src/main/resources/assets/computercraft/textures',
create: 'https://raw.githubusercontent.com/Creators-of-Create/Create/mc1.20.1/dev/src/main/resources/assets/create/textures',
};
// 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
const TEXTURE_ALIASES = {
@@ -23,6 +17,13 @@ const TEXTURE_ALIASES = {
// 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',
};
// Items whose texture lives in the block/ folder instead of item/
@@ -83,6 +84,42 @@ const BLOCK_TEXTURES = new Set([
'mushroom_stem', 'brown_mushroom_block', 'red_mushroom_block',
'oak_leaves', 'spruce_leaves', 'birch_leaves', 'jungle_leaves',
'acacia_leaves', 'dark_oak_leaves', 'mangrove_leaves', 'cherry_leaves', 'azalea_leaves',
// Additional blocks commonly seen as items
'smooth_stone', 'smooth_sandstone', 'smooth_red_sandstone', 'smooth_quartz',
'chiseled_sandstone', 'cut_sandstone', 'chiseled_red_sandstone', 'cut_red_sandstone',
'quartz_pillar', 'chiseled_quartz_block', 'quartz_bricks',
'ladder', 'cobweb', 'torch', 'soul_torch', 'lantern', 'soul_lantern',
'redstone_torch', 'chain',
'rail', 'powered_rail', 'detector_rail', 'activator_rail',
'brown_mushroom', 'red_mushroom',
'oak_sapling', 'spruce_sapling', 'birch_sapling', 'jungle_sapling',
'acacia_sapling', 'dark_oak_sapling', 'cherry_sapling',
'dandelion', 'poppy', 'blue_orchid', 'allium', 'azure_bluet',
'red_tulip', 'orange_tulip', 'white_tulip', 'pink_tulip',
'oxeye_daisy', 'cornflower', 'lily_of_the_valley', 'sunflower',
'lilac', 'rose_bush', 'peony', 'wither_rose', 'torchflower',
'dead_bush', 'fern', 'short_grass', 'tall_grass', 'large_fern',
'vine', 'lily_pad', 'seagrass', 'kelp', 'hanging_roots', 'spore_blossom',
'tube_coral', 'brain_coral', 'bubble_coral', 'fire_coral', 'horn_coral',
'tube_coral_block', 'brain_coral_block', 'bubble_coral_block', 'fire_coral_block', 'horn_coral_block',
'tube_coral_fan', 'brain_coral_fan', 'bubble_coral_fan', 'fire_coral_fan', 'horn_coral_fan',
'white_concrete_powder', 'orange_concrete_powder', 'magenta_concrete_powder',
'light_blue_concrete_powder', 'yellow_concrete_powder', 'lime_concrete_powder',
'pink_concrete_powder', 'gray_concrete_powder', 'light_gray_concrete_powder',
'cyan_concrete_powder', 'purple_concrete_powder', 'blue_concrete_powder',
'brown_concrete_powder', 'green_concrete_powder', 'red_concrete_powder', 'black_concrete_powder',
'sculk', 'sculk_catalyst', 'sculk_shrieker', 'sculk_sensor', 'sculk_vein',
'mud_bricks', 'packed_mud', 'muddy_mangrove_roots',
'crimson_stem', 'warped_stem', 'stripped_crimson_stem', 'stripped_warped_stem',
'crimson_nylium', 'warped_nylium', 'shroomlight', 'nether_wart_block', 'warped_wart_block',
'crying_obsidian', 'blackstone', 'polished_blackstone', 'polished_blackstone_bricks',
'chiseled_polished_blackstone', 'gilded_blackstone', 'cracked_polished_blackstone_bricks',
'lodestone', 'respawn_anchor',
'pointed_dripstone', 'moss_carpet', 'azalea', 'flowering_azalea',
'powder_snow', 'mangrove_roots',
'copper_block', 'exposed_copper', 'weathered_copper', 'oxidized_copper',
'cut_copper', 'exposed_cut_copper', 'weathered_cut_copper', 'oxidized_cut_copper',
'waxed_copper_block', 'waxed_exposed_copper', 'waxed_weathered_copper', 'waxed_oxidized_copper',
]);
// Some blocks need a specific texture suffix (e.g. furnace_front, oak_log_top)
@@ -104,6 +141,19 @@ const BLOCK_TEXTURE_SUFFIXES = {
grass_block: '_top',
mycelium: '_top',
podzol: '_top',
pumpkin: '_side',
carved_pumpkin: '_front',
jack_o_lantern: '_front',
jukebox: '_top',
loom: '_front',
bee_nest: '_front',
beehive: '_front',
respawn_anchor: '_top',
bone_block: '_side',
basalt: '_side',
polished_basalt: '_side',
quartz_pillar: '_side',
purpur_pillar: '_side',
};
/**
@@ -121,26 +171,26 @@ function getTextureUrls(fullItemName) {
// For non-minecraft mods, try mod-specific URLs first
if (namespace !== 'minecraft') {
const modBase = MOD_TEXTURE_BASES[namespace];
if (modBase) {
urls.push(`${modBase}/item/${shortName}.png`);
urls.push(`${modBase}/block/${shortName}.png`);
urls.push(`${modBase}/block/${shortName}_front.png`);
urls.push(`${modBase}/block/${shortName}_side.png`);
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`);
}
}
// Vanilla texture URLs
// Vanilla texture URLs (through proxy)
if (BLOCK_TEXTURES.has(shortName)) {
const suffix = BLOCK_TEXTURE_SUFFIXES[shortName] || '';
urls.push(`${MC_ASSETS_BASE}/block/${alias}${suffix}.png`);
if (suffix) urls.push(`${MC_ASSETS_BASE}/block/${alias}.png`);
urls.push(`${TEXTURE_PROXY_BASE}/minecraft/block/${alias}${suffix}.png`);
if (suffix) urls.push(`${TEXTURE_PROXY_BASE}/minecraft/block/${alias}.png`);
}
urls.push(`${MC_ASSETS_BASE}/item/${alias}.png`);
urls.push(`${TEXTURE_PROXY_BASE}/minecraft/item/${alias}.png`);
if (!BLOCK_TEXTURES.has(shortName)) {
urls.push(`${MC_ASSETS_BASE}/block/${alias}.png`);
urls.push(`${TEXTURE_PROXY_BASE}/minecraft/block/${alias}.png`);
}
return urls;