Skip to content

Commit ec2e41b

Browse files
committed
🚧 Add Custom Name and Custom Name Visible
- Added Custom Name and Custom Name Visible to bone, item display, and block display configs.
1 parent 3bbb526 commit ec2e41b

10 files changed

+291
-21
lines changed

src/blueprintFormat.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { process } from './systems/modelDataFixerUpper'
1616
* The serialized Variant Bone Config
1717
*/
1818
export interface IBlueprintBoneConfigJSON {
19+
custom_name?: BoneConfig['customName']
20+
custom_name_visible?: BoneConfig['customNameVisible']
1921
billboard?: BoneConfig['billboard']
2022
override_brightness?: BoneConfig['overrideBrightness']
2123
brightness_override?: BoneConfig['brightnessOverride']

src/components/boneConfigDialog.svelte

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313

1414
<script lang="ts">
1515
import { NbtCompound, NbtTag } from 'deepslate/lib/nbt'
16+
import { JsonText } from '../systems/minecraft/jsonText'
1617
1718
const pluginModeEnabled = !!Project?.animated_java?.enable_plugin_mode
1819
1920
export let variant: Variant
2021
22+
export let customName: Valuable<string>
23+
export let customNameVisible: Valuable<boolean>
2124
export let billboard: Valuable<string>
2225
export let overrideBrightness: Valuable<NonNullable<BoneConfig['_overrideBrightness']>>
2326
export let brightnessOverride: Valuable<NonNullable<BoneConfig['_brightnessOverride']>>
@@ -58,6 +61,21 @@
5861
5962
return { type: 'success', message: '' }
6063
}
64+
65+
const customNameChecker: DialogItemValueChecker<string> = value => {
66+
if (value === '') return { type: 'success', message: '' }
67+
68+
try {
69+
JsonText.fromString(value)
70+
} catch (e: any) {
71+
return {
72+
type: 'error',
73+
message: translate('dialog.bone_config.custom_name.invalid_json.error', e.message),
74+
}
75+
}
76+
77+
return { type: 'success', message: '' }
78+
}
6179
</script>
6280

6381
<div>
@@ -81,6 +99,19 @@
8199
bind:checked={inheritSettings}
82100
/>
83101

102+
<LineInput
103+
label={translate('dialog.bone_config.custom_name.title')}
104+
tooltip={translate('dialog.bone_config.custom_name.description')}
105+
bind:value={customName}
106+
valueChecker={customNameChecker}
107+
/>
108+
109+
<Checkbox
110+
label={translate('dialog.bone_config.custom_name_visible.title')}
111+
tooltip={translate('dialog.bone_config.custom_name_visible.description')}
112+
bind:checked={customNameVisible}
113+
/>
114+
84115
<Select
85116
label={translate('dialog.bone_config.billboard.title')}
86117
tooltip={translate('dialog.bone_config.billboard.description')}
@@ -150,6 +181,19 @@
150181
bind:checked={inheritSettings}
151182
/>
152183

184+
<LineInput
185+
label={translate('dialog.bone_config.custom_name.title')}
186+
tooltip={translate('dialog.bone_config.custom_name.description')}
187+
bind:value={customName}
188+
valueChecker={customNameChecker}
189+
/>
190+
191+
<Checkbox
192+
label={translate('dialog.bone_config.custom_name_visible.title')}
193+
tooltip={translate('dialog.bone_config.custom_name_visible.description')}
194+
bind:checked={customNameVisible}
195+
/>
196+
153197
<Checkbox
154198
label={translate('dialog.bone_config.use_nbt.title')}
155199
tooltip={translate('dialog.bone_config.use_nbt.description')}

src/components/vanillaBlockDisplayConfigDialog.svelte

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212

1313
<script lang="ts">
1414
import { NbtCompound, NbtTag } from 'deepslate/lib/nbt'
15+
import { JsonText } from '../systems/minecraft/jsonText'
1516
1617
const pluginModeEnabled = !!Project?.animated_java?.enable_plugin_mode
1718
19+
export let customName: Valuable<string>
20+
export let customNameVisible: Valuable<boolean>
1821
export let billboard: Valuable<string>
1922
export let overrideBrightness: Valuable<NonNullable<BoneConfig['_overrideBrightness']>>
2023
export let brightnessOverride: Valuable<NonNullable<BoneConfig['_brightnessOverride']>>
@@ -53,6 +56,21 @@
5356
5457
return { type: 'success', message: '' }
5558
}
59+
60+
const customNameChecker: DialogItemValueChecker<string> = value => {
61+
if (value === '') return { type: 'success', message: '' }
62+
63+
try {
64+
JsonText.fromString(value)
65+
} catch (e: any) {
66+
return {
67+
type: 'error',
68+
message: translate('dialog.bone_config.custom_name.invalid_json.error', e.message),
69+
}
70+
}
71+
72+
return { type: 'success', message: '' }
73+
}
5674
</script>
5775

5876
<div>
@@ -65,6 +83,19 @@
6583
bind:value={billboard}
6684
/>
6785

86+
<LineInput
87+
label={translate('dialog.bone_config.custom_name.title')}
88+
tooltip={translate('dialog.bone_config.custom_name.description')}
89+
bind:value={customName}
90+
valueChecker={customNameChecker}
91+
/>
92+
93+
<Checkbox
94+
label={translate('dialog.bone_config.custom_name_visible.title')}
95+
tooltip={translate('dialog.bone_config.custom_name_visible.description')}
96+
bind:checked={customNameVisible}
97+
/>
98+
6899
<Checkbox
69100
label={translate('dialog.bone_config.glowing.title')}
70101
tooltip={translate('dialog.bone_config.glowing.description')}
@@ -131,6 +162,19 @@
131162
valueChecker={nbtChecker}
132163
/>
133164
{:else}
165+
<LineInput
166+
label={translate('dialog.bone_config.custom_name.title')}
167+
tooltip={translate('dialog.bone_config.custom_name.description')}
168+
bind:value={customName}
169+
valueChecker={customNameChecker}
170+
/>
171+
172+
<Checkbox
173+
label={translate('dialog.bone_config.custom_name_visible.title')}
174+
tooltip={translate('dialog.bone_config.custom_name_visible.description')}
175+
bind:checked={customNameVisible}
176+
/>
177+
134178
<Select
135179
label={translate('dialog.bone_config.billboard.title')}
136180
tooltip={translate('dialog.bone_config.billboard.description')}

src/components/vanillaItemDisplayConfigDialog.svelte

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212

1313
<script lang="ts">
1414
import { NbtCompound, NbtTag } from 'deepslate/lib/nbt'
15+
import { JsonText } from '../systems/minecraft/jsonText'
1516
1617
const pluginModeEnabled = !!Project?.animated_java?.enable_plugin_mode
1718
19+
export let customName: Valuable<string>
20+
export let customNameVisible: Valuable<boolean>
1821
export let billboard: Valuable<string>
1922
export let overrideBrightness: Valuable<NonNullable<BoneConfig['_overrideBrightness']>>
2023
export let brightnessOverride: Valuable<NonNullable<BoneConfig['_brightnessOverride']>>
@@ -53,6 +56,21 @@
5356
5457
return { type: 'success', message: '' }
5558
}
59+
60+
const customNameChecker: DialogItemValueChecker<string> = value => {
61+
if (value === '') return { type: 'success', message: '' }
62+
63+
try {
64+
JsonText.fromString(value)
65+
} catch (e: any) {
66+
return {
67+
type: 'error',
68+
message: translate('dialog.bone_config.custom_name.invalid_json.error', e.message),
69+
}
70+
}
71+
72+
return { type: 'success', message: '' }
73+
}
5674
</script>
5775

5876
<div>
@@ -65,6 +83,19 @@
6583
bind:value={billboard}
6684
/>
6785

86+
<LineInput
87+
label={translate('dialog.bone_config.custom_name.title')}
88+
tooltip={translate('dialog.bone_config.custom_name.description')}
89+
bind:value={customName}
90+
valueChecker={customNameChecker}
91+
/>
92+
93+
<Checkbox
94+
label={translate('dialog.bone_config.custom_name_visible.title')}
95+
tooltip={translate('dialog.bone_config.custom_name_visible.description')}
96+
bind:checked={customNameVisible}
97+
/>
98+
6899
<Checkbox
69100
label={translate('dialog.bone_config.glowing.title')}
70101
tooltip={translate('dialog.bone_config.glowing.description')}
@@ -131,6 +162,19 @@
131162
valueChecker={nbtChecker}
132163
/>
133164
{:else}
165+
<LineInput
166+
label={translate('dialog.bone_config.custom_name.title')}
167+
tooltip={translate('dialog.bone_config.custom_name.description')}
168+
bind:value={customName}
169+
valueChecker={customNameChecker}
170+
/>
171+
172+
<Checkbox
173+
label={translate('dialog.bone_config.custom_name_visible.title')}
174+
tooltip={translate('dialog.bone_config.custom_name_visible.description')}
175+
bind:checked={customNameVisible}
176+
/>
177+
134178
<Select
135179
label={translate('dialog.bone_config.billboard.title')}
136180
tooltip={translate('dialog.bone_config.billboard.description')}

src/interface/boneConfigDialog.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ export function openBoneConfigDialog(bone: Group) {
6565

6666
const oldConfig = BoneConfig.fromJSON(boneConfigJSON)
6767

68+
const customName = new Valuable(oldConfig.customName)
69+
const customNameVisible = new Valuable(oldConfig.customNameVisible)
6870
const billboard = new Valuable(oldConfig.billboard as string)
6971
const overrideBrightness = new Valuable(oldConfig.overrideBrightness)
7072
const brightnessOverride = new Valuable(oldConfig.brightnessOverride)
@@ -86,6 +88,8 @@ export function openBoneConfigDialog(bone: Group) {
8688
component: BoneConfigDialogSvelteComponent,
8789
props: {
8890
variant: Variant.selected!,
91+
customName,
92+
customNameVisible,
8993
billboard,
9094
overrideBrightness,
9195
brightnessOverride,
@@ -104,6 +108,8 @@ export function openBoneConfigDialog(bone: Group) {
104108
onConfirm() {
105109
const newConfig = new BoneConfig()
106110

111+
newConfig.customName = customName.get()
112+
newConfig.customNameVisible = customNameVisible.get()
107113
newConfig.billboard = billboard.get() as any
108114
newConfig.overrideBrightness = overrideBrightness.get()
109115
newConfig.brightnessOverride = brightnessOverride.get()
@@ -118,6 +124,10 @@ export function openBoneConfigDialog(bone: Group) {
118124
newConfig.shadowStrength = shadowStrength.get()
119125
newConfig.useNBT = useNBT.get()
120126

127+
// Remove properties that are the same as the parent's
128+
newConfig.customName === parentConfig.customName && (newConfig.customName = undefined)
129+
newConfig.customNameVisible === parentConfig.customNameVisible &&
130+
(newConfig.customNameVisible = undefined)
121131
newConfig.billboard === parentConfig.billboard && (newConfig.billboard = undefined)
122132
newConfig.overrideBrightness === parentConfig.overrideBrightness &&
123133
(newConfig.overrideBrightness = undefined)

src/interface/vanillaBlockDisplayConfigDialog.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { isCurrentFormat } from '../blueprintFormat'
2-
import { TextDisplayConfig } from '../nodeConfigs'
2+
import { BoneConfig } from '../nodeConfigs'
33
import { PACKAGE } from '../constants'
44
import { createAction } from '../util/moddingTools'
55
import { Valuable } from '../util/stores'
@@ -11,10 +11,10 @@ import VanillaBlockDisplayConfigDialog from '../components/vanillaBlockDisplayCo
1111

1212
export function openVanillaBlockDisplayConfigDialog(display: VanillaBlockDisplay) {
1313
// Blockbench's JSON stringifier doesn't handle custom toJSON functions, so I'm storing the config JSON in the bone instead of the actual BoneConfig object
14-
const oldConfig = TextDisplayConfig.fromJSON(
15-
(display.config ??= new TextDisplayConfig().toJSON())
16-
)
14+
const oldConfig = BoneConfig.fromJSON((display.config ??= new BoneConfig().toJSON()))
1715

16+
const customName = new Valuable(oldConfig.customName)
17+
const customNameVisible = new Valuable(oldConfig.customNameVisible)
1818
const billboard = new Valuable(oldConfig.billboard as string)
1919
const overrideBrightness = new Valuable(oldConfig.overrideBrightness)
2020
const brightnessOverride = new Valuable(oldConfig.brightnessOverride)
@@ -34,6 +34,8 @@ export function openVanillaBlockDisplayConfigDialog(display: VanillaBlockDisplay
3434
component: VanillaBlockDisplayConfigDialog,
3535
props: {
3636
variant: Variant.selected,
37+
customName,
38+
customNameVisible,
3739
billboard,
3840
overrideBrightness,
3941
brightnessOverride,
@@ -48,8 +50,10 @@ export function openVanillaBlockDisplayConfigDialog(display: VanillaBlockDisplay
4850
},
4951
preventKeybinds: true,
5052
onConfirm() {
51-
const newConfig = new TextDisplayConfig()
53+
const newConfig = new BoneConfig()
5254

55+
newConfig.customName = customName.get()
56+
newConfig.customNameVisible = customNameVisible.get()
5357
newConfig.billboard = billboard.get() as any
5458
newConfig.overrideBrightness = overrideBrightness.get()
5559
newConfig.brightnessOverride = brightnessOverride.get()
@@ -62,8 +66,11 @@ export function openVanillaBlockDisplayConfigDialog(display: VanillaBlockDisplay
6266
newConfig.shadowStrength = shadowStrength.get()
6367
newConfig.useNBT = useNBT.get()
6468

65-
const defaultConfig = TextDisplayConfig.getDefault()
69+
const defaultConfig = BoneConfig.getDefault()
6670

71+
newConfig.customName === defaultConfig.customName && (newConfig.customName = undefined)
72+
newConfig.customNameVisible === defaultConfig.customNameVisible &&
73+
(newConfig.customNameVisible = undefined)
6774
newConfig.billboard === defaultConfig.billboard && (newConfig.billboard = undefined)
6875
newConfig.overrideBrightness === defaultConfig.overrideBrightness &&
6976
(newConfig.overrideBrightness = undefined)

src/interface/vanillaItemDisplayConfigDialog.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { isCurrentFormat } from '../blueprintFormat'
2-
import { TextDisplayConfig } from '../nodeConfigs'
2+
import { BoneConfig } from '../nodeConfigs'
33
import { PACKAGE } from '../constants'
44
import { createAction } from '../util/moddingTools'
55
import { Valuable } from '../util/stores'
@@ -11,10 +11,10 @@ import VanillaItemDisplayConfigDialog from '../components/vanillaItemDisplayConf
1111

1212
export function openVanillaItemDisplayConfigDialog(display: VanillaItemDisplay) {
1313
// Blockbench's JSON stringifier doesn't handle custom toJSON functions, so I'm storing the config JSON in the bone instead of the actual BoneConfig object
14-
const oldConfig = TextDisplayConfig.fromJSON(
15-
(display.config ??= new TextDisplayConfig().toJSON())
16-
)
14+
const oldConfig = BoneConfig.fromJSON((display.config ??= new BoneConfig().toJSON()))
1715

16+
const customName = new Valuable(oldConfig.customName)
17+
const customNameVisible = new Valuable(oldConfig.customNameVisible)
1818
const billboard = new Valuable(oldConfig.billboard as string)
1919
const overrideBrightness = new Valuable(oldConfig.overrideBrightness)
2020
const brightnessOverride = new Valuable(oldConfig.brightnessOverride)
@@ -34,6 +34,8 @@ export function openVanillaItemDisplayConfigDialog(display: VanillaItemDisplay)
3434
component: VanillaItemDisplayConfigDialog,
3535
props: {
3636
variant: Variant.selected,
37+
customName,
38+
customNameVisible,
3739
billboard,
3840
overrideBrightness,
3941
brightnessOverride,
@@ -48,8 +50,10 @@ export function openVanillaItemDisplayConfigDialog(display: VanillaItemDisplay)
4850
},
4951
preventKeybinds: true,
5052
onConfirm() {
51-
const newConfig = new TextDisplayConfig()
53+
const newConfig = new BoneConfig()
5254

55+
newConfig.customName = customName.get()
56+
newConfig.customNameVisible = customNameVisible.get()
5357
newConfig.billboard = billboard.get() as any
5458
newConfig.overrideBrightness = overrideBrightness.get()
5559
newConfig.brightnessOverride = brightnessOverride.get()
@@ -62,8 +66,11 @@ export function openVanillaItemDisplayConfigDialog(display: VanillaItemDisplay)
6266
newConfig.shadowStrength = shadowStrength.get()
6367
newConfig.useNBT = useNBT.get()
6468

65-
const defaultConfig = TextDisplayConfig.getDefault()
69+
const defaultConfig = BoneConfig.getDefault()
6670

71+
newConfig.customName === defaultConfig.customName && (newConfig.customName = undefined)
72+
newConfig.customNameVisible === defaultConfig.customNameVisible &&
73+
(newConfig.customNameVisible = undefined)
6774
newConfig.billboard === defaultConfig.billboard && (newConfig.billboard = undefined)
6875
newConfig.overrideBrightness === defaultConfig.overrideBrightness &&
6976
(newConfig.overrideBrightness = undefined)

0 commit comments

Comments
 (0)