Skip to content

Commit ef7b110

Browse files
SnaveSutitgitbutler-client
authored andcommitted
✨ Enchantment Glint Preview
1 parent 3f6669c commit ef7b110

8 files changed

Lines changed: 214 additions & 270 deletions

File tree

src/dialogs/displayEntityConfig/displayEntityConfig.svelte

Lines changed: 0 additions & 257 deletions
This file was deleted.

src/dialogs/displayEntityConfig/pages/perVariant.svelte

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { onDestroy } from 'svelte'
33
import { DisplayEntityConfig } from '../../../nodeConfigs'
44
import { TextDisplay } from '../../../outliner/textDisplay'
5+
import { VanillaBlockDisplay } from '../../../outliner/vanillaBlockDisplay'
56
import BoxSelect from '../../../svelteComponents/sidebarDialogItems/boxSelect.svelte'
67
import Checkbox from '../../../svelteComponents/sidebarDialogItems/checkbox.svelte'
78
import CodeEdit from '../../../svelteComponents/sidebarDialogItems/codeEdit.svelte'
@@ -80,6 +81,7 @@
8081
8182
onDestroy(() => {
8283
saveConfig()
84+
Canvas.updateAll()
8385
})
8486
</script>
8587

@@ -160,11 +162,13 @@
160162
{/if}
161163

162164
{#if !(displayEntity instanceof TextDisplay)}
163-
<Checkbox
164-
label={localize('dialog.display_entity.enchanted.title')}
165-
description={localize('dialog.display_entity.enchanted.description')}
166-
bind:value={enchanted}
167-
/>
165+
{#if !(displayEntity instanceof VanillaBlockDisplay)}
166+
<Checkbox
167+
label={localize('dialog.display_entity.enchanted.title')}
168+
description={localize('dialog.display_entity.enchanted.description')}
169+
bind:value={enchanted}
170+
/>
171+
{/if}
168172

169173
<Checkbox
170174
label={localize('dialog.display_entity.glowing.title')}

src/formats/blueprint/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,10 @@ export const BLUEPRINT_FORMAT = registerDeletableHandlerPatch({
346346
fixCubeRotation(cube)
347347
}
348348

349-
Canvas.updateAll()
349+
requestAnimationFrame(() => {
350+
Variant.selectDefault()
351+
Canvas.updateAll()
352+
})
350353
})
351354
},
352355

src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import './systems/minecraft/blockstateManager'
2323
import './systems/minecraft/fontManager'
2424
import './systems/minecraft/registryManager'
2525
import './systems/minecraft/versionManager'
26+
// Shaders
27+
import 'import_folder_recursive:./shaders'
2628
// Misc imports
2729
import { openChangelogDialog } from './dialogs/changelog/changelog'
2830
import { openExportProgressDialog } from './dialogs/exportProgress/exportProgress'
@@ -31,11 +33,15 @@ import { BLUEPRINT_FORMAT } from './formats/blueprint'
3133
import { BLUEPRINT_CODEC } from './formats/blueprint/codec'
3234
import { exportAll } from './interface/animatedJavaBarItem'
3335
import { TextDisplay } from './outliner/textDisplay'
34-
import { VanillaBlockDisplay, debugBlockState } from './outliner/vanillaBlockDisplay'
36+
import { debugBlockState, VanillaBlockDisplay } from './outliner/vanillaBlockDisplay'
3537
import { VanillaItemDisplay } from './outliner/vanillaItemDisplay'
3638
import { checkForIncompatabilities } from './popups/incompatability/incompatability'
3739
import { openInstallPopup } from './popups/installed/installed'
3840
import './prism/mcfunctionPrism'
41+
import {
42+
applyEnchantmentGlintToMesh,
43+
removeEnchantmentGlintFromMesh,
44+
} from './shaders/enchantmentGlint'
3945
import { cleanupExportedFiles } from './systems/cleaner'
4046
import TELLRAW from './systems/datapackCompiler/tellraw'
4147
import { exportProject } from './systems/exporter'
@@ -112,6 +118,8 @@ const AnimatedJavaApi = {
112118
},
113119
TELLRAW,
114120
getBlockState,
121+
applyEnchantmentGlintToMesh,
122+
removeEnchantmentGlintFromMesh,
115123
}
116124
window.AnimatedJava = AnimatedJavaApi
117125

src/mods/cube.ts

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1-
import { overrideAccessors, registerPatch } from 'blockbench-patch-manager'
2-
import { activeProjectIsBlueprintFormat, projectTargetVersionIsAtLeast } from '../formats/blueprint'
1+
import {
2+
overrideAccessors,
3+
registerPatch,
4+
registerPropertyOverridePatch,
5+
} from 'blockbench-patch-manager'
6+
import {
7+
activeProjectIsBlueprintFormat,
8+
projectTargetVersionIsAtLeast,
9+
type IBlueprintDisplayEntityConfigJSON,
10+
} from '../formats/blueprint'
11+
import {
12+
applyEnchantmentGlintToMesh,
13+
removeEnchantmentGlintFromMesh,
14+
} from '../shaders/enchantmentGlint'
315
import { isCubeValid } from '../systems/util'
416
import { localize as translate } from '../util/lang'
17+
import { Variant } from '../variants'
518

619
declare global {
720
// @ts-expect-error - Broken BB types
@@ -109,3 +122,35 @@ registerPatch({
109122
Cube.prototype.init = originalInit
110123
},
111124
})
125+
126+
registerPropertyOverridePatch({
127+
id: `animated_java:override-function/cube/preview_controller/updateGeometry`,
128+
target: Cube.preview_controller,
129+
key: 'updateGeometry',
130+
131+
condition: () => activeProjectIsBlueprintFormat(),
132+
133+
get: original => {
134+
return function (this: NodePreviewController, instance: Cube) {
135+
original.apply(this, [instance])
136+
137+
if (activeProjectIsBlueprintFormat()) {
138+
const parent = instance.parent
139+
let config: IBlueprintDisplayEntityConfigJSON
140+
if (parent instanceof Group) {
141+
if (!Variant.selected || Variant.selected.isDefault) {
142+
config = parent.configs.default
143+
} else {
144+
config = parent.configs.variants[Variant.selected.uuid]
145+
}
146+
147+
removeEnchantmentGlintFromMesh(instance.mesh)
148+
149+
if (config?.enchanted) {
150+
applyEnchantmentGlintToMesh(instance.mesh)
151+
}
152+
}
153+
}
154+
}
155+
},
156+
})

0 commit comments

Comments
 (0)