Search in sources :

Example 1 with RayTrace

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

the class ModuleShapeBeam method run.

@Override
public boolean run(@Nonnull SpellData spell, @Nonnull SpellRing spellRing) throws NullPointerException {
    World world = spell.world;
    Vec3d look = spell.getData(LOOK);
    Vec3d position = spell.getOrigin();
    Entity caster = spell.getCaster();
    if (look == null || position == null)
        return false;
    double range = spellRing.getAttributeValue(AttributeRegistry.RANGE, spell);
    double potency = 30 - spellRing.getAttributeValue(AttributeRegistry.POTENCY, spell);
    spellRing.multiplyMultiplierForAll((float) (potency / 25.0 * range / 75.0));
    RayTraceResult trace = new RayTrace(world, look, position, range).setSkipEntity(caster).setReturnLastUncollidableBlock(true).setIgnoreBlocksWithoutBoundingBoxes(true).trace();
    spell.processTrace(trace, look.scale(range));
    sendRenderPacket(spell, spellRing);
    if (spell.world.getTotalWorldTime() % potency == 0) {
        if (spellRing.getChildRing() != null) {
            spellRing.getChildRing().runSpellRing(spell);
        }
    }
    return true;
}
Also used : Entity(net.minecraft.entity.Entity) RayTrace(com.teamwizardry.wizardry.api.util.RayTrace) RayTraceResult(net.minecraft.util.math.RayTraceResult) World(net.minecraft.world.World) Vec3d(net.minecraft.util.math.Vec3d)

Example 2 with RayTrace

use of com.teamwizardry.wizardry.api.util.RayTrace 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 3 with RayTrace

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

the class TileManaInteracter method suckManaFrom.

public boolean suckManaFrom(TileManaInteracter interacterFrom, SuckRule suckRule) {
    if (getWizardryCap() == null || interacterFrom.getWizardryCap() == null)
        return false;
    if (!isAllowOutsideSucking() && interacterFrom.isAllowOutsideSucking())
        return false;
    if (!suckRule.condition.test(this, interacterFrom))
        return false;
    CapManager thisManager = new CapManager(getWizardryCap());
    CapManager theirManager = new CapManager(interacterFrom.getWizardryCap());
    if (thisManager.isManaFull())
        return false;
    if (theirManager.isManaEmpty())
        return false;
    if (suckRule.equalize && Math.abs(thisManager.getMana() - theirManager.getMana()) <= suckRule.idealAmount)
        return false;
    Vec3d thisPos = new Vec3d(getPos()).addVector(0.5, 0.5, 0.5);
    Vec3d theirPos = new Vec3d(interacterFrom.getPos()).addVector(0.5, 0.5, 0.5);
    // DEBUG
    // ParticleBuilder helix = new ParticleBuilder(200);
    // helix.setRender(new ResourceLocation(Wizardry.MODID, Constants.MISC.SPARKLE_BLURRED));
    // helix.setAlphaFunction(new InterpFadeInOut(0.1f, 0.1f));
    // ParticleSpawner.spawn(helix, world, new StaticInterp<>(thisPos), 1, 0, (someFloat, particleBuilder) -> {
    // particleBuilder.setColor(ColorUtils.changeColorAlpha(new Color(0xFF0000), RandUtil.nextInt(50, 200)));
    // particleBuilder.setScale(RandUtil.nextFloat(0.3f, 0.8f));
    // particleBuilder.disableRandom();
    // particleBuilder.setPositionFunction(new InterpLine(Vec3d.ZERO, theirPos.subtract(thisPos)));
    // particleBuilder.setLifetime(RandUtil.nextInt(50, 60));
    // });
    double ratio = theirManager.getMana() / thisManager.getMana();
    if (suckRule.equalize && Double.isFinite(ratio) && ratio <= 1.2)
        return false;
    if (getCachedDistanceSq(interacterFrom) > ConfigValues.networkLinkDistance * ConfigValues.networkLinkDistance)
        return false;
    if (!suckRule.ignoreTrace) {
        Vec3d thisSub = theirPos.subtract(thisPos.add(getOffset()));
        Vec3d thisNorm = thisSub.normalize();
        RayTraceResult trace = new RayTrace(world, thisNorm, thisPos.add(getOffset() == Vec3d.ZERO ? thisNorm : getOffset()), ConfigValues.networkLinkDistance * ConfigValues.networkLinkDistance).setSkipEntities(true).setIgnoreBlocksWithoutBoundingBoxes(true).trace();
        if (!trace.getBlockPos().equals(interacterFrom.getPos()))
            return false;
    }
    double amount = interacterFrom.drainMana(suckRule.idealAmount);
    if (amount <= 0)
        return false;
    thisManager.addMana(amount);
    ClientRunnable.run(new ClientRunnable() {

        @Override
        @SideOnly(Side.CLIENT)
        public void runIfClient() {
            ParticleBuilder helix = new ParticleBuilder(200);
            helix.setRender(new ResourceLocation(Wizardry.MODID, Constants.MISC.SPARKLE_BLURRED));
            helix.setAlphaFunction(new InterpFadeInOut(0.1f, 0.1f));
            ParticleSpawner.spawn(helix, world, new StaticInterp<>(new Vec3d(interacterFrom.getPos()).addVector(0.5, 1, 0.5)), 1, 0, (someFloat, particleBuilder) -> {
                particleBuilder.setColor(ColorUtils.changeColorAlpha(new Color(0x0097FF), RandUtil.nextInt(50, 200)));
                particleBuilder.setScale(RandUtil.nextFloat(0.3f, 0.8f));
                particleBuilder.setPositionFunction(new InterpBezier3D(Vec3d.ZERO, new Vec3d(getPos().subtract(interacterFrom.getPos())), new Vec3d(0, 5, 0), new Vec3d(0, -5, 0)));
                particleBuilder.setLifetime(RandUtil.nextInt(50, 60));
            });
        }
    });
    return true;
}
Also used : CapManager(com.teamwizardry.wizardry.api.capability.CapManager) java.util(java.util) 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) RayTraceResult(net.minecraft.util.math.RayTraceResult) BiPredicate(java.util.function.BiPredicate) Module(com.teamwizardry.librarianlib.features.saving.Module) Vec3d(net.minecraft.util.math.Vec3d) Side(net.minecraftforge.fml.relauncher.Side) ITickable(net.minecraft.util.ITickable) TilePearlHolder(com.teamwizardry.wizardry.common.tile.TilePearlHolder) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Nonnull(javax.annotation.Nonnull) Save(com.teamwizardry.librarianlib.features.saving.Save) Nullable(javax.annotation.Nullable) ConfigValues(com.teamwizardry.wizardry.api.ConfigValues) InterpBezier3D(com.teamwizardry.librarianlib.features.math.interpolate.position.InterpBezier3D) TileCraftingPlate(com.teamwizardry.wizardry.common.tile.TileCraftingPlate) ClientRunnable(com.teamwizardry.librarianlib.features.utilities.client.ClientRunnable) IWizardryCapability(com.teamwizardry.wizardry.api.capability.IWizardryCapability) Wizardry(com.teamwizardry.wizardry.Wizardry) TileMod(com.teamwizardry.librarianlib.features.base.block.tile.TileMod) RayTrace(com.teamwizardry.wizardry.api.util.RayTrace) BlockPos(net.minecraft.util.math.BlockPos) ColorUtils(com.teamwizardry.wizardry.api.util.ColorUtils) CustomWizardryCapability(com.teamwizardry.wizardry.api.capability.CustomWizardryCapability) java.awt(java.awt) ManaModule(com.teamwizardry.wizardry.api.capability.ManaModule) TileManaBattery(com.teamwizardry.wizardry.common.tile.TileManaBattery) MathHelper(net.minecraft.util.math.MathHelper) ResourceLocation(net.minecraft.util.ResourceLocation) RandUtil(com.teamwizardry.wizardry.api.util.RandUtil) Constants(com.teamwizardry.wizardry.api.Constants) RayTraceResult(net.minecraft.util.math.RayTraceResult) 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) Vec3d(net.minecraft.util.math.Vec3d) CapManager(com.teamwizardry.wizardry.api.capability.CapManager) RayTrace(com.teamwizardry.wizardry.api.util.RayTrace) ResourceLocation(net.minecraft.util.ResourceLocation) InterpBezier3D(com.teamwizardry.librarianlib.features.math.interpolate.position.InterpBezier3D)

Example 4 with RayTrace

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

the class EntitySpellProjectile method onUpdate.

@Override
public void onUpdate() {
    super.onUpdate();
    if (world.isRemote)
        return;
    if (spellRing == null || spellData == null) {
        setDead();
        world.removeEntity(this);
        return;
    }
    Vec3d origin = spellData.getOrigin();
    rotationPitch = spellData.getData(PITCH, 0F);
    rotationYaw = spellData.getData(YAW, 0F);
    Vec3d look = spellData.getData(LOOK);
    if (look == null) {
        setDead();
        world.removeEntity(this);
        return;
    }
    if (origin == null || dist < getDistance(origin.x, origin.y, origin.z)) {
        spellData.processBlock(getPosition(), EnumFacing.getFacingFromVector((float) look.x, (float) look.y, (float) look.z), getPositionVector());
        goBoom(spellData);
        return;
    }
    if (isDead)
        return;
    if (!collided) {
        // MOVE //
        motionX += ((look.x * speed) - motionX);
        motionY += ((look.y * speed) - motionY);
        motionZ += ((look.z * speed) - motionZ);
        // GRAVITY
        // if (getDistanceSq(origin.x, origin.y, origin.z) > 4)
        // motionY -= gravity;
        move(MoverType.SELF, motionX, motionY, motionZ);
    } else {
        RayTraceResult result = new RayTrace(world, look, getPositionVector(), 5).setSkipEntity(this).trace();
        spellData.processTrace(result, getPositionVector());
        goBoom(spellData);
        return;
    }
    List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(this, getEntityBoundingBox());
    if (!entities.isEmpty()) {
        Entity caster = spellData.getCaster();
        // Don't collide with other spell projectiles
        for (Entity entity : entities) {
            if (entity == caster)
                return;
            if (entity instanceof EntitySpellProjectile)
                return;
        }
        RayTraceResult result = new RayTrace(world, look, getPositionVector(), 1).setSkipEntity(this).trace();
        spellData.processTrace(result, getPositionVector());
        goBoom(spellData);
    }
}
Also used : Entity(net.minecraft.entity.Entity) RayTrace(com.teamwizardry.wizardry.api.util.RayTrace) RayTraceResult(net.minecraft.util.math.RayTraceResult) Vec3d(net.minecraft.util.math.Vec3d)

Example 5 with RayTrace

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

the class ModuleEffectZoom method run.

@Override
public boolean run(@Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
    World world = spell.world;
    Entity entityHit = spell.getVictim();
    Vec3d look = spell.getData(LOOK);
    Vec3d origin = spell.getData(ORIGIN);
    if (entityHit == null)
        return true;
    else {
        if (!spellRing.taxCaster(spell))
            return false;
        if (look == null)
            return true;
        if (origin == null)
            return true;
        double range = spellRing.getAttributeValue(AttributeRegistry.RANGE, spell);
        RayTraceResult trace = new RayTrace(world, look, origin, range).setSkipEntity(entityHit).setIgnoreBlocksWithoutBoundingBoxes(true).setReturnLastUncollidableBlock(false).trace();
        spell.addData(ORIGINAL_LOC, entityHit.getPositionVector());
        entityHit.setPositionAndUpdate(trace.hitVec.x, trace.hitVec.y, trace.hitVec.z);
        entityHit.motionX = 0;
        entityHit.motionY = 0;
        entityHit.motionZ = 0;
        entityHit.velocityChanged = true;
    }
    if (entityHit instanceof EntityLivingBase) {
        ((EntityLivingBase) entityHit).addPotionEffect(new PotionEffect(ModPotions.NULLIFY_GRAVITY, 5, 1, true, false));
        ((EntityLivingBase) entityHit).addPotionEffect(new PotionEffect(ModPotions.NULL_MOVEMENT, 5, 1, true, false));
    }
    return true;
}
Also used : Entity(net.minecraft.entity.Entity) PotionEffect(net.minecraft.potion.PotionEffect) RayTrace(com.teamwizardry.wizardry.api.util.RayTrace) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityLivingBase(net.minecraft.entity.EntityLivingBase) World(net.minecraft.world.World) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

RayTrace (com.teamwizardry.wizardry.api.util.RayTrace)8 RayTraceResult (net.minecraft.util.math.RayTraceResult)8 Vec3d (net.minecraft.util.math.Vec3d)8 Entity (net.minecraft.entity.Entity)7 World (net.minecraft.world.World)5 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 BlockPos (net.minecraft.util.math.BlockPos)2 TileMod (com.teamwizardry.librarianlib.features.base.block.tile.TileMod)1 StaticInterp (com.teamwizardry.librarianlib.features.math.interpolate.StaticInterp)1 InterpBezier3D (com.teamwizardry.librarianlib.features.math.interpolate.position.InterpBezier3D)1 ParticleBuilder (com.teamwizardry.librarianlib.features.particle.ParticleBuilder)1 ParticleSpawner (com.teamwizardry.librarianlib.features.particle.ParticleSpawner)1 InterpFadeInOut (com.teamwizardry.librarianlib.features.particle.functions.InterpFadeInOut)1 Module (com.teamwizardry.librarianlib.features.saving.Module)1 Save (com.teamwizardry.librarianlib.features.saving.Save)1 ClientRunnable (com.teamwizardry.librarianlib.features.utilities.client.ClientRunnable)1 Wizardry (com.teamwizardry.wizardry.Wizardry)1 ConfigValues (com.teamwizardry.wizardry.api.ConfigValues)1 Constants (com.teamwizardry.wizardry.api.Constants)1 LightningGenerator (com.teamwizardry.wizardry.api.LightningGenerator)1