With the mixin that KubeJS does on DamageSource, which adds actual, it seems the event doesn't recognize that source has that parameter, and therefore does not run the code at all because event.source.actual is null/undefined.
const $LivingEntity = java('net.minecraft.world.entity.LivingEntity')
const $EntityDamageSource = java('net.minecraft.world.damagesource.EntityDamageSource')
global.LivingAttackEventIndicator = function (/** @type {Internal.LivingAttackEvent} */ event) {
if (!event.source) return
if (!event.source.actual) return
if (!event.entity) return
if (!event.entity.asKJS().isPlayer()) return
if (Platform.isClientEnvironment()) return
event.setCanceled(true)
let entity = event.entity.asKJS()
let source = event.source.actual.asKJS()
source.playSound('paucal:pet.bwop', 1, 1.2)
entity.tell('test')
Utils.server.scheduleInTicks(2, cb => {
entity.tell('test2')
entity.attack(new $EntityDamageSource(event.source.toString(), source.minecraftEntity), event.amount)
})
}
onForgeEvent('net.minecraftforge.event.entity.living.LivingAttackEvent', event => {
global.LivingAttackEventIndicator(event)
})
My goal is to delay the attack of an entity on a player and indicate an attack before the damage goes through (therefore making PvE better).
