Skip to content

Commit 898a004

Browse files
SnaveSutitgitbutler-client
authored andcommitted
✨ Update version-specific vanilla models when changing target MC version
1 parent f9e50fe commit 898a004

7 files changed

Lines changed: 50 additions & 15 deletions

File tree

src/dialogs/blueprintSettings/blueprintSettings.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
OPEN_DOCUMENTATION,
88
} from '../../interface/animatedJavaBarItem'
99
import { updateAllCubeOutlines } from '../../mods/cube'
10+
import { VanillaBlockDisplay } from '../../outliner/vanillaBlockDisplay'
11+
import { VanillaItemDisplay } from '../../outliner/vanillaItemDisplay'
1012
import { createScopedTranslator } from '../../util/lang'
1113
import FooterComponent from './footer.svelte'
1214
import DatapackComponent from './pages/datapack.svelte'
@@ -81,6 +83,9 @@ export function openBlueprintSettings() {
8183
disableKeybinds: true,
8284
buttons: [tl('dialog.close')],
8385
onClose: () => {
86+
VanillaBlockDisplay.forceUpdateAll()
87+
VanillaItemDisplay.forceUpdateAll()
88+
VanillaItemDisplay.forceUpdateAll()
8489
updateRotationConstraints()
8590
updateAllCubeOutlines()
8691
Canvas.updateAll()

src/outliner/textDisplay.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ export class TextDisplay extends ResizableOutlinerElement {
7171
this.sanitizeName()
7272
}
7373

74+
static forceUpdateAll() {
75+
for (const textDisplay of TextDisplay.all) {
76+
textDisplay.preview_controller.updateAll(textDisplay)
77+
}
78+
}
79+
7480
sanitizeName(): string {
7581
this.name = sanitizeOutlinerElementName(this.name, this.uuid)
7682
return this.name

src/outliner/vanillaBlockDisplay.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ export class VanillaBlockDisplay extends ResizableOutlinerElement {
6464
})
6565
}
6666

67+
static forceUpdateAll() {
68+
for (const blockDisplay of VanillaBlockDisplay.all) {
69+
blockDisplay.preview_controller.updateAll(blockDisplay)
70+
}
71+
}
72+
6773
get block() {
6874
if (this.__block === undefined) return 'minecraft:stone'
6975
return this.__block.get()

src/outliner/vanillaItemDisplay.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ export class VanillaItemDisplay extends ResizableOutlinerElement {
7575
})
7676
}
7777

78+
static forceUpdateAll() {
79+
for (const itemDisplay of VanillaItemDisplay.all) {
80+
itemDisplay.preview_controller.updateAll(itemDisplay)
81+
}
82+
}
83+
7884
get item() {
7985
if (this.__item === undefined) return 'minecraft:diamond'
8086
return this.__item.get()

src/systems/minecraft/blockModelManager.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,20 @@ const BLACKLISTED_BLOCKS = new Map([
4949
['piglin_wall_head', translate('block_model_manager.mob_head_warning')],
5050
])
5151

52-
export async function getBlockModel(block: string): Promise<BlockModelMesh | undefined> {
53-
let result = BLOCK_MODEL_CACHE.get(block)
52+
export async function getBlockModel(
53+
block: string,
54+
minecraftVersion = Project.animated_java.target_minecraft_version
55+
): Promise<BlockModelMesh | undefined> {
56+
const key = minecraftVersion + '|' + block
57+
let result = BLOCK_MODEL_CACHE.get(key)
5458
if (!result) {
5559
const parsed = await parseBlock(block)
5660
if (!parsed) return undefined
5761
if (BLACKLISTED_BLOCKS.has(block)) {
5862
throw new Error(BLACKLISTED_BLOCKS.get(block))
5963
}
6064
result = await parseBlockState(parsed)
61-
BLOCK_MODEL_CACHE.set(block, result)
65+
BLOCK_MODEL_CACHE.set(key, result)
6266
}
6367
if (!result) return undefined
6468
result = {

src/systems/minecraft/fontManager.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,12 @@ export class MinecraftFont {
407407
return Math.max(width, 0)
408408
}
409409

410-
getColorMaterial(color: tinycolor.Instance): THREE.Material {
411-
const colorString = color.toHex8String()
412-
let material = this.materialCache.get(colorString)
410+
getColorMaterial(
411+
color: tinycolor.Instance,
412+
minecraftVersion = Project.animated_java.target_minecraft_version
413+
): THREE.Material {
414+
const cacheKey = color.toHex8String() + ';' + minecraftVersion
415+
let material = this.materialCache.get(cacheKey)
413416
if (!material) {
414417
const alpha = color.getAlpha()
415418
if (alpha < 1) {
@@ -421,7 +424,7 @@ export class MinecraftFont {
421424
} else {
422425
material = new THREE.MeshBasicMaterial({ color: color.toHexString() })
423426
}
424-
this.materialCache.set(colorString, material)
427+
this.materialCache.set(cacheKey, material)
425428
}
426429
return material
427430
}
@@ -571,7 +574,11 @@ export class MinecraftFont {
571574
return { mesh, hitbox: backgroundGeo, outline }
572575
}
573576

574-
async getCharGeo(char: string, style: TextComponentStyle): Promise<CachedCharGeo> {
577+
async getCharGeo(
578+
char: string,
579+
style: TextComponentStyle,
580+
minecraftVersion = Project.animated_java.target_minecraft_version
581+
): Promise<CachedCharGeo> {
575582
let font: MinecraftFont = this
576583
if (style.font) {
577584
const newFont = await MinecraftFont.getById(style.font)
@@ -580,12 +587,12 @@ export class MinecraftFont {
580587

581588
const hash = createHash('sha256')
582589
hash.update(char)
590+
hash.update(';' + minecraftVersion)
583591
hash.update(';' + font.id)
584-
if (style.bold) hash.update('bold')
585-
if (style.italic) hash.update('italic')
586-
if (style.underlined) hash.update('underlined')
587-
if (style.strikethrough) hash.update('strikethrough')
588-
if (style.font) hash.update(';' + font.id)
592+
if (style.bold) hash.update(';bold')
593+
if (style.italic) hash.update(';italic')
594+
if (style.underlined) hash.update(';underlined')
595+
if (style.strikethrough) hash.update(';strikethrough')
589596
const digest = hash.digest('hex')
590597

591598
const charData = font.getChar(char)

src/systems/minecraft/itemModelManager.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ const ITEM_MODEL_CACHE = new Map<string, ItemMesh>()
1818

1919
export async function getItemModel(
2020
item: string,
21-
itemDisplay: ItemDisplayMode
21+
itemDisplay: ItemDisplayMode,
22+
minecraftVersion = Project.animated_java.target_minecraft_version
2223
): Promise<ItemMesh | undefined> {
23-
const cacheKey = item + '|' + itemDisplay
24+
const cacheKey = minecraftVersion + '|' + item + '|' + itemDisplay
2425
let result = ITEM_MODEL_CACHE.get(cacheKey)
2526
if (!result) {
2627
result = await parseItemModel(getItemResourceLocation(item), itemDisplay)

0 commit comments

Comments
 (0)