Search in sources :

Example 1 with RandUtilSeed

use of com.teamwizardry.wizardry.api.util.RandUtilSeed in project Wizardry by TeamWizardry.

the class ModuleEffectLightning method run.

@Override
public boolean run(@Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
    World world = spell.world;
    Vec3d target = spell.getTarget();
    Entity caster = spell.getCaster();
    float yaw = spell.getData(YAW, 0F);
    float pitch = spell.getData(PITCH, 0F);
    if (target == null)
        return false;
    Vec3d origin = target;
    if (caster != null) {
        float offX = 0.5f * (float) Math.sin(Math.toRadians(-90.0f - yaw));
        float offZ = 0.5f * (float) Math.cos(Math.toRadians(-90.0f - yaw));
        origin = new Vec3d(offX, caster.getEyeHeight(), offZ).add(target);
    }
    double range = spellRing.getAttributeValue(AttributeRegistry.RANGE, spell);
    double strength = spellRing.getAttributeValue(AttributeRegistry.POTENCY, spell) / 2.0;
    if (!spellRing.taxCaster(spell))
        return false;
    RayTraceResult traceResult = new RayTrace(world, PosUtils.vecFromRotations(pitch, yaw), target, range).setSkipBlocks(true).setSkipEntities(true).trace();
    long seed = RandUtil.nextLong(100, 100000);
    spell.addData(SEED, seed);
    LightningGenerator generator = new LightningGenerator(origin, traceResult.hitVec, new RandUtilSeed(seed));
    ArrayList<Vec3d> points = generator.generate();
    spell.world.playSound(null, new BlockPos(traceResult.hitVec), ModSounds.LIGHTNING, SoundCategory.NEUTRAL, 0.5f, RandUtil.nextFloat(1, 1.5f));
    for (Vec3d point : points) {
        List<Entity> entityList = world.getEntitiesWithinAABBExcludingEntity(caster, new AxisAlignedBB(new BlockPos(point)).contract(0.2, 0.2, 0.2));
        if (!entityList.isEmpty()) {
            for (Entity entity : entityList) {
                LightningTracker.INSTANCE.addEntity(origin, entity, caster, (int) strength);
            }
        }
    }
    return true;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) RayTraceResult(net.minecraft.util.math.RayTraceResult) World(net.minecraft.world.World) RandUtilSeed(com.teamwizardry.wizardry.api.util.RandUtilSeed) Vec3d(net.minecraft.util.math.Vec3d) RayTrace(com.teamwizardry.wizardry.api.util.RayTrace) BlockPos(net.minecraft.util.math.BlockPos) LightningGenerator(com.teamwizardry.wizardry.api.LightningGenerator)

Example 2 with RandUtilSeed

use of com.teamwizardry.wizardry.api.util.RandUtilSeed in project Wizardry by TeamWizardry.

the class ModelSpiritBlight method render.

@Override
public void render(@Nonnull Entity entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale) {
    GlStateManager.disableBlend();
    GlStateManager.enableBlend();
    GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GlStateManager.color(1.0F, 1.0F, 1.0F, 0.9F);
    RandUtilSeed seed = new RandUtilSeed(entityIn.getDataManager().get(DATA_SHIFT_SEED));
    GlStateManager.translate(seed.nextDouble(-2, 2), seed.nextDouble(-2, 2), seed.nextDouble(-2, 2));
    double multiplier = 0.05;
    GlStateManager.translate(RandUtil.nextFloat() * multiplier, RandUtil.nextFloat() * multiplier, RandUtil.nextFloat() * multiplier);
    GlStateManager.rotate(entityIn.rotationYaw, 0, 1, 0);
    super.render(entityIn, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale);
    GlStateManager.disableBlend();
}
Also used : RandUtilSeed(com.teamwizardry.wizardry.api.util.RandUtilSeed)

Example 3 with RandUtilSeed

use of com.teamwizardry.wizardry.api.util.RandUtilSeed in project Wizardry by TeamWizardry.

the class EntitySpiritBlight method onUpdate.

@Override
public void onUpdate() {
    super.onUpdate();
    if (world.isRemote)
        return;
    if (isAIDisabled())
        return;
    if (RandUtil.nextInt(100) == 0) {
        setShiftseed(RandUtil.nextInt(1000, 100000000));
        playSound(ModSounds.ZAP, 0.3f, RandUtil.nextFloat(1.5f, 2f));
    }
    if ((ticksExisted % RandUtil.nextInt(100, 200)) == 0)
        playSound(ModSounds.HALLOWED_SPIRIT, RandUtil.nextFloat(), RandUtil.nextFloat());
    // if (world.getTotalWorldTime() % 30 == 0) {
    // playSound(ModSounds.ELECTRIC_WHITE_NOISE, RandUtil.nextFloat(0.2f, 0.3f), RandUtil.nextFloat(0.1f, 0.3f));
    // }
    fallDistance = 0;
    EntityPlayer farPlayer = world.getNearestPlayerNotCreative(this, 300);
    setAttackTarget(farPlayer);
    if (getAttackTarget() != null) {
        noClip = true;
        Vec3d direction = getPositionVector().subtract(getAttackTarget().getPositionVector()).normalize();
        motionX = direction.x * -0.05;
        motionY = direction.y * -0.05;
        motionZ = direction.z * -0.05;
        rotationYaw = (float) (((-MathHelper.atan2(direction.x, direction.z) * 180) / Math.PI) - 180) / 2;
    } else {
        if (!collidedVertically) {
            motionY = 0;
        }
        noClip = false;
    }
    EntityPlayer player = getAttackTarget() == null ? null : world.getNearestPlayerNotCreative(this, 2);
    EntityPlayer closePlayer = getAttackTarget() == null ? null : world.getNearestPlayerNotCreative(this, 30);
    boolean angry = player != null;
    ClientRunnable.run(new ClientRunnable() {

        @Override
        @SideOnly(Side.CLIENT)
        public void runIfClient() {
            ParticleBuilder glitter = new ParticleBuilder(30);
            glitter.setRender(new ResourceLocation(Wizardry.MODID, Constants.MISC.SPARKLE_BLURRED));
            glitter.setAlphaFunction(new InterpFadeInOut(1f, 1f));
            glitter.setColor(new Color(0xf404d4));
            RandUtilSeed seed = new RandUtilSeed(getDataManager().get(DATA_SHIFT_SEED));
            Matrix4 matrix4 = new Matrix4();
            matrix4.rotate(rotationYaw, new Vec3d(0, 1, 0));
            Vec3d offset = new Vec3d(seed.nextDouble(-2, 2), seed.nextDouble(-2, 2), seed.nextDouble(-2, 2));
            ParticleSpawner.spawn(glitter, world, new StaticInterp<>(getPositionVector().addVector(0, getEyeHeight(), 0).add(offset)), 10, 0, (i, build) -> {
                double radius = 0.1;
                double theta = 2.0f * (float) Math.PI * RandUtil.nextFloat();
                double r = radius * RandUtil.nextFloat();
                double x = r * MathHelper.cos((float) theta);
                double z = r * MathHelper.sin((float) theta);
                glitter.setLifetime(RandUtil.nextInt(10, 40));
                glitter.setScaleFunction(new InterpScale(0, (float) RandUtil.nextDouble(3, 4)));
                glitter.setPositionOffset(new Vec3d(x, RandUtil.nextDouble(0, 0.2), z));
                if (RandUtil.nextInt(15) == 0)
                    glitter.addMotion(new Vec3d(RandUtil.nextDouble(-0.01, 0.01), RandUtil.nextDouble(0, 0.03), RandUtil.nextDouble(-0.01, 0.01)));
            });
        }
    });
    if (angry) {
        player.attackEntityFrom(DamageSource.MAGIC, 0.15f);
        player.hurtResistantTime = 0;
    }
}
Also used : Matrix4(com.teamwizardry.librarianlib.features.math.Matrix4) EntityDataManager(net.minecraft.network.datasync.EntityDataManager) InterpScale(com.teamwizardry.wizardry.api.util.interp.InterpScale) InterpFadeInOut(com.teamwizardry.librarianlib.features.particle.functions.InterpFadeInOut) StaticInterp(com.teamwizardry.librarianlib.features.math.interpolate.StaticInterp) ParticleSpawner(com.teamwizardry.librarianlib.features.particle.ParticleSpawner) ParticleBuilder(com.teamwizardry.librarianlib.features.particle.ParticleBuilder) Vec3d(net.minecraft.util.math.Vec3d) Side(net.minecraftforge.fml.relauncher.Side) RandUtilSeed(com.teamwizardry.wizardry.api.util.RandUtilSeed) ModSounds(com.teamwizardry.wizardry.init.ModSounds) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Nonnull(javax.annotation.Nonnull) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Entity(net.minecraft.entity.Entity) ClientRunnable(com.teamwizardry.librarianlib.features.utilities.client.ClientRunnable) World(net.minecraft.world.World) Wizardry(com.teamwizardry.wizardry.Wizardry) DataParameter(net.minecraft.network.datasync.DataParameter) DamageSource(net.minecraft.util.DamageSource) SharedMonsterAttributes(net.minecraft.entity.SharedMonsterAttributes) java.awt(java.awt) DataSerializers(net.minecraft.network.datasync.DataSerializers) EntityMob(net.minecraft.entity.monster.EntityMob) LibParticles(com.teamwizardry.wizardry.client.fx.LibParticles) EntityPlayer(net.minecraft.entity.player.EntityPlayer) MathHelper(net.minecraft.util.math.MathHelper) ResourceLocation(net.minecraft.util.ResourceLocation) RandUtil(com.teamwizardry.wizardry.api.util.RandUtil) Constants(com.teamwizardry.wizardry.api.Constants) StaticInterp(com.teamwizardry.librarianlib.features.math.interpolate.StaticInterp) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) ClientRunnable(com.teamwizardry.librarianlib.features.utilities.client.ClientRunnable) InterpFadeInOut(com.teamwizardry.librarianlib.features.particle.functions.InterpFadeInOut) ParticleBuilder(com.teamwizardry.librarianlib.features.particle.ParticleBuilder) RandUtilSeed(com.teamwizardry.wizardry.api.util.RandUtilSeed) Vec3d(net.minecraft.util.math.Vec3d) Matrix4(com.teamwizardry.librarianlib.features.math.Matrix4) InterpScale(com.teamwizardry.wizardry.api.util.interp.InterpScale) ResourceLocation(net.minecraft.util.ResourceLocation) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 4 with RandUtilSeed

use of com.teamwizardry.wizardry.api.util.RandUtilSeed in project Wizardry by TeamWizardry.

the class TileUnicornTrail method update.

@Override
public void update() {
    RandUtilSeed seed = new RandUtilSeed(getPos().toLong());
    if (System.currentTimeMillis() - savedTime >= seed.nextInt(3000, 5000)) {
        getWorld().setBlockToAir(getPos());
    } else {
        if (RandUtil.nextInt(20) == 0)
            ClientRunnable.run(new ClientRunnable() {

                @Override
                @SideOnly(Side.CLIENT)
                public void runIfClient() {
                    ParticleBuilder builder = new ParticleBuilder(50);
                    builder.setRender(new ResourceLocation(Wizardry.MODID, SPARKLE_BLURRED));
                    builder.disableMotionCalculation();
                    builder.setAlphaFunction(new InterpFadeInOut(0.3f, 0f));
                    builder.setScaleFunction(new InterpScale(0.3f, 0f));
                    ParticleSpawner.spawn(builder, world, new StaticInterp<>(new Vec3d(getPos()).addVector(0.5, 0.5, 0.5)), 2, 0, (aFloat, particleBuilder) -> {
                        particleBuilder.setPositionOffset(new Vec3d(RandUtil.nextDouble(-0.5, 0.5), RandUtil.nextDouble(-0.5, 0.5), RandUtil.nextDouble(-0.5, 0.5)));
                        particleBuilder.setMotion(new Vec3d(RandUtil.nextDouble(-0.1, 0.1), RandUtil.nextDouble(-0.1, 0.1), RandUtil.nextDouble(-0.1, 0.1)));
                    });
                }
            });
    }
}
Also used : InterpScale(com.teamwizardry.wizardry.api.util.interp.InterpScale) ResourceLocation(net.minecraft.util.ResourceLocation) ClientRunnable(com.teamwizardry.librarianlib.features.utilities.client.ClientRunnable) InterpFadeInOut(com.teamwizardry.librarianlib.features.particle.functions.InterpFadeInOut) RandUtilSeed(com.teamwizardry.wizardry.api.util.RandUtilSeed) ParticleBuilder(com.teamwizardry.librarianlib.features.particle.ParticleBuilder) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

RandUtilSeed (com.teamwizardry.wizardry.api.util.RandUtilSeed)4 Vec3d (net.minecraft.util.math.Vec3d)3 ParticleBuilder (com.teamwizardry.librarianlib.features.particle.ParticleBuilder)2 InterpFadeInOut (com.teamwizardry.librarianlib.features.particle.functions.InterpFadeInOut)2 ClientRunnable (com.teamwizardry.librarianlib.features.utilities.client.ClientRunnable)2 InterpScale (com.teamwizardry.wizardry.api.util.interp.InterpScale)2 Entity (net.minecraft.entity.Entity)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 World (net.minecraft.world.World)2 Matrix4 (com.teamwizardry.librarianlib.features.math.Matrix4)1 StaticInterp (com.teamwizardry.librarianlib.features.math.interpolate.StaticInterp)1 ParticleSpawner (com.teamwizardry.librarianlib.features.particle.ParticleSpawner)1 Wizardry (com.teamwizardry.wizardry.Wizardry)1 Constants (com.teamwizardry.wizardry.api.Constants)1 LightningGenerator (com.teamwizardry.wizardry.api.LightningGenerator)1 RandUtil (com.teamwizardry.wizardry.api.util.RandUtil)1 RayTrace (com.teamwizardry.wizardry.api.util.RayTrace)1 LibParticles (com.teamwizardry.wizardry.client.fx.LibParticles)1 ModSounds (com.teamwizardry.wizardry.init.ModSounds)1 java.awt (java.awt)1