Skip to content

Commit 3bbb526

Browse files
committed
🚧 Add item_display mode to Item Displays
1 parent a8e2b72 commit 3bbb526

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-0
lines changed

src/components/vanillaItemDisplayElementPanel.svelte

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script lang="ts" context="module">
2+
import { ITEM_DISPLAY_ITEM_DISPLAY_SELECT } from '../interface/vanillaItemDisplayElementPanel'
23
import { VanillaItemDisplay } from '../outliner/vanillaItemDisplay'
34
import { events } from '../util/events'
45
import { Valuable } from '../util/stores'
@@ -10,6 +11,7 @@
1011
1112
let item = new Valuable<string>('')
1213
let error = new Valuable<string>('')
14+
let itemDisplaySlot: HTMLDivElement
1315
let visible = false
1416
1517
events.UPDATE_SELECTION.subscribe(() => {
@@ -22,8 +24,13 @@
2224
}
2325
item = selectedDisplay._item
2426
error = selectedDisplay.error
27+
ITEM_DISPLAY_ITEM_DISPLAY_SELECT.set(selectedDisplay.itemDisplay)
2528
visible = true
2629
})
30+
31+
requestAnimationFrame(() => {
32+
itemDisplaySlot.appendChild(ITEM_DISPLAY_ITEM_DISPLAY_SELECT.node)
33+
})
2734
</script>
2835

2936
<p class="panel_toolbar_label label" style={!!visible ? '' : 'visibility:hidden; height: 0px;'}>
@@ -38,6 +45,7 @@
3845
<div class="content" style="width: 95%;">
3946
<input type="text" bind:value={$item} />
4047
</div>
48+
<div class="content" bind:this={itemDisplaySlot}></div>
4149
</div>
4250

4351
<div
@@ -71,4 +79,7 @@
7179
font-size: 14px;
7280
color: var(--color-error);
7381
}
82+
.custom-toolbar :global([toolbar_item='animated_java:itemDisplayAlignmentSelect']) {
83+
margin: 0px 2px !important;
84+
}
7485
</style>

src/interface/vanillaItemDisplayElementPanel.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
import { isCurrentFormat } from '../blueprintFormat'
12
import VanillaItemDisplayElementPanel from '../components/vanillaItemDisplayElementPanel.svelte'
3+
import { PACKAGE } from '../constants'
4+
import { VanillaItemDisplay } from '../outliner/vanillaItemDisplay'
25
import { injectSvelteCompomponentMod } from '../util/injectSvelteComponent'
6+
import { translate } from '../util/translation'
37

48
injectSvelteCompomponentMod({
59
component: VanillaItemDisplayElementPanel,
@@ -8,3 +12,51 @@ injectSvelteCompomponentMod({
812
return document.querySelector('#panel_element')
913
},
1014
})
15+
16+
export const ITEM_DISPLAY_ITEM_DISPLAY_SELECT = new BarSelect(
17+
`${PACKAGE.name}:itemDisplayAlignmentSelect`,
18+
{
19+
name: translate('tool.item_display.item_display.title'),
20+
icon: 'format_align_left',
21+
description: translate('tool.item_display.item_display.description'),
22+
condition: () => isCurrentFormat() && !!VanillaItemDisplay.selected.length,
23+
options: {
24+
none: translate('tool.item_display.item_display.options.none'),
25+
thirdperson_lefthand: translate(
26+
'tool.item_display.item_display.options.thirdperson_lefthand'
27+
),
28+
thirdperson_righthand: translate(
29+
'tool.item_display.item_display.options.thirdperson_righthand'
30+
),
31+
firstperson_lefthand: translate(
32+
'tool.item_display.item_display.options.firstperson_lefthand'
33+
),
34+
firstperson_righthand: translate(
35+
'tool.item_display.item_display.options.firstperson_righthand'
36+
),
37+
head: translate('tool.item_display.item_display.options.head'),
38+
gui: translate('tool.item_display.item_display.options.gui'),
39+
ground: translate('tool.item_display.item_display.options.ground'),
40+
fixed: translate('tool.item_display.item_display.options.fixed'),
41+
},
42+
}
43+
)
44+
ITEM_DISPLAY_ITEM_DISPLAY_SELECT.get = function () {
45+
const selected = VanillaItemDisplay.selected[0]
46+
if (!selected) return 'left'
47+
return selected.itemDisplay
48+
}
49+
ITEM_DISPLAY_ITEM_DISPLAY_SELECT.set = function (this: BarSelect<string>, value: string) {
50+
const selected = VanillaItemDisplay.selected[0]
51+
if (!selected) return this
52+
this.value = value
53+
const name = this.getNameFor(value)
54+
this.nodes.forEach(node => {
55+
$(node).find('bb-select').text(name)
56+
})
57+
if (!this.nodes.includes(this.node)) {
58+
$(this.node).find('bb-select').text(name)
59+
}
60+
selected.itemDisplay = value
61+
return this
62+
}

src/lang/en.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,17 @@ animated_java.tool.text_display.see_through.description: Whether or not the text
503503
# Item Display Panel
504504
animated_java.panel.vanilla_item_display.title: Displayed Item
505505
animated_java.panel.vanilla_item_display.description: The item to display.
506+
animated_java.tool.item_display.item_display.title: Item Display Mode
507+
animated_java.tool.item_display.item_display.description: Which item model transform to apply to the item (as defined in display field in model JSON).
508+
animated_java.tool.item_display.item_display.options.none: None
509+
animated_java.tool.item_display.item_display.options.thirdperson_lefthand: Third Person Left Hand
510+
animated_java.tool.item_display.item_display.options.thirdperson_righthand: Third Person Right Hand
511+
animated_java.tool.item_display.item_display.options.firstperson_lefthand: First Person Left Hand
512+
animated_java.tool.item_display.item_display.options.firstperson_righthand: First Person Right Hand
513+
animated_java.tool.item_display.item_display.options.head: Head
514+
animated_java.tool.item_display.item_display.options.gui: GUI
515+
animated_java.tool.item_display.item_display.options.ground: Ground
516+
animated_java.tool.item_display.item_display.options.fixed: Fixed
506517

507518
# Block Display Panel
508519
animated_java.panel.vanilla_block_display.title: Displayed Block

src/outliner/vanillaItemDisplay.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { VanillaBlockDisplay } from './vanillaBlockDisplay'
1717
interface VanillaItemDisplayOptions {
1818
name?: string
1919
item?: string
20+
item_display?: string
2021
position?: ArrayVector3
2122
rotation?: ArrayVector3
2223
scale?: ArrayVector3
@@ -34,6 +35,7 @@ export class VanillaItemDisplay extends ResizableOutlinerElement {
3435

3536
// Properties
3637
public _item = new Valuable('minecraft:diamond')
38+
public _itemDisplay = new Valuable('none')
3739
public config: IBlueprintBoneConfigJSON
3840

3941
public error = new Valuable('')
@@ -63,6 +65,7 @@ export class VanillaItemDisplay extends ResizableOutlinerElement {
6365
this.extend(data)
6466

6567
this.item ??= 'minecraft:diamond'
68+
this.itemDisplay ??= 'none'
6669
this.position ??= [0, 0, 0]
6770
this.rotation ??= [0, 0, 0]
6871
this.scale ??= [1, 1, 1]
@@ -106,6 +109,15 @@ export class VanillaItemDisplay extends ResizableOutlinerElement {
106109
this._item.set(value)
107110
}
108111

112+
get itemDisplay() {
113+
if (this._itemDisplay === undefined) return 'none'
114+
return this._itemDisplay.get()
115+
}
116+
set itemDisplay(value: string) {
117+
if (this._itemDisplay === undefined) return
118+
this._itemDisplay.set(value)
119+
}
120+
109121
async waitForReady() {
110122
while (!this.ready) {
111123
await new Promise(resolve => setTimeout(resolve, 1000 / framespersecond))
@@ -210,6 +222,7 @@ export class VanillaItemDisplay extends ResizableOutlinerElement {
210222
}
211223
}
212224
new Property(VanillaItemDisplay, 'string', 'item', { default: 'minecraft:diamond' })
225+
new Property(VanillaItemDisplay, 'string', 'item_display', { default: 'none' })
213226
new Property(VanillaItemDisplay, 'object', 'config', {
214227
get default() {
215228
return new BoneConfig().toJSON()

src/systems/rigRenderer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ export interface IRenderedNodes {
127127
ItemDisplay: IRenderedNode & {
128128
type: 'item_display'
129129
item: string
130+
itme_display: string
130131
/**
131132
* The base scale of the bone, used to offset any rescaling done to the bone's model due to exceeding the 3x3x3 model size limit.
132133
*/
@@ -443,6 +444,7 @@ function renderItemDisplay(display: VanillaItemDisplay, rig: IRenderedRig) {
443444
uuid: display.uuid,
444445
parent: parentId,
445446
item: display.item,
447+
itme_display: display.itemDisplay,
446448
base_scale: 1,
447449
config: display.config,
448450
default_transform: {} as INodeTransform,

0 commit comments

Comments
 (0)