#What is the function to edit nbt of a block entity in a level? Also, how do you add a new data tag?

86 messages · Page 1 of 1 (latest)

remote musk
#

As above, so below

Please help me out of this hell

blazing lavaBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

upbeat jasper
#

level.getBlock(pos).entityData / .mergeEntityData(nbt)

lost finch
#

oh right that's all from mc itself

upbeat jasper
#

nope

#

getBlock is KJS' class

lost finch
#

oh the BlockContainerJS stuff?

upbeat jasper
#

BlockContainerJS previously

#

LevelBlock now after my latest push in 1.21

lost finch
#

oh i see

remote musk
#

Sorry it's taking me so long

#

I'm being dumb

#
BlockEvents.rightClicked('kubejs:portal_totem', e => {
    e.level.getBlock(e.block.getPos()).entityData
    console.log(entityData)
})```
#

Server is hiting me with that [ERROR] ! gateway_block.js#3: Error in 'BlockEvents.rightClicked': ReferenceError: "entityData" is not defined.

lone rootBOT
#

Paste version of server.log from @remote musk

remote musk
#

WAIT

#

IM SO DUMB

#

fuckin ned a constant saOFDIHLAFG

#

dAMN

#
BlockEvents.rightClicked('kubejs:portal_totem', e => {
    let blockData = e.level.getBlock(e.block.getPos()).entityData =
    console.log(blockData)
})```
#

[INFO] gateway_block.js#2: undefined

upbeat jasper
#

whats the = for

#

at end

#

you are setting blockData to console.log

remote musk
#

Block registry:

StartupEvents.registry('block', e =>{
    e.create('portal_totem')
    .blockEntity(portalTotem =>{
      portalTotem.initialData('{active: 1}')
    })
  })```
remote musk
upbeat jasper
#

no

#

not printing

#

SETTING

remote musk
#

trying to see what it says

upbeat jasper
#

= at end

remote musk
#

I saw that

upbeat jasper
#

...do you understand why it shouldnt be like that

remote musk
#

Im about to remove it but my pc is giving me shit

remote musk
#

I know

#

It was not put there on purpose

#

was a typeo on my end which is my bad

#

again sorry for the wait, my gpu just hates modded mc

remote musk
#

we are so back

#

[INFO] gateway_block.js#4: {ForgeCaps:{},data:{active:1},id:"kubejs:portal_totem",placer:[I;748692735,826950754,-2105760280,107573356],x:-25,y:-60,z:58} [net.minecraft.nbt.CompoundTag]

#

Problably made another typo here

#
BlockEvents.rightClicked('kubejs:portal_totem', e => {
    let blockData = e.level.getBlock(e.block.getPos()).entityData
    blockData
    e.level.getBlock(e.block.getPos()).mergeEntityData({active: 100})
    console.log(blockData)
})```
#

Sorry if im not processing everything right

#

Im in a situation

lone rootBOT
#

Paste version of server.log from @remote musk

upbeat jasper
#

isnt active a boolean

#

so its either 0 or 1

#

actually its a byte so 100 should work

#

I suggest using string for nbt

#

so try .mergeEntityData('{active: 100b}')

remote musk
#

I mean, I've tried merge entity data before

#

Found it through probe

#

Couldn't get it to work, and it is still not working

#

Nothing interesting has changed in the logs from what I can tell

lone rootBOT
#

Paste version of server.log from @remote musk

remote musk
#
StartupEvents.registry('block', e =>{
    e.create('portal_totem')
    .blockEntity(portalTotem =>{
      portalTotem.initialData('{active: 1}')
    })
  })```
#

Maybe initial data is fucking with things

#

I dont know

remote musk
upbeat jasper
#

no initial data shouldnt change anything, weird

remote musk
#

Im gonna load this up in a new pack without any other mods or scripts

#

And if it doesn't work

#

Ill uuuuuh

#

idk

#

Yeah shit is still fucked

#

You know, at least me screaming your name (saying it in all caps) was validated

#

( In all seriousness, thank you for your help and making this tool but PLEASE set up a volunteer system for the documentation or something)

#

(ur great)

#

Okay, not even /data merge is editing this thing

#

Something is afoot

orchid wedge
#

something like this work for chests:

BlockEvents.rightClicked(e => {
    const {block} = e;
    if(e.hand == 'off_hand') return;

    e.server.tell(block.entityData)
    block.mergeEntityData({Items:[{Count:1,Slot:11,id:"minecraft:coal_ore"}]})
    e.server.tell(block.entityData)
})
remote musk
#

ayyyyyyy that worked

#

Now i need to just detect the numberg

orchid wedge
#

try this

block.entityData.data.active```
remote musk
#

also worked!

#

thanks for the help