Search in sources :

Example 1 with PktPlayEffect

use of hellfirepvp.astralsorcery.common.network.play.server.PktPlayEffect in project AstralSorcery by HellFirePvP.

the class CelestialStrike method play.

public static void play(@Nullable LivingEntity attacker, ServerWorld world, Vector3 at, Vector3 displayPosition) {
    double radius = 16D;
    List<LivingEntity> livingEntities = world.getEntitiesWithinAABB(LivingEntity.class, EMPTY.grow(radius, radius / 2, radius).offset(at.toBlockPos()), EntityPredicates.IS_ALIVE);
    if (attacker != null) {
        livingEntities.remove(attacker);
    }
    DamageSource ds = CommonProxy.DAMAGE_SOURCE_STELLAR;
    if (attacker != null) {
        ds = DamageSource.causeMobDamage(attacker);
        if (attacker instanceof PlayerEntity) {
            ds = DamageSource.causePlayerDamage((PlayerEntity) attacker);
        }
    }
    float dmg = 25F;
    dmg += SkyCollectionHelper.getSkyNoiseDistribution(world, at.toBlockPos()) * 10F;
    for (LivingEntity living : livingEntities) {
        if ((living instanceof PlayerEntity) && (living.isSpectator() || ((PlayerEntity) living).isCreative() || (attacker != null && living.isOnSameTeam(attacker)))) {
            continue;
        }
        float dstPerc = (float) (Vector3.atEntityCenter(living).distance(at) / radius);
        dstPerc = 1F - MathHelper.clamp(dstPerc, 0F, 1F);
        float dmgDealt = dstPerc * dmg;
        if (dmgDealt > 0.5) {
            DamageUtil.attackEntityFrom(living, ds, dmgDealt);
            if (attacker != null) {
                int fireAspectLevel = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.FIRE_ASPECT, attacker);
                if (fireAspectLevel > 0 && !living.isBurning()) {
                    living.setFire(fireAspectLevel * 4);
                }
            }
        }
    }
    PktPlayEffect pkt = new PktPlayEffect(PktPlayEffect.Type.CELESTIAL_STRIKE).addData(buf -> {
        ByteBufUtils.writeVector(buf, displayPosition);
    });
    PacketChannel.CHANNEL.sendToAllAround(pkt, PacketChannel.pointFromPos(world, at.toBlockPos(), 96));
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) DamageSource(net.minecraft.util.DamageSource) PktPlayEffect(hellfirepvp.astralsorcery.common.network.play.server.PktPlayEffect) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 2 with PktPlayEffect

use of hellfirepvp.astralsorcery.common.network.play.server.PktPlayEffect in project AstralSorcery by HellFirePvP.

the class IndependentCrystalSource method produceStarlightTick.

@Override
public float produceStarlightTick(ServerWorld world, BlockPos pos) {
    if (!doesSeeSky || crystalAttributes == null) {
        return 0F;
    }
    IWeakConstellation cst = getStarlightType();
    WorldContext ctx = SkyHandler.getContext(world, LogicalSide.SERVER);
    if (ctx == null || cst == null) {
        return 0F;
    }
    if (posDistribution == -1) {
        posDistribution = SkyCollectionHelper.getSkyNoiseDistribution(world, pos);
    }
    if (closestOtherCollector != null && rand.nextInt(40) == 0) {
        PktPlayEffect pkt = new PktPlayEffect(PktPlayEffect.Type.LIGHTNING).addData(buf -> {
            ByteBufUtils.writeVector(buf, new Vector3(pos).add(0.5, 0.5, 0.5));
            ByteBufUtils.writeVector(buf, new Vector3(closestOtherCollector).add(0.5, 0.5, 0.5));
            buf.writeInt(this.constellation.getConstellationColor().darker().getRGB());
        });
        PacketChannel.CHANNEL.sendToAllAround(pkt, PacketChannel.pointFromPos(world, pos, 32));
    }
    Function<Float, Float> distrFunction = getDistributionFunc();
    float perc = CrystalCalculations.getCollectorCrystalCollectionRate(this);
    perc *= distrFunction.apply(0.3F + (0.7F * DayTimeHelper.getCurrentDaytimeDistribution(world)));
    perc *= collectionDstMultiplier;
    perc *= 1 + (0.3 * posDistribution);
    perc *= 0.4 + 0.6 * ctx.getDistributionHandler().getDistribution(cst);
    return perc;
}
Also used : PktPlayEffect(hellfirepvp.astralsorcery.common.network.play.server.PktPlayEffect) Vector3(hellfirepvp.astralsorcery.common.util.data.Vector3) WorldContext(hellfirepvp.astralsorcery.common.constellation.world.WorldContext) IWeakConstellation(hellfirepvp.astralsorcery.common.constellation.IWeakConstellation)

Example 3 with PktPlayEffect

use of hellfirepvp.astralsorcery.common.network.play.server.PktPlayEffect in project AstralSorcery by HellFirePvP.

the class ItemArchitectWand method attemptPlaceBlocks.

private ActionResult<ItemStack> attemptPlaceBlocks(World world, PlayerEntity player, ItemStack held) {
    Map<BlockPos, BlockState> placeStates = getPlayerPlaceableStates(player, held);
    if (placeStates.isEmpty()) {
        return ActionResult.resultFail(held);
    }
    Map<BlockState, Tuple<ItemStack, Integer>> availableStacks = MapStream.of(ItemBlockStorage.getInventoryMatching(player, held)).filter(tpl -> placeStates.containsValue(tpl.getA())).collect(Collectors.toMap(Tuple::getA, Tuple::getB));
    for (BlockPos placePos : placeStates.keySet()) {
        BlockState stateToPlace = placeStates.get(placePos);
        Tuple<ItemStack, Integer> availableStack = availableStacks.get(stateToPlace);
        if (availableStack == null) {
            continue;
        }
        ItemStack extractable = ItemUtils.copyStackWithSize(availableStack.getA(), 1);
        boolean canExtract = player.isCreative();
        if (!canExtract) {
            if (ItemUtils.consumeFromPlayerInventory(player, held, extractable, true)) {
                canExtract = true;
            }
        }
        if (!canExtract) {
            continue;
        }
        if (AlignmentChargeHandler.INSTANCE.drainCharge(player, LogicalSide.SERVER, COST_PER_PLACEMENT, true) && (player.isCreative() || ItemUtils.consumeFromPlayerInventory(player, held, extractable, true)) && MiscUtils.canPlayerPlaceBlockPos(player, stateToPlace, placePos, Direction.UP) && (player.isCreative() || ItemUtils.consumeFromPlayerInventory(player, held, extractable, false)) && AlignmentChargeHandler.INSTANCE.drainCharge(player, LogicalSide.SERVER, COST_PER_PLACEMENT, false) && world.setBlockState(placePos, stateToPlace)) {
            PktPlayEffect ev = new PktPlayEffect(PktPlayEffect.Type.BLOCK_EFFECT).addData(buf -> {
                ByteBufUtils.writePos(buf, placePos);
                ByteBufUtils.writeBlockState(buf, stateToPlace);
            });
            PacketChannel.CHANNEL.sendToAllAround(ev, PacketChannel.pointFromPos(world, placePos, 32));
        }
    }
    return ActionResult.resultSuccess(held);
}
Also used : net.minecraft.util(net.minecraft.util) Vector3(hellfirepvp.astralsorcery.common.util.data.Vector3) ByteBufUtils(hellfirepvp.astralsorcery.common.util.data.ByteBufUtils) ItemOverlayRender(hellfirepvp.astralsorcery.common.item.base.client.ItemOverlayRender) NBTHelper(hellfirepvp.astralsorcery.common.util.nbt.NBTHelper) Item(net.minecraft.item.Item) CommonProxy(hellfirepvp.astralsorcery.common.CommonProxy) CompoundNBT(net.minecraft.nbt.CompoundNBT) RenderingUtils(hellfirepvp.astralsorcery.client.util.RenderingUtils) Dist(net.minecraftforge.api.distmarker.Dist) Blending(hellfirepvp.astralsorcery.client.util.Blending) RenderingOverlayUtils(hellfirepvp.astralsorcery.client.util.RenderingOverlayUtils) BlockAtlasTexture(hellfirepvp.astralsorcery.client.resource.BlockAtlasTexture) GL11(org.lwjgl.opengl.GL11) RenderingVectorUtils(hellfirepvp.astralsorcery.client.util.RenderingVectorUtils) BlockState(net.minecraft.block.BlockState) MapStream(hellfirepvp.astralsorcery.common.util.MapStream) LogicalSide(net.minecraftforge.fml.LogicalSide) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Collectors(java.util.stream.Collectors) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) BufferDecoratorBuilder(hellfirepvp.observerlib.client.util.BufferDecoratorBuilder) ItemUtils(hellfirepvp.astralsorcery.common.util.item.ItemUtils) ItemHeldRender(hellfirepvp.astralsorcery.common.item.base.client.ItemHeldRender) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) net.minecraft.util.text(net.minecraft.util.text) Iterables(com.google.common.collect.Iterables) java.util(java.util) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) BlockUtils(hellfirepvp.astralsorcery.common.util.block.BlockUtils) ItemBlockStorage(hellfirepvp.astralsorcery.common.item.base.ItemBlockStorage) ITooltipFlag(net.minecraft.client.util.ITooltipFlag) ItemUseContext(net.minecraft.item.ItemUseContext) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) ItemStack(net.minecraft.item.ItemStack) RayTraceResult(net.minecraft.util.math.RayTraceResult) AlignmentChargeHandler(hellfirepvp.astralsorcery.common.auxiliary.charge.AlignmentChargeHandler) Lists(com.google.common.collect.Lists) Minecraft(net.minecraft.client.Minecraft) MiscUtils(hellfirepvp.astralsorcery.common.util.MiscUtils) RaytraceAssist(hellfirepvp.astralsorcery.common.util.RaytraceAssist) PacketChannel(hellfirepvp.astralsorcery.common.network.PacketChannel) Nonnull(javax.annotation.Nonnull) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) Nullable(javax.annotation.Nullable) World(net.minecraft.world.World) PktPlayEffect(hellfirepvp.astralsorcery.common.network.play.server.PktPlayEffect) BlockGeometry(hellfirepvp.astralsorcery.common.util.block.BlockGeometry) BlockPos(net.minecraft.util.math.BlockPos) Maps(com.google.common.collect.Maps) RayTraceContext(net.minecraft.util.math.RayTraceContext) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) AlignmentChargeConsumer(hellfirepvp.astralsorcery.common.item.base.AlignmentChargeConsumer) BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) PktPlayEffect(hellfirepvp.astralsorcery.common.network.play.server.PktPlayEffect) ItemStack(net.minecraft.item.ItemStack)

Example 4 with PktPlayEffect

use of hellfirepvp.astralsorcery.common.network.play.server.PktPlayEffect in project AstralSorcery by HellFirePvP.

the class ConstellationEffect method sendConstellationPing.

public static void sendConstellationPing(World world, Vector3 at, IConstellation cst) {
    PktPlayEffect pkt = new PktPlayEffect(PktPlayEffect.Type.CONSTELLATION_EFFECT_PING).addData(buf -> {
        ByteBufUtils.writeVector(buf, at);
        ByteBufUtils.writeRegistryEntry(buf, cst);
    });
    PacketChannel.CHANNEL.sendToAllAround(pkt, PacketChannel.pointFromPos(world, at.toBlockPos(), 32));
}
Also used : PktPlayEffect(hellfirepvp.astralsorcery.common.network.play.server.PktPlayEffect)

Example 5 with PktPlayEffect

use of hellfirepvp.astralsorcery.common.network.play.server.PktPlayEffect in project AstralSorcery by HellFirePvP.

the class CEffectAevitas method playEffect.

@Override
public boolean playEffect(World world, BlockPos pos, ConstellationEffectProperties properties, @Nullable IMinorConstellation trait) {
    boolean changed = false;
    CropHelper.GrowablePlant plant = getRandomElementChanced();
    if (plant != null) {
        changed = MiscUtils.executeWithChunk(world, plant.getPos(), changed, (changedFlag) -> {
            if (properties.isCorrupted()) {
                if (world instanceof ServerWorld) {
                    CropHelper.HarvestablePlant harvestablePlant = CropHelper.wrapHarvestablePlant(world, plant.getPos());
                    if (harvestablePlant != null) {
                        NonNullList<ItemStack> drops = harvestablePlant.harvestDropsAndReplant((ServerWorld) world, rand, 1);
                        drops.forEach(drop -> ItemUtils.dropItem(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, drop));
                        changedFlag = !drops.isEmpty();
                    } else if (BlockUtils.breakBlockWithoutPlayer(((ServerWorld) world), plant.getPos())) {
                        changedFlag = true;
                    }
                } else {
                    if (world.removeBlock(plant.getPos(), false)) {
                        changedFlag = true;
                    }
                }
            } else {
                if (!plant.isValid(world)) {
                    removeElement(plant.getPos());
                    changedFlag = true;
                } else {
                    if (plant.tryGrow(world, rand)) {
                        PktPlayEffect pkt = new PktPlayEffect(PktPlayEffect.Type.CROP_GROWTH).addData(buf -> ByteBufUtils.writeVector(buf, new Vector3(plant.getPos())));
                        PacketChannel.CHANNEL.sendToAllAround(pkt, PacketChannel.pointFromPos(world, plant.getPos(), 16));
                        changedFlag = true;
                    }
                }
            }
            return changedFlag;
        }, false);
    }
    if (this.findNewPosition(world, pos, properties).ifRight(attemptedPos -> sendConstellationPing(world, new Vector3(attemptedPos).add(0.5, 0.5, 0.5))).left().isPresent())
        changed = true;
    if (this.findNewPosition(world, pos, properties).ifRight(attemptedPos -> sendConstellationPing(world, new Vector3(attemptedPos).add(0.5, 0.5, 0.5))).left().isPresent())
        changed = true;
    int amplifier = CONFIG.potionAmplifier.get();
    List<LivingEntity> entities = world.getEntitiesWithinAABB(LivingEntity.class, BOX.offset(pos).grow(properties.getSize()));
    for (LivingEntity entity : entities) {
        if (entity.isAlive()) {
            if (properties.isCorrupted()) {
                EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(EffectsAS.EFFECT_BLEED, 120, amplifier * 2));
                EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(Effects.WEAKNESS, 120, amplifier * 3));
                EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(Effects.HUNGER, 120, amplifier * 4));
                EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(Effects.MINING_FATIGUE, 120, amplifier * 2));
            } else {
                EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(Effects.REGENERATION, 120, amplifier));
            }
            if (entity instanceof PlayerEntity) {
                markPlayerAffected((PlayerEntity) entity);
            }
        }
    }
    return changed;
}
Also used : TileRitualPedestal(hellfirepvp.astralsorcery.common.tile.TileRitualPedestal) Vector3(hellfirepvp.astralsorcery.common.util.data.Vector3) ServerWorld(net.minecraft.world.server.ServerWorld) ByteBufUtils(hellfirepvp.astralsorcery.common.util.data.ByteBufUtils) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) BlockUtils(hellfirepvp.astralsorcery.common.util.block.BlockUtils) ForgeConfigSpec(net.minecraftforge.common.ForgeConfigSpec) IMinorConstellation(hellfirepvp.astralsorcery.common.constellation.IMinorConstellation) CompoundNBT(net.minecraft.nbt.CompoundNBT) ConstellationsAS(hellfirepvp.astralsorcery.common.lib.ConstellationsAS) PlayerAffectionFlags(hellfirepvp.astralsorcery.common.event.PlayerAffectionFlags) Dist(net.minecraftforge.api.distmarker.Dist) ItemStack(net.minecraft.item.ItemStack) EffectInstance(net.minecraft.potion.EffectInstance) ILocatable(hellfirepvp.astralsorcery.common.util.block.ILocatable) EffectTemplatesAS(hellfirepvp.astralsorcery.client.lib.EffectTemplatesAS) MiscUtils(hellfirepvp.astralsorcery.common.util.MiscUtils) NonNullList(net.minecraft.util.NonNullList) PacketChannel(hellfirepvp.astralsorcery.common.network.PacketChannel) ColorsAS(hellfirepvp.astralsorcery.common.lib.ColorsAS) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Effects(net.minecraft.potion.Effects) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) World(net.minecraft.world.World) PktPlayEffect(hellfirepvp.astralsorcery.common.network.play.server.PktPlayEffect) CropHelper(hellfirepvp.astralsorcery.common.auxiliary.CropHelper) BlockPos(net.minecraft.util.math.BlockPos) EffectHelper(hellfirepvp.astralsorcery.client.effect.handler.EffectHelper) java.awt(java.awt) EntityUtils(hellfirepvp.astralsorcery.common.util.entity.EntityUtils) List(java.util.List) VFXColorFunction(hellfirepvp.astralsorcery.client.effect.function.VFXColorFunction) EffectsAS(hellfirepvp.astralsorcery.common.lib.EffectsAS) ItemUtils(hellfirepvp.astralsorcery.common.util.item.ItemUtils) ConstellationEffectProperties(hellfirepvp.astralsorcery.common.constellation.effect.ConstellationEffectProperties) CEffectAbstractList(hellfirepvp.astralsorcery.common.constellation.effect.base.CEffectAbstractList) PktPlayEffect(hellfirepvp.astralsorcery.common.network.play.server.PktPlayEffect) Vector3(hellfirepvp.astralsorcery.common.util.data.Vector3) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerWorld(net.minecraft.world.server.ServerWorld) LivingEntity(net.minecraft.entity.LivingEntity) CropHelper(hellfirepvp.astralsorcery.common.auxiliary.CropHelper) NonNullList(net.minecraft.util.NonNullList) EffectInstance(net.minecraft.potion.EffectInstance)

Aggregations

PktPlayEffect (hellfirepvp.astralsorcery.common.network.play.server.PktPlayEffect)24 Vector3 (hellfirepvp.astralsorcery.common.util.data.Vector3)14 BlockPos (net.minecraft.util.math.BlockPos)11 BlockState (net.minecraft.block.BlockState)6 PlayerEntity (net.minecraft.entity.player.PlayerEntity)6 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)6 World (net.minecraft.world.World)6 PacketChannel (hellfirepvp.astralsorcery.common.network.PacketChannel)4 ByteBufUtils (hellfirepvp.astralsorcery.common.util.data.ByteBufUtils)4 AlignmentChargeHandler (hellfirepvp.astralsorcery.common.auxiliary.charge.AlignmentChargeHandler)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 FluidStack (net.minecraftforge.fluids.FluidStack)3 Iterables (com.google.common.collect.Iterables)2 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)2 RenderSystem (com.mojang.blaze3d.systems.RenderSystem)2 BlockAtlasTexture (hellfirepvp.astralsorcery.client.resource.BlockAtlasTexture)2 Blending (hellfirepvp.astralsorcery.client.util.Blending)2 RenderingOverlayUtils (hellfirepvp.astralsorcery.client.util.RenderingOverlayUtils)2