use of hellfirepvp.astralsorcery.common.network.play.server.PktShootEntity in project AstralSorcery by HellFirePvP.
the class ItemBlinkWand method onPlayerStoppedUsing.
@Override
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, LivingEntity entityLiving, int timeLeft) {
if (worldIn.isRemote() || !(entityLiving instanceof ServerPlayerEntity)) {
return;
}
ServerPlayerEntity player = (ServerPlayerEntity) entityLiving;
BlinkMode mode = getBlinkMode(stack);
if (mode == BlinkMode.TELEPORT) {
Vector3 origin = Vector3.atEntityCorner(player).addY(0.5F);
Vector3 look = new Vector3(player.getLook(1F)).normalize().multiply(40F).add(origin);
List<BlockPos> blockLine = new ArrayList<>();
RaytraceAssist rta = new RaytraceAssist(origin, look);
rta.forEachBlockPos(pos -> {
return MiscUtils.executeWithChunk(player.getEntityWorld(), pos, () -> {
if (BlockUtils.isReplaceable(player.getEntityWorld(), pos) && BlockUtils.isReplaceable(player.getEntityWorld(), pos.up())) {
blockLine.add(pos);
return true;
}
return false;
}, false);
});
if (!blockLine.isEmpty()) {
BlockPos at = Iterables.getLast(blockLine);
if (origin.distance(at) > 5) {
if (AlignmentChargeHandler.INSTANCE.drainCharge(player, LogicalSide.SERVER, COST_PER_BLINK, false)) {
player.setPositionAndUpdate(at.getX() + 0.5, at.getY(), at.getZ() + 0.5);
if (!player.isCreative()) {
player.getCooldownTracker().setCooldown(stack.getItem(), 40);
}
}
}
}
} else if (mode == BlinkMode.LAUNCH) {
float multiplier = 0.8F;
if (!entityLiving.isElytraFlying()) {
multiplier = 2.4F;
}
float strength = 0.2F + Math.min(1F, Math.min(50, stack.getUseDuration() - timeLeft) / 50F) * multiplier;
if (strength > 0.3F) {
float chargeCost = COST_PER_DASH * 0.8F;
if (AlignmentChargeHandler.INSTANCE.drainCharge(player, LogicalSide.SERVER, chargeCost, false)) {
Vector3 motion = new Vector3(player.getLook(1F)).normalize().multiply(strength * 3F);
if (motion.getY() > 0) {
motion.setY(MathHelper.clamp(motion.getY() + (0.2F * strength), 0.2F * strength, Float.MAX_VALUE));
}
player.setMotion(motion.toVector3d());
player.fallDistance = 0F;
if (ItemMantle.getEffect(player, ConstellationsAS.vicio) != null) {
AstralSorcery.getProxy().scheduleClientside(player::startFallFlying, 2);
}
PktShootEntity pkt = new PktShootEntity(player.getEntityId(), motion);
pkt.setEffectLength(strength);
PacketChannel.CHANNEL.sendToAllAround(pkt, PacketChannel.pointFromPos(worldIn, player.getPosition(), 64));
if (!player.isElytraFlying()) {
EventHelperDamageCancelling.markInvulnerableToNextDamage(player, DamageSource.FALL);
}
}
}
}
}
Aggregations