Skip to content

Commit 823caf2

Browse files
committed
Fix NBT merging for locators and cameras
1 parent 595bd67 commit 823caf2

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

exporters/datapackExporter/exporter/gen/functions.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,16 @@ function generateLocatorPassenger(
125125
)
126126
)
127127

128-
const locatorEntityNbt = (deepslate.NbtTag.fromString(locator.nbt) as NbtCompound)
129-
.set(
130-
'Tags',
131-
new deepslate.NbtList([
132-
new deepslate.NbtString(G.TAGS.locatorEntity),
133-
new deepslate.NbtString(formatStr(G.TAGS.namedLocatorEntity, [locator.name])),
134-
new deepslate.NbtString(G.TAGS.new),
135-
])
136-
)
137-
.set(
128+
const locatorEntityNbt = deepslate.NbtTag.fromString(locator.nbt) as NbtCompound
129+
if (!locatorEntityNbt.get('Tags')) locatorEntityNbt.set('Tags', new deepslate.NbtList())
130+
const tags = locatorEntityNbt.get('Tags') as InstanceType<typeof deepslate.NbtList>
131+
132+
tags.add(new deepslate.NbtString(G.TAGS.locatorEntity))
133+
tags.add(new deepslate.NbtString(formatStr(G.TAGS.namedLocatorEntity, [locator.name])))
134+
tags.add(new deepslate.NbtString(G.TAGS.new))
135+
136+
if (!locatorEntityNbt.get('CustomName'))
137+
locatorEntityNbt.set(
138138
'CustomName',
139139
new deepslate.NbtString(
140140
new JsonText([
@@ -153,6 +153,7 @@ function generateLocatorPassenger(
153153
]).toString()
154154
)
155155
)
156+
156157
function locatorToString(node: AnimatedJava.IAnimationNode) {
157158
const pos = node.pos
158159
const euler = new THREE.Euler().setFromQuaternion(node.rot, 'YXZ')
@@ -238,16 +239,16 @@ function generateCameraPassenger(
238239
)
239240
)
240241

241-
const cameraNbt = (deepslate.NbtTag.fromString(camera.nbt) as NbtCompound)
242-
.set(
243-
'Tags',
244-
new deepslate.NbtList([
245-
new deepslate.NbtString(G.TAGS.cameraEntity),
246-
new deepslate.NbtString(formatStr(G.TAGS.namedCameraEntity, [camera.name])),
247-
new deepslate.NbtString(G.TAGS.new),
248-
])
249-
)
250-
.set(
242+
const cameraEntityNbt = deepslate.NbtTag.fromString(camera.nbt) as NbtCompound
243+
if (!cameraEntityNbt.get('Tags')) cameraEntityNbt.set('Tags', new deepslate.NbtList())
244+
const tags = cameraEntityNbt.get('Tags') as InstanceType<typeof deepslate.NbtList>
245+
246+
tags.add(new deepslate.NbtString(G.TAGS.cameraEntity))
247+
tags.add(new deepslate.NbtString(formatStr(G.TAGS.namedCameraEntity, [camera.name])))
248+
tags.add(new deepslate.NbtString(G.TAGS.new))
249+
250+
if (!cameraEntityNbt.get('CustomName'))
251+
cameraEntityNbt.set(
251252
'CustomName',
252253
new deepslate.NbtString(
253254
new JsonText([
@@ -258,14 +259,15 @@ function generateCameraPassenger(
258259
'',
259260
{ text: `${G.PROJECT_NAME}`, color: 'light_purple' },
260261
`.`,
261-
{ text: `camera`, color: 'white' },
262+
{ text: `cameraEntity`, color: 'white' },
262263
`[`,
263264
{ text: `${camera.name}`, color: 'yellow' },
264265
`]`,
265266
],
266267
]).toString()
267268
)
268269
)
270+
269271
function cameraToString(node: AnimatedJava.IAnimationNode) {
270272
const pos = node.pos
271273
const euler = new THREE.Euler().setFromQuaternion(node.rot, 'YXZ')
@@ -280,7 +282,7 @@ function generateCameraPassenger(
280282
// ANCHOR - function G.PROJECT_PATH/summon/camera_<camera_name>/as_origin
281283
.chainNewFile('as_origin.mcfunction', [
282284
// `say Camera Origin`,
283-
`summon ${camera.entity_type} ~ ~ ~ ${cameraNbt.toString()}`,
285+
`summon ${camera.entity_type} ~ ~ ~ ${cameraEntityNbt.toString()}`,
284286
`execute as @e[type=${camera.entity_type},tag=${formatStr(G.TAGS.namedCameraEntity, [
285287
camera.name,
286288
])},tag=${G.TAGS.new},limit=1,distance=..1] run function ${

0 commit comments

Comments
 (0)