diff --git a/src/main/java/com/hollingsworth/arsnouveau/api/spell/SpellContext.java b/src/main/java/com/hollingsworth/arsnouveau/api/spell/SpellContext.java index d0de92bbd..1117d064b 100644 --- a/src/main/java/com/hollingsworth/arsnouveau/api/spell/SpellContext.java +++ b/src/main/java/com/hollingsworth/arsnouveau/api/spell/SpellContext.java @@ -98,7 +98,10 @@ public SpellContext popContext(){ } } setCanceled(true); - return this; + //todo: feel free to discard the changes in this file if it conflicts with the other PR + //I only changed this to prevent a stack overflow from it being it's own parent + //but PLEASE PLEASE PLEASE use the other better PR which supports filters and stuff + return this.clone().withSpell(this.getRemainingSpell()); } public boolean hasNextPart() { diff --git a/src/main/java/com/hollingsworth/arsnouveau/common/spell/effect/EffectKnockback.java b/src/main/java/com/hollingsworth/arsnouveau/common/spell/effect/EffectKnockback.java index 4920d54c9..bd8ce3aa0 100644 --- a/src/main/java/com/hollingsworth/arsnouveau/common/spell/effect/EffectKnockback.java +++ b/src/main/java/com/hollingsworth/arsnouveau/common/spell/effect/EffectKnockback.java @@ -30,9 +30,9 @@ private EffectKnockback() { @Override public void onResolveEntity(EntityHitResult rayTraceResult, Level world, @NotNull LivingEntity shooter, SpellStats spellStats, SpellContext spellContext, SpellResolver resolver) { - float strength = (float) (GENERIC_DOUBLE.get() + AMP_VALUE.get() * spellStats.getAmpMultiplier()); - knockback(rayTraceResult.getEntity(), shooter, strength); + Vec3 fromPosition = spellStats.hasBuff(AugmentExtract.INSTANCE) ? shooter.position : previousPosition(resolver); + knockback(rayTraceResult.getEntity(), fromPosition, strength); rayTraceResult.getEntity().hurtMarked = true; } @@ -42,20 +42,36 @@ public void onResolveBlock(BlockHitResult rayTraceResult, Level world, @NotNull if (spellStats.isSensitive()) return; List posList = SpellUtil.calcAOEBlocks(shooter, rayTraceResult.getBlockPos(), rayTraceResult, spellStats); float strength = (float) (GENERIC_DOUBLE.get() + AMP_VALUE.get() * spellStats.getAmpMultiplier()); + Vec3 fromPosition = spellStats.hasBuff(AugmentExtract.INSTANCE) ? shooter.position : previousPosition(resolver); for (BlockPos p : posList) { EnchantedFallingBlock fallingBlock = EnchantedFallingBlock.fall(world, p, shooter, spellContext, resolver, spellStats); if (fallingBlock != null) { - knockback(fallingBlock, shooter, strength); + knockback(fallingBlock, fromPosition, strength); ShapersFocus.tryPropagateEntitySpell(fallingBlock, world, shooter, spellContext, resolver); } } } + public Vec3 previousPosition(SpellResolver resolver){ + if(resolver.previousResolver != null){ + return resolver.previousResolver.hitResult.getLocation(); + } + return resolver.spellContext.getUnwrappedCaster().position(); + } + + + @Deprecated public void knockback(Entity target, LivingEntity shooter, float strength) { knockback(target, strength, Mth.sin(shooter.yRot * ((float) Math.PI / 180F)), -Mth.cos(shooter.yRot * ((float) Math.PI / 180F))); } + public void knockback(Entity target, Vec3 fromPos, float strength) { + Vec3 diff = fromPos.subtract(target.position).normalize(); + knockback(target, strength, diff.x, diff.z); + } + + public void knockback(Entity entity, double strength, double xRatio, double zRatio) { if (entity instanceof LivingEntity living) strength *= 1.0D - living.getAttributeValue(Attributes.KNOCKBACK_RESISTANCE); @@ -82,12 +98,12 @@ public int getDefaultManaCost() { @NotNull @Override public Set getCompatibleAugments() { - return augmentSetOf(AugmentAmplify.INSTANCE, AugmentDampen.INSTANCE, AugmentAOE.INSTANCE, AugmentPierce.INSTANCE, AugmentSensitive.INSTANCE); + return augmentSetOf(AugmentAmplify.INSTANCE, AugmentDampen.INSTANCE, AugmentAOE.INSTANCE, AugmentPierce.INSTANCE, AugmentSensitive.INSTANCE, AugmentExtract.INSTANCE); } @Override public String getBookDescription() { - return "Knocks a target or block away a short distance from the caster. Sensitive will stop this spell from launching blocks."; + return "Knocks a target or block away a short distance from the spell. Sensitive will stop this spell from launching blocks. Extract will make always knockback from the caster instead. "; } @NotNull