Search in sources :

Example 1 with WorldBlockPos

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

the class CEffectLucerna method runStatusEffect.

@Override
public boolean runStatusEffect(World world, BlockPos pos, int mirrorAmount, ConstellationEffectProperties modified, @Nullable IMinorConstellation possibleTraitEffect) {
    if (modified.isCorrupted()) {
        if (world instanceof ServerWorld && DayTimeHelper.isNight(world) && rand.nextBoolean()) {
            SkyHandler.getInstance().revertWorldTimeTick((ServerWorld) world);
        }
        return true;
    }
    WorldBlockPos at = WorldBlockPos.wrapServer(world, pos);
    TickTokenMap.SimpleTickToken<Double> token = EventHelperSpawnDeny.spawnDenyRegions.get(at);
    if (token != null && Math.abs(token.getValue() - modified.getSize()) < 1E-3) {
        int next = token.getRemainingTimeout() + 80;
        if (next > 400)
            next = 400;
        token.setTimeout(next);
        rememberedTimeout = next;
    } else {
        if (token != null) {
            token.setTimeout(0);
        }
        rememberedTimeout = Math.min(400, rememberedTimeout + 80);
        EventHelperSpawnDeny.spawnDenyRegions.put(at, new TickTokenMap.SimpleTickToken<>(modified.getSize(), rememberedTimeout));
    }
    return true;
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) WorldBlockPos(hellfirepvp.astralsorcery.common.util.block.WorldBlockPos) TickTokenMap(hellfirepvp.astralsorcery.common.util.tick.TickTokenMap)

Example 2 with WorldBlockPos

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

the class CEffectArmara method playEffect.

@Override
public boolean playEffect(World world, BlockPos pos, ConstellationEffectProperties properties, @Nullable IMinorConstellation trait) {
    int toAdd = 2 + rand.nextInt(5);
    WorldBlockPos at = WorldBlockPos.wrapServer(world, pos);
    TickTokenMap.SimpleTickToken<Double> token = EventHelperSpawnDeny.spawnDenyRegions.get(at);
    if (token != null) {
        int next = token.getRemainingTimeout() + toAdd;
        if (next > 400)
            next = 400;
        token.setTimeout(next);
        rememberedTimeout = next;
    } else {
        rememberedTimeout = Math.min(400, rememberedTimeout + toAdd);
        EventHelperSpawnDeny.spawnDenyRegions.put(at, new TickTokenMap.SimpleTickToken<>(properties.getSize(), rememberedTimeout));
    }
    if (!properties.isCorrupted()) {
        List<Entity> projectiles = world.getEntitiesWithinAABB(Entity.class, BOX.offset(pos).grow(properties.getSize()));
        if (!projectiles.isEmpty()) {
            for (Entity e : projectiles) {
                if (e.isAlive() && TechnicalEntityRegistry.INSTANCE.canAffect(e)) {
                    if (e instanceof ProjectileEntity) {
                        double xRatio = (pos.getX() + 0.5) - e.getPosX();
                        double zRatio = (pos.getZ() + 0.5) - e.getPosZ();
                        float f = MathHelper.sqrt(xRatio * xRatio + zRatio * zRatio);
                        Vector3 motion = new Vector3(e.getMotion());
                        motion.multiply(new Vector3(0.5, 1, 0.5));
                        motion.subtract(xRatio / f * 0.4, 0, zRatio / f * 0.4);
                        ((ProjectileEntity) e).shoot(motion.getX(), motion.getY(), motion.getZ(), 1.5F, 0F);
                    } else if (e instanceof MobEntity) {
                        ((LivingEntity) e).applyKnockback(0.4F, (pos.getX() + 0.5) - e.getPosX(), (pos.getZ() + 0.5) - e.getPosZ());
                    }
                }
            }
        }
    }
    int potionAmplifier = CONFIG.potionAmplifier.get();
    List<LivingEntity> entities = this.collectEntities(world, pos, properties);
    for (LivingEntity entity : entities) {
        if (entity.isAlive() && (entity instanceof MobEntity || entity instanceof PlayerEntity)) {
            if (properties.isCorrupted()) {
                if (entity instanceof PlayerEntity) {
                    continue;
                }
                EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(Effects.SPEED, 100, potionAmplifier + 4));
                EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(Effects.REGENERATION, 100, potionAmplifier + 4));
                EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(Effects.RESISTANCE, 100, potionAmplifier + 2));
                EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(Effects.STRENGTH, 100, potionAmplifier + 4));
                EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(Effects.WATER_BREATHING, 100, potionAmplifier + 4));
                EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(Effects.HASTE, 100, potionAmplifier + 4));
                EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(EffectsAS.EFFECT_DROP_MODIFIER, 100, 5));
            } else {
                EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(Effects.RESISTANCE, 30, Math.min(potionAmplifier, 3), true, true));
                if (entity instanceof PlayerEntity) {
                    EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(Effects.ABSORPTION, 30, potionAmplifier, true, false));
                }
            }
            if (entity instanceof PlayerEntity) {
                markPlayerAffected((PlayerEntity) entity);
            }
        }
    }
    return true;
}
Also used : MobEntity(net.minecraft.entity.MobEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) ProjectileEntity(net.minecraft.entity.projectile.ProjectileEntity) ProjectileEntity(net.minecraft.entity.projectile.ProjectileEntity) WorldBlockPos(hellfirepvp.astralsorcery.common.util.block.WorldBlockPos) TickTokenMap(hellfirepvp.astralsorcery.common.util.tick.TickTokenMap) Vector3(hellfirepvp.astralsorcery.common.util.data.Vector3) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) MobEntity(net.minecraft.entity.MobEntity) EffectInstance(net.minecraft.potion.EffectInstance)

Example 3 with WorldBlockPos

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

the class BlockTransmutationHandler method receiveStarlight.

@Override
public void receiveStarlight(World world, Random rand, BlockPos pos, BlockState state, IWeakConstellation starlightType, double amount) {
    BlockTransmutation recipe = RecipeTypesAS.TYPE_BLOCK_TRANSMUTATION.findRecipe(new BlockTransmutationContext(world, pos, state, starlightType));
    if (recipe == null) {
        // Wait what
        return;
    }
    WorldBlockPos at = WorldBlockPos.wrapServer(world, pos);
    ActiveTransmutation activeRecipe = runningTransmutations.get(at);
    if (activeRecipe == null || !activeRecipe.recipe.equals(recipe)) {
        activeRecipe = new ActiveTransmutation(recipe);
        runningTransmutations.put(at, activeRecipe);
    }
    activeRecipe.acceptStarlight(amount);
    PktPlayEffect pkt = new PktPlayEffect(PktPlayEffect.Type.BLOCK_TRANSMUTATION_TICK).addData(buf -> ByteBufUtils.writePos(buf, pos));
    PacketChannel.CHANNEL.sendToAllAround(pkt, PacketChannel.pointFromPos(world, pos, 24));
    if (activeRecipe.isFinished() && activeRecipe.finish(world, pos)) {
        runningTransmutations.remove(at);
    }
}
Also used : WorldBlockPos(hellfirepvp.astralsorcery.common.util.block.WorldBlockPos) BlockTransmutationContext(hellfirepvp.astralsorcery.common.crafting.recipe.BlockTransmutationContext) PktPlayEffect(hellfirepvp.astralsorcery.common.network.play.server.PktPlayEffect) BlockTransmutation(hellfirepvp.astralsorcery.common.crafting.recipe.BlockTransmutation)

Aggregations

WorldBlockPos (hellfirepvp.astralsorcery.common.util.block.WorldBlockPos)3 TickTokenMap (hellfirepvp.astralsorcery.common.util.tick.TickTokenMap)2 BlockTransmutation (hellfirepvp.astralsorcery.common.crafting.recipe.BlockTransmutation)1 BlockTransmutationContext (hellfirepvp.astralsorcery.common.crafting.recipe.BlockTransmutationContext)1 PktPlayEffect (hellfirepvp.astralsorcery.common.network.play.server.PktPlayEffect)1 Vector3 (hellfirepvp.astralsorcery.common.util.data.Vector3)1 Entity (net.minecraft.entity.Entity)1 LivingEntity (net.minecraft.entity.LivingEntity)1 MobEntity (net.minecraft.entity.MobEntity)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 ProjectileEntity (net.minecraft.entity.projectile.ProjectileEntity)1 EffectInstance (net.minecraft.potion.EffectInstance)1 ServerWorld (net.minecraft.world.server.ServerWorld)1