trying to make a script that empties an entities hand and summons an item entity that flys towards the player, but for some reason I just crash everytime it runs. any help would be amazing
StartupEvents.registry('palladium:abilities', (EventHandler) => {
EventHandler
.create('gravestone:magnetic_disarm')
.icon(palladium.createItemIcon('minecraft:blaze_rod'))
.documentationDescription('Disarming ability, nuff said - VenWhoVian')
.firstTick((entity, enabled) => {
if (enabled) {
let targets = entity.level.getEntities(entity, AABB.ofSize(entity.position(), 10, 10, 10)).toArray();
targets.forEach(otherEntity => {
if (otherEntity.mainHandItem && otherEntity.mainHandItem.id) { // Added null and id check
let item = otherEntity.block.createEntity("minecraft:item");
item.mergeNbt({
Item: { id: otherEntity.mainHandItem.id, Count: 1 },
PickupDelay: 20
});
item.setPosition(otherEntity.x, otherEntity.y, otherEntity.z);
otherEntity.mainHandItem = "minecraft:air";
let direction = entity.position().subtract(item.position()).normalize();
item.setDeltaMovement(direction.x * 0.5, direction.y * 0.5, direction.z * 0.5);
}
});
}
});
});