#how would i make an item that runs /data modify on the clicked block?

39 messages · Page 1 of 1 (latest)

teal laurel
#

this is the code i have right now and it doesn't do anything

ItemEvents.rightClicked(event => {
  const { block, player } = event
  if (player.mainHandItem !== "gtceu:yellow_garnet_rod") return
  if (player.name !== "Thermgon") return

  event.cancel()
  event.server.runCommandSilent([
    `/data modify block ${block.pos.x} ${block.pos.y} ${block.pos.z}`,
    "recipeLogic.lastOriginRecipe.recipe.duration 1"
  ].join(" "))
})
spare frostBOT
#

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

teal laurel
#

and i also want it to not open the block if it's openable

#

that's why i tried putting event.cancel there

drowsy condor
#

I think the proper event is BlockEvents.rightClicked, not ItemEvents.rightClicked

teal laurel
#

uhh huh hold on

#

nah still doesn't work

#

oh wait should i run event.cancel after the command

drowsy condor
#

Also, I think there's a way to edit the block's NBT directly without using commands, but I am experimenting with that

teal laurel
#

o

drowsy condor
#

So hold on

#

So far I only know that I can read block's NBT data by using event.block.entityData:

  BlockEvents.rightClicked((event) => {
    if (event.block.id == "minecraft:chest") {
      // @ts-expect-error
      event.player.tell(Text.of(event.block.entityData))
    }
  })
teal laurel
#

uh

#

i mean /data get block can also do that but it's color coded

drowsy condor
#

Yeah, but I'm investigating whether you can do that without using commands, these should be used as a last resort

teal laurel
#

ah

#

why?

drowsy condor
#

Try right-clicking the machine with this event:

BlockEvents.rightClicked((event) => {
  event.player.tell(Text.of(event.block.entity))
})

and tell what it returns

#

For example: Right-clicking the chest will print this in chat, which contains the block entity's class name

#

Maybe there's a useful method on that class which will do what you want

teal laurel
drowsy condor
teal laurel
#

yeah i don't think i see anything that can replicate what i'm doing

drowsy condor
#

You can call anything from:

  • MetaMachineBlockEntity
  • BlockEntity and its ancestors
  • IMachineBlockEntity and its ancestors
#

That's quite a big inheritance chain, so you might find something that works

teal laurel
#

uh yeah idk

#

the main issue is still here tho

#

why did i think player.mainHandItem is a string bro

#

ok it still doesn't work

#

waitt

#

it was thje name check

#

why doesn't that work

#

the command was wrong as well 🤦‍♂️

teal laurel
#

@drowsy condor did you figure out how to set entity data without commands

#
BlockEvents.rightClicked(event => {
  const { block, player, server } = event
  if (player.mainHandItem.id !== "gtceu:yellow_garnet_rod") return
  if (player.uuid.toString() !== "0d3ab088-2ee6-438c-ba65-0c9f6e30f7c3") return

  const setBlockValue = (valuePath, newValue) => {
    const commandPrefix = `/data modify block ${block.pos.x} ${block.pos.y} ${block.pos.z}`
    server.runCommandSilent(`${commandPrefix} ${valuePath} set value ${newValue}`)
  }

  setBlockValue("recipeLogic.lastOriginRecipe.recipe.duration", 1)
  setBlockValue("recipeLogic.progress", block.entityData.recipeLogic.duration)
  event.cancel()
})

this works but i'll replace it if you have another solution without running commands

drowsy condor
#

Nope, I didn't