Search in sources :

Example 1 with RaytraceAssist

use of hellfirepvp.astralsorcery.common.util.RaytraceAssist 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);
                }
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) PktShootEntity(hellfirepvp.astralsorcery.common.network.play.server.PktShootEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Vector3(hellfirepvp.astralsorcery.common.util.data.Vector3) BlockPos(net.minecraft.util.math.BlockPos) RaytraceAssist(hellfirepvp.astralsorcery.common.util.RaytraceAssist)

Example 2 with RaytraceAssist

use of hellfirepvp.astralsorcery.common.util.RaytraceAssist in project AstralSorcery by HellFirePvP.

the class ItemBlinkWand method playUseParticles.

@OnlyIn(Dist.CLIENT)
private void playUseParticles(ItemStack stack, LivingEntity entity, int useTicks, float usagePercent) {
    if (!(entity instanceof PlayerEntity)) {
        return;
    }
    PlayerEntity player = (PlayerEntity) entity;
    if (player.getCooldownTracker().hasCooldown(this)) {
        return;
    }
    if (getBlinkMode(stack) == BlinkMode.LAUNCH) {
        Vector3 look = new Vector3(entity.getLook(1F)).normalize().multiply(20);
        Vector3 pos = Vector3.atEntityCorner(entity).addY(entity.getEyeHeight());
        Vector3 motion = look.clone().normalize().multiply(-0.8F + random.nextFloat() * -0.5F);
        Vector3 perp = look.clone().perpendicular().normalize();
        for (int i = 0; i < Math.round(usagePercent * 6); i++) {
            float dst = i == 0 ? random.nextFloat() * 0.4F : 0.2F + random.nextFloat() * 0.4F;
            float speed = i == 0 ? 0.005F : 0.5F + random.nextFloat() * 0.5F;
            float angleDeg = random.nextFloat() * 360F;
            Vector3 angle = perp.clone().rotate(angleDeg, look).normalize();
            Vector3 at = pos.clone().add(look.clone().multiply(0.7F + random.nextFloat() * 0.3F)).add(angle.clone().multiply(dst));
            Vector3 mot = motion.clone().add(angle.clone().multiply(0.1F + random.nextFloat() * 0.15F)).multiply(speed);
            FXFacingParticle p = EffectHelper.of(EffectTemplatesAS.GENERIC_PARTICLE).setOwner(entity.getUniqueID()).spawn(at).setScaleMultiplier(0.3F + random.nextFloat() * 0.3F).setAlphaMultiplier(usagePercent).setMotion(mot).color(VFXColorFunction.constant(ColorsAS.CONSTELLATION_VICIO)).setMaxAge(20 + random.nextInt(15));
            if (random.nextBoolean()) {
                p.color(VFXColorFunction.WHITE);
            }
        }
    } else if (getBlinkMode(stack) == BlinkMode.TELEPORT) {
        Vector3 origin = Vector3.atEntityCorner(entity).addY(0.5F);
        Vector3 look = new Vector3(entity.getLook(1F)).normalize().multiply(40F).add(origin);
        List<Vector3> line = new ArrayList<>();
        RaytraceAssist rta = new RaytraceAssist(origin, look);
        boolean clearLine = rta.forEachStep(v -> {
            BlockPos pos = v.toBlockPos();
            return MiscUtils.executeWithChunk(entity.getEntityWorld(), pos, () -> {
                if (BlockUtils.isReplaceable(entity.getEntityWorld(), pos) && BlockUtils.isReplaceable(entity.getEntityWorld(), pos.up())) {
                    line.add(v);
                    return true;
                }
                return false;
            }, false);
        });
        if (!line.isEmpty()) {
            Vector3 last = Iterables.getLast(line);
            for (Vector3 v : line) {
                if (v == last || random.nextInt(300) == 0) {
                    VFXColorFunction<?> colorFn = VFXColorFunction.constant(ColorsAS.CONSTELLATION_VICIO);
                    float scale = 0.4F + random.nextFloat() * 0.2F;
                    float speed = random.nextFloat() * 0.02F;
                    int age = 20 + random.nextInt(15);
                    if (random.nextInt(3) == 0) {
                        colorFn = VFXColorFunction.WHITE;
                    }
                    if (v == last) {
                        scale *= 1.5F;
                        speed *= 4;
                        age *= 0.7F;
                        if (!clearLine) {
                            colorFn = VFXColorFunction.constant(ColorsAS.CONSTELLATION_AEVITAS);
                        } else {
                            colorFn = VFXColorFunction.constant(ColorsAS.CONSTELLATION_EVORSIO);
                        }
                        if (random.nextInt(5) == 0) {
                            colorFn = VFXColorFunction.WHITE;
                        }
                    }
                    EffectHelper.of(EffectTemplatesAS.GENERIC_PARTICLE).setOwner(entity.getUniqueID()).spawn(v).setScaleMultiplier(scale).setAlphaMultiplier(usagePercent).alpha(VFXAlphaFunction.FADE_OUT).setMotion(Vector3.random().normalize().multiply(speed)).color(colorFn).setMaxAge(age);
                }
            }
        }
    }
}
Also used : net.minecraft.util.text(net.minecraft.util.text) Vector3(hellfirepvp.astralsorcery.common.util.data.Vector3) Iterables(com.google.common.collect.Iterables) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) BlockUtils(hellfirepvp.astralsorcery.common.util.block.BlockUtils) NBTHelper(hellfirepvp.astralsorcery.common.util.nbt.NBTHelper) Item(net.minecraft.item.Item) CommonProxy(hellfirepvp.astralsorcery.common.CommonProxy) CompoundNBT(net.minecraft.nbt.CompoundNBT) UseAction(net.minecraft.item.UseAction) ITooltipFlag(net.minecraft.client.util.ITooltipFlag) ConstellationsAS(hellfirepvp.astralsorcery.common.lib.ConstellationsAS) Dist(net.minecraftforge.api.distmarker.Dist) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) AlignmentChargeHandler(hellfirepvp.astralsorcery.common.auxiliary.charge.AlignmentChargeHandler) EffectTemplatesAS(hellfirepvp.astralsorcery.client.lib.EffectTemplatesAS) AstralSorcery(hellfirepvp.astralsorcery.AstralSorcery) MiscUtils(hellfirepvp.astralsorcery.common.util.MiscUtils) Hand(net.minecraft.util.Hand) RaytraceAssist(hellfirepvp.astralsorcery.common.util.RaytraceAssist) PacketChannel(hellfirepvp.astralsorcery.common.network.PacketChannel) ColorsAS(hellfirepvp.astralsorcery.common.lib.ColorsAS) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) LogicalSide(net.minecraftforge.fml.LogicalSide) FXFacingParticle(hellfirepvp.astralsorcery.client.effect.vfx.FXFacingParticle) VFXAlphaFunction(hellfirepvp.astralsorcery.client.effect.function.VFXAlphaFunction) ItemMantle(hellfirepvp.astralsorcery.common.item.armor.ItemMantle) PlayerEntity(net.minecraft.entity.player.PlayerEntity) PktShootEntity(hellfirepvp.astralsorcery.common.network.play.server.PktShootEntity) LivingEntity(net.minecraft.entity.LivingEntity) World(net.minecraft.world.World) BlockPos(net.minecraft.util.math.BlockPos) EffectHelper(hellfirepvp.astralsorcery.client.effect.handler.EffectHelper) DamageSource(net.minecraft.util.DamageSource) ActionResult(net.minecraft.util.ActionResult) List(java.util.List) VFXColorFunction(hellfirepvp.astralsorcery.client.effect.function.VFXColorFunction) MathHelper(net.minecraft.util.math.MathHelper) AlignmentChargeConsumer(hellfirepvp.astralsorcery.common.item.base.AlignmentChargeConsumer) EventHelperDamageCancelling(hellfirepvp.astralsorcery.common.event.helper.EventHelperDamageCancelling) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) VFXColorFunction(hellfirepvp.astralsorcery.client.effect.function.VFXColorFunction) Vector3(hellfirepvp.astralsorcery.common.util.data.Vector3) FXFacingParticle(hellfirepvp.astralsorcery.client.effect.vfx.FXFacingParticle) ArrayList(java.util.ArrayList) List(java.util.List) BlockPos(net.minecraft.util.math.BlockPos) RaytraceAssist(hellfirepvp.astralsorcery.common.util.RaytraceAssist) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 3 with RaytraceAssist

use of hellfirepvp.astralsorcery.common.util.RaytraceAssist in project AstralSorcery by HellFirePvP.

the class TileLens method doColorEffects.

private void doColorEffects() {
    World world = this.getWorld();
    if (!world.isRemote() && !this.occupiedConnections.isEmpty()) {
        this.occupiedConnections.clear();
        markForUpdate();
        preventNetworkSync();
    }
    if (accumulatedStarlight <= 0) {
        return;
    }
    float effectMultiplier = accumulatedStarlight * 1.4F;
    accumulatedStarlight = 0;
    List<BlockPos> linked = getLinkedPositions();
    if (linked.isEmpty()) {
        return;
    }
    Vector3 thisVec = new Vector3(this).add(0.5, 0.5, 0.5);
    for (BlockPos linkedTo : linked) {
        PartialEffectExecutor exec = new PartialEffectExecutor((1F / ((float) linked.size())) * effectMultiplier, rand);
        Vector3 to = new Vector3(linkedTo).add(0.5, 0.5, 0.5);
        RaytraceAssist rta = new RaytraceAssist(thisVec, to).includeEndPoint();
        if (colorType.getType().doBlockInteraction()) {
            if (!rta.isClear(world) && rta.positionHit() != null) {
                BlockPos posHit = rta.positionHit();
                BlockState stateHit = world.getBlockState(posHit);
                colorType.blockInBeam(world, posHit, stateHit, exec);
                if (!world.isRemote()) {
                    this.occupiedConnections.add(posHit);
                }
            } else {
                if (!world.isRemote()) {
                    this.occupiedConnections.add(linkedTo);
                }
            }
        }
        if (colorType.getType().doEntityInteraction()) {
            exec.reset();
            rta.setCollectEntities(0.5);
            rta.isClear(world);
            List<Entity> found = rta.collectedEntities(world);
            found.forEach(e -> colorType.entityInBeam(world, thisVec, to, e, exec));
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) BlockState(net.minecraft.block.BlockState) PartialEffectExecutor(hellfirepvp.astralsorcery.common.util.PartialEffectExecutor) BlockPos(net.minecraft.util.math.BlockPos) Vector3(hellfirepvp.astralsorcery.common.util.data.Vector3) World(net.minecraft.world.World) RaytraceAssist(hellfirepvp.astralsorcery.common.util.RaytraceAssist)

Example 4 with RaytraceAssist

use of hellfirepvp.astralsorcery.common.util.RaytraceAssist in project AstralSorcery by HellFirePvP.

the class SimpleTransmissionNode method addLink.

private void addLink(World world, BlockPos pos, boolean doRayTest, boolean oldRayState) {
    this.nextPos = pos;
    this.assistNext = new RaytraceAssist(thisPos, nextPos);
    if (doRayTest) {
        this.nextReachable = this.ignoreBlockCollision || assistNext.isClear(world);
    } else {
        this.nextReachable = oldRayState;
    }
    this.dstToNextSq = pos.distanceSq(Vector3d.copy(thisPos), false);
}
Also used : RaytraceAssist(hellfirepvp.astralsorcery.common.util.RaytraceAssist)

Example 5 with RaytraceAssist

use of hellfirepvp.astralsorcery.common.util.RaytraceAssist in project AstralSorcery by HellFirePvP.

the class ChaliceHelper method findNearbyChalices.

@Nonnull
public static List<BlockPos> findNearbyChalices(World world, BlockPos origin, int distance) {
    Vector3 thisVector = new Vector3(origin).add(0.5, 1.5, 0.5);
    List<BlockPos> foundChalices = BlockDiscoverer.searchForBlocksAround(world, origin, MathHelper.clamp(distance, 0, 16), (w, pos, state) -> !pos.equals(origin) && state.getBlock() instanceof BlockChalice && !w.isBlockPowered(pos) && !(w.getBlockState(pos.down()).getBlock() instanceof BlockFountain));
    foundChalices.removeIf(pos -> {
        Vector3 chaliceVector = new Vector3(pos).add(0.5, 1.5, 0.5);
        RaytraceAssist assist = new RaytraceAssist(thisVector, chaliceVector);
        return !assist.isClear(world);
    });
    return foundChalices;
}
Also used : BlockFountain(hellfirepvp.astralsorcery.common.block.tile.BlockFountain) BlockChalice(hellfirepvp.astralsorcery.common.block.tile.BlockChalice) Vector3(hellfirepvp.astralsorcery.common.util.data.Vector3) BlockPos(net.minecraft.util.math.BlockPos) RaytraceAssist(hellfirepvp.astralsorcery.common.util.RaytraceAssist) Nonnull(javax.annotation.Nonnull)

Aggregations

RaytraceAssist (hellfirepvp.astralsorcery.common.util.RaytraceAssist)8 Vector3 (hellfirepvp.astralsorcery.common.util.data.Vector3)7 BlockPos (net.minecraft.util.math.BlockPos)7 PktPlayEffect (hellfirepvp.astralsorcery.common.network.play.server.PktPlayEffect)2 PktShootEntity (hellfirepvp.astralsorcery.common.network.play.server.PktShootEntity)2 ArrayList (java.util.ArrayList)2 Nonnull (javax.annotation.Nonnull)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 World (net.minecraft.world.World)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 Iterables (com.google.common.collect.Iterables)1 AstralSorcery (hellfirepvp.astralsorcery.AstralSorcery)1 VFXAlphaFunction (hellfirepvp.astralsorcery.client.effect.function.VFXAlphaFunction)1 VFXColorFunction (hellfirepvp.astralsorcery.client.effect.function.VFXColorFunction)1 EffectHelper (hellfirepvp.astralsorcery.client.effect.handler.EffectHelper)1 FXFacingParticle (hellfirepvp.astralsorcery.client.effect.vfx.FXFacingParticle)1 EffectTemplatesAS (hellfirepvp.astralsorcery.client.lib.EffectTemplatesAS)1 CommonProxy (hellfirepvp.astralsorcery.common.CommonProxy)1 AlignmentChargeHandler (hellfirepvp.astralsorcery.common.auxiliary.charge.AlignmentChargeHandler)1 BlockChalice (hellfirepvp.astralsorcery.common.block.tile.BlockChalice)1