Spartan Weaponry

Spartan Weaponry

34M Downloads

Trouble with Weapon Traits

minhtet-htoon opened this issue ยท 2 comments

commented

I'm trying to add a trait so that certain weapons will strike the hit entity with lightning. I did it using the same syntax I did in 1.12. Here is the script that I thought would add the trait. (Since I couldn't find a discord server or forum, I thought that this would be the best place to ask for help.)

package com.github.tharthar2.saf2021.integrations;


import com.oblivioussp.spartanweaponry.api.WeaponMaterial;
import com.oblivioussp.spartanweaponry.api.trait.WeaponTrait;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.LightningBoltEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;


public class LDS extends WeaponTrait {
    public LDS(String type, String modId, TraitQuality quality) {
        super(type, modId, quality);
    }

    public void onHitEntity(WeaponMaterial material, ItemStack stack, LivingEntity target,
                            LivingEntity attacker, Entity projectile) {
        boolean flag = true;
        if(attacker instanceof PlayerEntity){
            if(((PlayerEntity)attacker).swingProgress > 0.2){
                flag = false;
            }
        }
        if(!attacker.world.isRemote && flag){
            LightningBoltEntity lightningboltentity = EntityType.LIGHTNING_BOLT.create(target.world);
            lightningboltentity.moveForced(target.getPositionVec());
            if(!target.world.isRemote){
                target.world.addEntity(lightningboltentity);
            }
        }
        target.applyKnockback( 1F, attacker.getPosX() - target.getPosX(), attacker.getPosZ() - target.getPosZ());
    }
}
commented

Called the wrong method and I just realized my very dumb mistake

commented

Hello, would you happen to know where to edit existent weapon's trait?
like remove/add existent trait on existent weapon in the mod