Skip to content

Commit

Permalink
Read CHANGES.md
Browse files Browse the repository at this point in the history
  • Loading branch information
RadonCoding committed Nov 23, 2023
1 parent e4d4346 commit 451d459
Showing 1 changed file with 61 additions and 46 deletions.
107 changes: 61 additions & 46 deletions src/main/java/radon/jujutsu_kaisen/ability/misc/DivergentFist.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.PathfinderMob;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.event.entity.living.LivingDamageEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import org.jetbrains.annotations.Nullable;
import radon.jujutsu_kaisen.JujutsuKaisen;
import radon.jujutsu_kaisen.ability.AbilityDisplayInfo;
import radon.jujutsu_kaisen.ability.JJKAbilities;
import radon.jujutsu_kaisen.ability.MenuType;
Expand All @@ -30,13 +25,14 @@
import radon.jujutsu_kaisen.damage.JJKDamageSources;
import radon.jujutsu_kaisen.util.HelperMethods;

public class DivergentFist extends Ability implements Ability.IToggled {
public class DivergentFist extends Ability {
private static final float DAMAGE = 10.0F;
private static final double RANGE = 3.0D;
private static final double LAUNCH_POWER = 5.0D;

@Override
public boolean shouldTrigger(PathfinderMob owner, @Nullable LivingEntity target) {
return target != null && owner.distanceTo(target) < 5.0D;
return target != null;
}

@Override
Expand All @@ -46,7 +42,14 @@ public boolean isTechnique() {

@Override
public ActivationType getActivationType(LivingEntity owner) {
return ActivationType.TOGGLED;
return ActivationType.INSTANT;
}

private @Nullable Entity getTarget(LivingEntity owner) {
if (HelperMethods.getLookAtHit(owner, RANGE) instanceof EntityHitResult hit) {
return hit.getEntity();
}
return null;
}

@Override
Expand All @@ -73,50 +76,37 @@ public int getPointsCost() {

@Override
public void run(LivingEntity owner) {
if (owner.level().isClientSide) return;

}

@Override
public float getCost(LivingEntity owner) {
return 1.0F;
}

@Override
public void onEnabled(LivingEntity owner) {

}

@Override
public void onDisabled(LivingEntity owner) {

}
Entity target = this.getTarget(owner);

@Mod.EventBusSubscriber(modid = JujutsuKaisen.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE)
public static class ForgeEvents {
@SubscribeEvent
public static void onLivingDamage(LivingDamageEvent event) {
DamageSource source = event.getSource();
if (!(source.getEntity() instanceof LivingEntity attacker)) return;
if (target != null) {
ISorcererData cap = owner.getCapability(SorcererDataHandler.INSTANCE).resolve().orElseThrow();

if (attacker.level().isClientSide) return;
owner.swing(InteractionHand.MAIN_HAND);

LivingEntity victim = event.getEntity();
if (owner instanceof Player player) {
player.attack(target);
} else {
owner.doHurtTarget(target);
}
target.invulnerableTime = 0;

ISorcererData cap = attacker.getCapability(SorcererDataHandler.INSTANCE).resolve().orElseThrow();
Vec3 look = owner.getLookAngle();

Vec3 look = attacker.getLookAngle();
float power = this.getPower(owner);

cap.delayTickEvent(() -> {
attacker.swing(InteractionHand.MAIN_HAND, true);
owner.swing(InteractionHand.MAIN_HAND, true);

if (attacker instanceof Player player) {
player.attack(victim);
if (owner instanceof Player player) {
player.attack(target);
} else {
attacker.doHurtTarget(victim);
owner.doHurtTarget(target);
}
victim.invulnerableTime = 0;
target.invulnerableTime = 0;

Vec3 pos = victim.position().add(0.0D, victim.getBbHeight() / 2.0F, 0.0D);
Vec3 pos = target.position().add(0.0D, target.getBbHeight() / 2.0F, 0.0D);

for (int i = 0; i < 96; i++) {
double theta = HelperMethods.RANDOM.nextDouble() * 2 * Math.PI;
Expand All @@ -127,18 +117,43 @@ public static void onLivingDamage(LivingDamageEvent event) {
double z = r * Math.cos(phi);
Vec3 speed = look.add(x, y, z);
Vec3 offset = pos.add(look);
((ServerLevel) victim.level()).sendParticles(new CursedEnergyParticle.CursedEnergyParticleOptions(ParticleColors.getCursedEnergyColor(attacker), attacker.getBbWidth(),
((ServerLevel) target.level()).sendParticles(new CursedEnergyParticle.CursedEnergyParticleOptions(ParticleColors.getCursedEnergyColor(owner), owner.getBbWidth(),
0.2F, 8), offset.x(), offset.y(), offset.z(), 0, speed.x(), speed.y(), speed.z(), 1.0D);
}

if (victim.hurt(JJKDamageSources.jujutsuAttack(attacker, JJKAbilities.DIVERGENT_FIST.get()), DAMAGE * Ability.getPower(JJKAbilities.DIVERGENT_FIST.get(), attacker))) {
((ServerLevel) victim.level()).sendParticles(ParticleTypes.EXPLOSION, pos.x(), pos.y(), pos.z(), 0, 1.0D, 0.0D, 0.0D, 1.0D);
victim.level().playSound(null, pos.x(), pos.y(), pos.z(), SoundEvents.GENERIC_EXPLODE, SoundSource.MASTER, 1.0F, 1.0F);
if (target.hurt(JJKDamageSources.jujutsuAttack(owner, this), DAMAGE * this.getPower(owner))) {
((ServerLevel) target.level()).sendParticles(ParticleTypes.EXPLOSION, pos.x(), pos.y(), pos.z(), 0, 1.0D, 0.0D, 0.0D, 1.0D);
target.level().playSound(null, pos.x(), pos.y(), pos.z(), SoundEvents.GENERIC_EXPLODE, SoundSource.MASTER, 1.0F, 1.0F);

victim.setDeltaMovement(look.scale(LAUNCH_POWER));
victim.hurtMarked = true;
target.setDeltaMovement(look.scale(LAUNCH_POWER));
target.hurtMarked = true;
}
}, 5);
}
}

@Override
public Status checkTriggerable(LivingEntity owner) {
Entity target = this.getTarget(owner);

if (target == null) {
return Status.FAILURE;
}
return super.checkTriggerable(owner);
}

@Override
public float getCost(LivingEntity owner) {
return 50.0F;
}

@Override
public int getCooldown() {
return 10 * 20;
}

@Override
public MenuType getMenuType() {
return MenuType.SCROLL;
}
}

0 comments on commit 451d459

Please sign in to comment.