#Increasing attack damage upon killing certain entity

12 messages · Page 1 of 1 (latest)

twin python
#

My plan is to increase my sword's damage every time I kill a certain mob...

let $ItemAttributeModifierEvent = Java.loadClass("net.neoforged.neoforge.event.ItemAttributeModifierEvent");
[...]

let bonus = 0.5;
NativeEvents.onEvent($ItemAttributeModifierEvent, e => {
  let { itemStack } = e;
  let modifierId = itemStack.id + "_penguin_slayer";

  // e.addModifier("minecraft:generic.attack_damage", { id: modifierId, amount: bonus, operation: 'add_value'}, 'mainhand');
})

EntityEvents.death('livingthings:penguin', e => {
  let { source, entity, server } = e
  let killer = source.actual
  if (killer && killer.mainHandItem.id === 'owlery:joe_sword') {
      e.addModifier("minecraft:generic.attack_damage", { id: modifierId, amount: bonus, operation: 'add_value'}, 'mainhand');
  }
})

However, I can't call e.addModifier from EntityEvents.death obviously.
Also the modifierId has no way to transfer to EntityEvents.death too.
Is there other way to make the sword gain damage after killing mobs?

(My plan was to make the sword have a counter that it will increase the damage every 20 penguin kills, but first I want to figure out how to make the damage increase at all.)

untold condorBOT
#

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

hollow cliff
#

Why can’t you call it in the death event?

twin python
#

server.log:
[01:26:13] [ERROR] ! joesword.js#77: Error in 'EntityEvents.death': dev.latvian.mods.rhino.EcmaError: TypeError: Cannot find function addModifier in object dev.latvian.mods.kubejs.entity.LivingEntityDeathKubeEvent@a28b51d.

hollow cliff
#

You should be using kill.addModifier, not e.addModifier

#

Or you can add it to the item instead

twin python
#

killer:
[01:35:51] [ERROR] ! joesword.js#77: Error in 'EntityEvents.death': dev.latvian.mods.rhino.EcmaError: TypeError: Cannot find function addModifier in object ServerPlayer['krewetus'/103, l='ServerLevel[test]', x=-857.24, y=74.00, z=-543.50].

killer.mainHandItem:
[01:36:45] [ERROR] ! joesword.js#77: Error in 'EntityEvents.death': dev.latvian.mods.rhino.EcmaError: TypeError: Cannot find function addModifier in object 1 owlery:joe_sword.

#

hmm

#

maybe i should try making it an itemStack as above or something

hollow cliff
#

I would recommend probejs to get method info

twin python
#

Error in 'EntityEvents.death': dev.latvian.mods.rhino.EcmaError: TypeError: Cannot find function addModifier in object 1 owlery:joe_sword.

it still says "cant find function" in 'EntityEvents.death'

so trying to turn it into itemStack wouldnt do the trick

twin python
#

#1449215989714784478 <- New thread
Scratching this idea (for now).