mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-23 23:27:09 +00:00
Show item textures for loot table entries
This commit is contained in:
@@ -9,7 +9,7 @@ import { localize, useStore } from '../contexts'
|
||||
import { useFocus } from '../hooks'
|
||||
import { VanillaColors } from '../previews'
|
||||
import type { BlockStateRegistry, VersionId } from '../services'
|
||||
import { CachedDecorator, CachedFeature } from '../services'
|
||||
import { CachedCollections, CachedDecorator, CachedFeature, getTextureUrl } from '../services'
|
||||
import { deepClone, deepEqual, generateUUID, hexId, hexToRgb, isObject, newSeed, rgbToHex, stringToColor } from '../Utils'
|
||||
import { ModelWrapper } from './ModelWrapper'
|
||||
|
||||
@@ -22,6 +22,8 @@ const fixedLists = ['generator_biome.parameters.temperature', 'generator_biome.p
|
||||
const collapsedFields = ['noise_settings.surface_rule', 'noise_settings.noise.terrain_shaper']
|
||||
const collapsableFields = ['density_function.argument', 'density_function.argument1', 'density_function.argument2', 'density_function.input', 'density_function.when_in_range', 'density_function.when_out_of_range']
|
||||
|
||||
const PACKAGE = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M8.878.392a1.75 1.75 0 00-1.756 0l-5.25 3.045A1.75 1.75 0 001 4.951v6.098c0 .624.332 1.2.872 1.514l5.25 3.045a1.75 1.75 0 001.756 0l5.25-3.045c.54-.313.872-.89.872-1.514V4.951c0-.624-.332-1.2-.872-1.514L8.878.392zM7.875 1.69a.25.25 0 01.25 0l4.63 2.685L8 7.133 3.245 4.375l4.63-2.685zM2.5 5.677v5.372c0 .09.047.171.125.216l4.625 2.683V8.432L2.5 5.677zm6.25 8.271l4.625-2.683a.25.25 0 00.125-.216V5.677L8.75 8.432v5.516z"></path></svg>'
|
||||
|
||||
const findGenerator = (id: string) => {
|
||||
return config.generators.find(g => g.id === id.replace(/^\$/, ''))
|
||||
}
|
||||
@@ -134,11 +136,24 @@ const renderHtml: RenderHook = {
|
||||
const cPath = path.push(index).contextPush('entry')
|
||||
const canToggle = children.type(cPath) === 'object'
|
||||
const toggle = isToggled(cId)
|
||||
|
||||
let label: undefined | string | JSX.Element
|
||||
if (['loot_pool.entries.entry', 'loot_entry.alternatives.children.entry', 'loot_entry.group.children.entry', 'loot_entry.sequence.children.entry', 'function.set_contents.entries.entry'].includes(cPath.getContext().join('.'))) {
|
||||
if (isObject(cValue) && typeof cValue.type === 'string' && cValue.type.replace(/^minecraft:/, '') === 'item' && typeof cValue.name === 'string') {
|
||||
const texturePath = `item/${cValue.name.replace(/^minecraft:/, '')}`
|
||||
if (CachedCollections.get('texture').includes('minecraft:' + texturePath)) {
|
||||
label = <img src={getTextureUrl(version, texturePath)} alt="" onError={e => e.currentTarget.outerHTML = PACKAGE} />
|
||||
} else {
|
||||
label = Octicon.package
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (canToggle && (toggle === false || (toggle === undefined && value.length > 20))) {
|
||||
return <div class="node node-header" data-category={children.category(cPath)}>
|
||||
<ErrorPopup lang={lang} path={cPath} nested />
|
||||
<button class="toggle tooltipped tip-se" aria-label={`${localize(lang, 'expand')}\n${localize(lang, 'expand_all', 'Ctrl')}`} onClick={expand(cId)}>{Octicon.chevron_right}</button>
|
||||
<label>{pathLocale(lang, cPath, `${index}`)}</label>
|
||||
<label>{label ?? pathLocale(lang, cPath, `${index}`)}</label>
|
||||
<Collapsed key={cId} path={cPath} value={cValue} schema={children} />
|
||||
</div>
|
||||
}
|
||||
@@ -165,7 +180,7 @@ const renderHtml: RenderHook = {
|
||||
},
|
||||
},
|
||||
]
|
||||
return <MemoedTreeNode key={cId} path={cPath} schema={children} value={cValue} {...{lang, version, states, actions}} ctx={{...ctx, index: (index === 0 ? 1 : 0) + (index === value.length - 1 ? 2 : 0)}}>
|
||||
return <MemoedTreeNode key={cId} label={label} path={cPath} schema={children} value={cValue} {...{lang, version, states, actions}} ctx={{...ctx, index: (index === 0 ? 1 : 0) + (index === value.length - 1 ? 2 : 0)}}>
|
||||
{canToggle && <button class="toggle tooltipped tip-se" aria-label={`${localize(lang, 'collapse')}\n${localize(lang, 'collapse_all', 'Ctrl')}`} onClick={collapse(cId)}>{Octicon.chevron_down}</button>}
|
||||
<button class="remove tooltipped tip-se" aria-label={localize(lang, 'remove')} onClick={onRemove}>{Octicon.trashcan}</button>
|
||||
{value.length > 1 && <div class="node-move">
|
||||
@@ -451,7 +466,7 @@ type TreeNodeProps = {
|
||||
states: BlockStateRegistry,
|
||||
ctx: Record<string, any>,
|
||||
compare?: any,
|
||||
label?: string,
|
||||
label?: string | ComponentChildren,
|
||||
actions?: MenuAction[],
|
||||
children?: ComponentChildren,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user