I made this script to be able to convert an attack from (in this case a group of specific weapons) to a different damage type that would be handled by Alembic. For people who do not know what alembic is or how it works, it totally overhauls the damage type system allowing you to assign specific resistances and boosts to entities and convert existing damage types to alembic damage types. The basic functions of the mod are very useful for element type attacks and for adding attributes to your weapons and armors. While it is possible to change melee damage to an alembic damage type, it isn't very optimal in its current state. You either convert ALL physical damage to one alembic damage type (which is pointless because physical damage is an alembic type) or you change the actual damage on the weapon from "Damage" to "Example Damage" and that "Example Damage" does not get affected by most if not all normal damage buffs. This script solves that issue by allowing the damage to be calculated as vanilla damage fully and then switching it to a alembic damage so that it can be handled by the entity you attack! Note: on top of making the alembic damage type, you have to make a kubejs damage type that you will convert to the alembic damage type. (So it is kind of a double conversion lmao) for the alembic side of things if you are not familiar with alembic I suggest both the wiki and their discord. (linked at the bottom)
Server Script:
const $ResourceKey = Java.loadClass("net.minecraft.resources.ResourceKey")
const DAMAGE_TYPE = $ResourceKey.createRegistryKey("damage_type")
function getDamageSource(/** @type {Internal.Level}*/ level, /** @type {Internal.DamageType_}*/ damageType, projectile, thrower) {
const resourceKey = $ResourceKey.create(DAMAGE_TYPE, Utils.id(damageType))
const holder = level.registryAccess().registryOrThrow(DAMAGE_TYPE).getHolderOrThrow(resourceKey)
return new DamageSource(holder, projectile, thrower)
}
// Thrust Damage
EntityEvents.hurt(event => {
const { amount, source: { actual }, player, source, entity } = event
if (entity.level.clientSide) return;
if (source.actual == null) return
if (source.getType() == 'ranThru') return
if(actual.isPlayer && actual.mainHandItem.hasTag("combat:thrust_damage")) {
const damageSource = getDamageSource(entity.getLevel(), "kubejs:thrust_damage", entity, actual)
event.cancel
entity.attack(damageSource, event.damage);
}
})
Server Script:
ServerEvents.highPriorityData(event => {
event.addJson("kubejs:damage_type/thrust_damage", {
"effects": "freezing",
"exhaustion": 0.5,
"message_id": "ranThru",
"scaling": "when_caused_by_living_non_player"
})
})
Client Script:
ClientEvents.lang('en_us', (e) => {
e.add("death.attack.ranThru", "%1$s was ran thru by a pointy object");
})
obviously open to optimizations or potential oversights