Fixed catapult spell and fixed spells not being applied when a projectile hits something

This commit is contained in:
Sollace 2022-12-26 23:48:01 +01:00
parent 3c065ac097
commit 10758fc25d
2 changed files with 1 additions and 21 deletions

View file

@ -11,11 +11,9 @@ import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait;
import com.minelittlepony.unicopia.mixin.MixinFallingBlockEntity; import com.minelittlepony.unicopia.mixin.MixinFallingBlockEntity;
import com.minelittlepony.unicopia.projectile.MagicProjectileEntity; import com.minelittlepony.unicopia.projectile.MagicProjectileEntity;
import com.minelittlepony.unicopia.projectile.ProjectileDelegate; import com.minelittlepony.unicopia.projectile.ProjectileDelegate;
import com.minelittlepony.unicopia.util.Trace;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.FallingBlockEntity; import net.minecraft.entity.FallingBlockEntity;
import net.minecraft.predicate.entity.EntityPredicates;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.EntityHitResult; import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -60,7 +58,7 @@ public class CatapultSpell extends AbstractSpell implements ProjectileDelegate.B
return true; return true;
} }
getTarget(caster, e -> apply(caster, e)); getTypeAndTraits().create().toThrowable().throwProjectile(caster);
return false; return false;
} }
@ -77,23 +75,6 @@ public class CatapultSpell extends AbstractSpell implements ProjectileDelegate.B
} }
} }
protected void getTarget(Caster<?> caster, Consumer<Entity> apply) {
if (caster.isClient()) {
return;
}
double maxDistance = 2 + (getTraits().get(Trait.FOCUS) - 50) * 8;
Trace trace = Trace.create(caster.asEntity(), maxDistance, 1, EntityPredicates.EXCEPT_SPECTATOR);
trace.getEntity().ifPresentOrElse(apply, () -> {
trace.ifBlock(pos -> {
if (caster.canModifyAt(pos)) {
createBlockEntity(caster.asWorld(), pos, apply);
}
});
});
}
static void createBlockEntity(World world, BlockPos bpos, @Nullable Consumer<Entity> apply) { static void createBlockEntity(World world, BlockPos bpos, @Nullable Consumer<Entity> apply) {
if (world.isAir(bpos)) { if (world.isAir(bpos)) {

View file

@ -256,7 +256,6 @@ public class MagicProjectileEntity extends ThrownItemEntity implements Caster<Ma
@Override @Override
protected void onCollision(HitResult result) { protected void onCollision(HitResult result) {
if (!isRemoved()) { if (!isRemoved()) {
discard();
super.onCollision(result); super.onCollision(result);
if (!world.isClient()) { if (!world.isClient()) {