#Right Click Apply on Block with Item in Hand to change its form. Help.

32 messages · Page 1 of 1 (latest)

jaunty flare
#

I want a Item in my Main Hand to be able to be right clicked on a Block, in order to change it..
i have this script:

  const player = event.player
  const item = player.mainHandItem
  
  
  if (item.id == 'kubejs:end_portal_frame_top') {
  event.block.set('minecraft:end_portal_frame')
  }
})```

Wont work 🙁
fierce skyBOT
#

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

jaunty flare
#

(Ment to change the block with the item, if i sounded confusing (block transform)

dry wraith
#

The item (and the hand used) to interact with the block is already provided by the event

const {block, item, player} = event //shortcut for declaring multiple variables that already exist in X
if (item == 'kubejs:end_portal_frame_top'){ //no need to use ID, KubeJS provides easy equals check
  block.set('minecraft:end_portal_frame')
  if(!player.isCreative())
    item.count--
  player.swing() //makes the hand swing as if an item was used
}
jaunty flare
dry wraith
#
BlockEvents.rightClicked('minecraft:endstone', event => {
    const {block, item, player} = event 
    player.tell(`Right-clicked ${block} with ${item}`)
    if (item == 'kubejs:end_portal_frame_top') {
        event.block.set('minecraft:end_portal_frame')
        
        if(!player.isCreative())
            item.count--

        player.swing() 
    }
})

also check logs to see if there's any issues
Oh and this is in a server_scripts file yes?

jaunty flare
keen shadowBOT
#

Paste version of server.log from @jaunty flare

dry wraith
#

ah

#

Don't have minecraft running atm, but check the mod:id of end stone
It should likely be minecraft:end_stone, not minecraft:endstone

jaunty flare
#

yeah... makes sense

#

just.... one problem..
when i create the portal, the portal FRAMES are not in the right direction, so the portal wont activate when i place in the eyes

dry wraith
#

/kjs hand will output into chat the held item's ID, and any and all possible tags etc into chat
All of them can be clicked to copy that string to clipboard, so you can easily ctrl+v into your script

dry wraith
#
block.set('minecraft:end_portal_frame[facing=north]')

You'll have to do some maths and calculate which facing (north/south/west/east) you need to place them, oooor, you can add a tooltip to the item, stating that players must use the frame top on a cardinal side (N/S/W/E), which allows you to reference that direction from the rightClicked event through event.facing
From that, you can either set the end stone with the same facing, or if needed use the opposite facing using event.facing.opposite
You may also want to disable using the frame top if the right-clicked side is Up/Down

#

Easy way to implement the facing without 4 separate if-statements et similar, is to use template literals, eg backticks, like I did in that player.tell snippet earlier

block.set(`minecraft:end_portal_frame[facing=${event.facing}]`)

This will place the block facing the player
If you need the opposite, the event.facing.opposite will have the block be placed facing away from you

jaunty flare
#

oh... wait

#

sec..

#

edited

dry wraith
#

yeah, that should alter the portal frame block's facing based on which side you clicked

jaunty flare
#

ill try that in a sec

#

now it wont let me place them anymore, at all

#

ok, ok... me beeing me, means stupid... "endstone"

#

instead of end_stone

#

yeah no, still wont

#

they are ALL facing north... yea

jaunty flare
#

oh wait no... nothing, it stopped

#

and i cannot right click it