#edit blockstate/property of existing block in the world

44 messages · Page 1 of 1 (latest)

crisp kelp
#

BlockEvents.rightClicked(event => {
    const heldItem = event.player.getMainHandItem()
    const blockId=event.block.id

    if (blockId === 'artifality:upgrading_pedestal') {
        for (let [a, b] in upgradingPedestalUpgrades) {
            if (heldItem.id != a)
                return
            if (event.block.properties.charges != b.charges)
                return
            if (heldItem.nbt.artifactTier >= b.tier)
                continue
            heldItem.nbt.artifactTier=b.charges
            event.player.mainHandItem=heldItem.withNBT(b.nbt);
            
        }
    }
    return
});
blissful ermineBOT
#

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

crisp kelp
#

at the bottom i need to set the block properties
i tried with

event.block.properties.charges=0

but it doesn't change

rotund inlet
#

you have to use

event.block.set(block.id, {age:'0'})
crisp kelp
#

@rotund inlet would this work with shulkers or would it overwrite the contents

crisp kelp
#

and also it seems to not work for me?

rotund inlet
rotund inlet
#

i had destructered everything and forgot to place the event back in that part

crisp kelp
#

oh sry for late response

#

il get on my computer

#
    if (blockId === 'artifality:upgrading_pedestal') {
        for (let [a, b] in upgradingPedestalUpgrades) {
            if (heldItem.id != a)
                continue
            if (event.block.properties.charges != b.charges)
                continue
            if (b.tier!=0) {
                if (heldItem.nbt.artifactTier >= b.tier)
                    continue

                heldItem.nbt.artifactTier=b.charges
            }
            //event.player.tell(heldItem.nbt)
            event.player.mainHandItem=heldItem.withNBT(b.nbt);
            event.block.set(blockId,{charges:0})
            //change tooltip if its not auto
            //event.player.tell(heldItem.nbt)
            break
        }
    }
#

i also tried some testing with shulker boxes but it seems it doesn't change the properties

rotund inlet
#

do you get any error?

crisp kelp
#

the block.set works it just doesn't pass the properties

#

i can check again in the log to see if it errors

rotund inlet
#

try {charges:'0'} lol

crisp kelp
#

wow

#

that worked

#

i saw that in log there was some shenangins about the value not working

#

and for some reason that works

#

neat

#

well i need some help with something else then

rotund inlet
#

yeah, sometimes you have this simples things that makes a lot of difference, lol

crisp kelp
#

nbt makes no sense lol

#

well how would i make something like this work with shulker boxes

rotund inlet
crisp kelp
#

i was looking into making player-only shulker boxes

#

by storing the uuid in the properties then checking when shulker boxes are interacted with then cancelling the event if its not the same name

#

would it be possible to get the placed shulker boxes nbt then in the same way set the block then re-add the nbt

rotund inlet
#

you want the player that placed the shulker box be only one that can open it?

crisp kelp
#

yeah

rotund inlet
crisp kelp
#

well i tried event.block.set('minecraft:shulker_box',{uuidLock:uuid}) with shulker boxes but it wipes the contents

rotund inlet
crisp kelp
#

so how would i transfer the nbt

#

id guess getting the nbt beforehand then just setting it after the set

#

but maybe there is a better method off block for this

rotund inlet
#

i will test somethings here, idk if you can put random nbt data to existing blocks. you can edit them but adding something that doesn't exist i'm not sure

crisp kelp
#

well in theory shulker boxes should be placed with the prerequisite nbt data for the inventory

#

could edit that

rotund inlet
#

okay so you cant add nbt to block entities like that

#

i'm trying to save the block pos in the player presistent data and than read that to open or not the shulker box