#Convert melee weapon attacks to different damage type (for use with Alembic)

54 messages · Page 1 of 1 (latest)

timid spindle
#

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");
})

https://github.com/FoundryMC/Alembic/wiki

#

Slight correction, "Example Damage" would benefit from sharpness but thats about it, but it would not be the correct damage type. Items with a non "Damage" stat also cannot deal crit damage or be buffed by any sort of statistic that is not "+Example Damage" which considering the point of alembic is mostly elemental based, I am not surprised that it is this way. I hope alembic grows to be a bigger and even more in depth mod and I know it will be, in the mean time, this script serves as a bridge to what will be possible in the future for the mod.

timid spindle
#

Another slight correction, the script does not need the throttle at all, I used that in testing to make testing easier, however it is pretty useless since the source null check and player check resolve any loops

#

Thanks to cadentem for pointing that out, you can use throttle if you would like to make a cooldown on the conversion or insert other purposes, you would need to put it after the check for player so that other entities taking damage wouldn't mess with the throttle

timid spindle
#

script is still w.i.p lmao, without throttle at all the script will loop and eventually just null and won't work, setting throttle to 1 fixes the loop and should (almost) never cause any problems, especially putting the throttle after checking if the damage comes from a player rather than another entity.

#

Hopefully that was the last edit to the script, this script also works with bows and likely other ranged weapons which is extremely nice. It should work 99.99% of the time, only time it might not convert properly is if you and another player attack an entity in the exact same tick with the same damage type tag on your weapon, so it's basically fullproof heh obviously open to optimizations or potential oversights

timid spindle
#

Throttle is now gone. Forever this time. It should be 100% now

#

Cadentem is the goat

fallow hornet
#

btw I don't know what I am talking about but would it not be easier to just give the weapons the alembic damage attribute ??

timid spindle
#

So in theory yes, but the issue comes when the damage doesn't calculate the same due to it not being the normal "Damage" in minecraft

#

Sharpness DOES affect the weapons damage however it isn't converted to "Arcane Damage" or whatever you may have on the weapon

#

Jump critical pretty much is useless as well with the damage attributes, and any other type of damage amplifier from mods, you may deal extra damage but it won't be the damage type on the weapon

#

So this solves that by converting the damage AFTER vanilla damage calculations and then it will deal any extra damage based on entity stats

fallow hornet
#

I see, tbh I just thought that that problem was only present for me cus the devs told me that it is not normal because alembic uses attribute lib's damage calculations which take into account crits

#

And also I think that "Lh's mirical road" mod's crits work with alembic, the only one I have not tested yet is "Passive Skill Tree"s crits and if those don't work then I will have to eather drop the elemental Idea or make a kjs attribute with a custom damage type (I hope it does not come down to that)

timid spindle
#

If they say that it takes into account attributelib stuff then it isn't working, because I was just extensively testing damage calculation for the scripts above last night and armor pierce does not factor in

timid spindle
#

Still doing testing as I keep noticing things aren't working correctly, and I can't tell if it is me or alembic

tawdry schooner
#

I think source.getType()!=meleeattack return would be much better. But how to judge it's melee attack or not will be a new issue then.

timid spindle
#

i use the (source.getType() == 'ranThru') to see if the damage dealt to the entity was from post conversion to prevent loops

timid spindle
#

yea even if I use a normal unmodified weapon that deals physical damage it cannot crit at all

#

it says it does but it deal no extra damage

timid spindle
#

so currently as far as I am concerned this script actually doesn't really work right now, from what I can tell it isn't changing the damage correctly in the first place due to, idk honestly, alembic is extremely unique but I don't think it currently works well enough to do what I am trying to do, I thought it was working but I figured out what was really happening the whole time, it was actually getting the damage type that the entity deals and is dealing that type of damage, I know how it was doing that and tried messing with the damageSource parameters but it kept doubling the damage and just yeilding mixed results, so until they fix the issues with melee damage not factoring attributeslib things properly this will be non-functional, it IS technically better than not using it since you can crit and use sharpness ect with your damage type, but you cannot do multiple types yet.

timid spindle
#

I FIXED IT ALL FOR REAL THIS TIME I AM SO PROUD

// Slash Damage
PlayerEvents.tick(event => {
    let armorPierce = event.player.getAttributeTotalValue('attributeslib:armor_pierce')
    event.entity.persistentData.armorPierce = armorPierce
})

EntityEvents.hurt(event => {
    const { amount, source: { actual }, player, source, entity } = event
    if (entity.level.clientSide) return
    if (source.actual == null) return
    if (source.getType() == 'slashBits') return
    if (source.getType() != 'player') return
    if(actual.isPlayer && actual.mainHandItem.hasTag("combat:slash_damage")) {
        let armorCoverPercentage = entity.getArmorValue()
        let pierce = actual.persistentData.armorPierce
        console.log(armorCoverPercentage)
        const damageSourceSlash = getDamageSource(entity.getLevel(), "kubejs:slash_damage", null, actual)
        if (armorCoverPercentage - pierce < 0) {
            entity.attack(damageSourceSlash, event.damage)
            actual.sendSystemMessage('Slash!')
            event.cancel()
        }
        else {
        entity.attack(damageSourceThrust, event.damage * (1 - (((armorCoverPercentage - pierce) + (event.damage * 4) / 100) / 50)))
        actual.sendSystemMessage('Slash!')
        event.cancel()
        }   
    }
})
#

fully working script (I still cannot believe setting the value in the damageSource to null actually worked and fixed the key issue I was having)

#

I did have to manually calculate armor and armor piercing for this to work, so the armor damage reduction isnt exact and doesn't factor armor toughness (honestly armor toughness is wack) but it is close enough to the damage values it should be and it works so I can rest easy

timid spindle
#

now punishes higher damage amounts more than normal to compensate for armor toughness not being in the calculation, and since this only affects damage to mobs, its good to make it a lil harder

tawdry schooner
#

It might be better to support Damage Type Change through modding, or more specifically, by using mixins. I will try to figure out how to achieve this.

timid spindle
#

unsure, the script now looks like this after I manually made all the enchantment calculation and damage calculation for different interactions in my modpack so thats cool

tawdry schooner
#

By the way, thank you for letting me know Alembic; this mod is truly epic! I might find a way to create a Kjs addon for modifying entitie's damage type through mixin for serving this mod.

polar reef
#

You're a freakin legend, thank you for this!

summer oak
#

@timid spindle did you ever get crits working again?

timid spindle
#

Well yes but also no. Yes as in I scripted it to work in this, no as in, alembic had no intention of making it work by default, the intent is for the dev themselves to have free reign over what their damage type does and how it interacts with the game

summer oak
timid spindle
#

In my case, jump criticals aren't possible in the modpack (sort of). Epic fight handles most of the melee interactions so you can still land a "jump crit" it's just considered a jump attack in epic fight. As far as stat wise, when the player attacks with a weapon, before damage is dealt it'll check the players crit chance and then roll for a potential crit

#

Alembics intention that they don't exactly state is that the damage type you add with alembic is intended to be blank and not impacted by pre existing mods stats and such, meaning they want you to incorporate your own "critical damage" and other stats

#

They want you to have complete control over damage as a whole

summer oak
summer oak
#

its a chinese rpg leveling mod

timid spindle
#

The honest answer when it comes to alembic is basically, you are likely gonna have to do absolutely everything yourself in terms of making whatever content you have compatible with alembic

#

I've had to do an immense amount of work on solely making everything work with the alembic damage types I have made

summer oak
#

yeah ive seen some other valiant ones trying to do their custom damage types

timid spindle
#

I've found great success so far, as long as you go into it understanding how much work you as the dev have to do to make everything work you'll come out ok

summer oak
#

i dont mind putting in work, i unified all the damage types to alembic except for an specific one

#

from eeabs mobs

#

it causes a crash

timid spindle
#

I overcomplicated things by doing this whole physical damage splitting, but it's been a blessing I'm disguise

summer oak
#

piercing blunt and slashing right

timid spindle
#

Essentially yes

summer oak
#

i left it at phys and the other 3 elements

#

basically just diablo

timid spindle
#

The way I did it has forced me to recreate basically every possible interaction weapons can have with mobs and such, including I will have to recreate apotheosis interactions, special weapon abilities from other mods, basically anything that happens when you hit a mob I have to remake

summer oak