I'm currently trying to replicate what someone did for a modjam (https://streamable.com/yn7gnb) to experiment with custom item actions, and I can't seem to find a way to correctly deviate the positions given, given that I can't get the block result of a raytrace. rayTrace(10).block is undefined/null.
onEvent('item.registry', event => {
event.create('observing_eye').displayName('Observing Eye').useAnimation('bow').use((level, player, hand) => {
player.setMotion(0, 0, 0)
return true
}).useDuration(itemstack => {
return 20
}).finishUsing((itemstack, level, entity) => {
global.observingEyeFunc(itemstack, level, entity)
return itemstack
})
})
global.observingEyeFunc = (itemstack, level, entity) => {
entity.addItemCooldown('kubejs:observing_eye', 100)
let pitch = entity.getPitch()
let yaw = entity.getYaw()
let raytrace = entity.rayTrace(10)
//use entity.addMotion() in the direction of the pitch and yaw
function getDirection(pitch, yaw) {
//get deviation of raytraced block from current position
let x = raytrace.block.x - entity.block.x
return [x, y, z]
}
let direction = getDirection(pitch, yaw)
entity.addMotion(direction[0], direction[1], direction[2])
return itemstack
}