KubeJS (Old)

KubeJS (Old)

3M Downloads

event.attack seems not work in 1.18 fabric (kubejs-fabric-1800.4.0-build.223)

biryeongtrain opened this issue ยท 1 comments

commented

Hi. first, thank you for make this awesome mod!
my code worked in 1.17 and 1.16(kubejs-fabric-1605.3.19-build.218)

is event name changed or is this a bug?

here's code that i used.

onEvent('entity.attack',
event => { 

  try {
    if(event.source.actual.isPlayer() && event.source.actual.getMainHandItem().id == 'minecraft:stick') {
        event.cancel()
        let targetEntity = event.getEntity();
        console.log("Mob's ID : " + targetEntity);
        console.log(targetEntity.persistentData.defendElement)
        if(targetEntity.persistentData.defendElement == undefined) {

            targetEntity.persistentData.defendElement = "none"
            console.log("Player's Element is now None.")

        }
        else if(targetEntity.persistentData.defendElement = "none") {
            console.log("Player's Element = None");
        }
    }
  } catch(e){
    //
  }
} 
)

here's log when does work in 1.16(kubejs-fabric-1605.3.19-build.218)

[19:38:10] [Server thread/INFO]: server_scripts:script.js:90: Mob's ID : Pig-fb8074a1-4ea3-4150-acb8-ae6a292a84d0
[19:38:10] [Server thread/INFO]: server_scripts:script.js:91: undefined
[19:38:10] [Server thread/INFO]: server_scripts:script.js:95: Player's Element is now None.

Thank you!

commented

o/ "entity.attack" was renamed to "entity.hurt" somewhere down the line to describe its actual purpose a little more closely, and the old event id will no longer work in 1.18 ^^