Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Knockback rework #1183

Open
wants to merge 1 commit into
base: demo-pop-context
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
Expand All @@ -42,20 +42,36 @@ public void onResolveBlock(BlockHitResult rayTraceResult, Level world, @NotNull
if (spellStats.isSensitive()) return;
List<BlockPos> 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);
Expand All @@ -82,12 +98,12 @@ public int getDefaultManaCost() {
@NotNull
@Override
public Set<AbstractAugment> 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
Expand Down