Search in sources :

Example 46 with Vec3

use of net.minecraft.util.Vec3 in project ArsMagica2 by Mithion.

the class Beam method beginStackStage.

@Override
public SpellCastResult beginStackStage(ItemSpellBase item, ItemStack stack, EntityLivingBase caster, EntityLivingBase target, World world, double x, double y, double z, int side, boolean giveXP, int useCount) {
    boolean shouldApplyEffect = useCount % 10 == 0;
    double range = SpellUtils.instance.getModifiedDouble_Add(SpellModifiers.RANGE, stack, caster, target, world, 0);
    boolean targetWater = SpellUtils.instance.modifierIsPresent(SpellModifiers.TARGET_NONSOLID_BLOCKS, stack, 0);
    MovingObjectPosition mop = item.getMovingObjectPosition(caster, world, range, true, targetWater);
    SpellCastResult result = null;
    Vec3 beamHitVec = null;
    Vec3 spellVec = null;
    if (mop == null) {
        beamHitVec = MathUtilities.extrapolateEntityLook(world, caster, range);
        spellVec = beamHitVec;
    } else if (mop.typeOfHit == MovingObjectType.ENTITY) {
        if (shouldApplyEffect) {
            Entity e = mop.entityHit;
            if (e instanceof EntityDragonPart && ((EntityDragonPart) e).entityDragonObj instanceof EntityLivingBase)
                e = (EntityLivingBase) ((EntityDragonPart) e).entityDragonObj;
            result = SpellHelper.instance.applyStageToEntity(stack, caster, world, e, 0, giveXP);
            if (result != SpellCastResult.SUCCESS) {
                return result;
            }
        }
        float rng = (float) mop.hitVec.distanceTo(Vec3.createVectorHelper(caster.posX, caster.posY, caster.posZ));
        beamHitVec = MathUtilities.extrapolateEntityLook(world, caster, rng);
        spellVec = beamHitVec;
    } else {
        if (shouldApplyEffect) {
            result = SpellHelper.instance.applyStageToGround(stack, caster, world, mop.blockX, mop.blockY, mop.blockZ, mop.sideHit, mop.hitVec.xCoord, mop.hitVec.yCoord, mop.hitVec.zCoord, 0, giveXP);
            if (result != SpellCastResult.SUCCESS) {
                return result;
            }
        }
        beamHitVec = mop.hitVec;
        spellVec = Vec3.createVectorHelper(mop.blockX, mop.blockY, mop.blockZ);
    }
    if (world.isRemote && beamHitVec != null) {
        AMBeam beam = (AMBeam) beams.get(caster.getEntityId());
        double startX = caster.posX;
        double startY = caster.posY + caster.getEyeHeight() - 0.2f;
        double startZ = caster.posZ;
        Affinity affinity = SpellUtils.instance.mainAffinityFor(stack);
        int color = -1;
        if (SpellUtils.instance.modifierIsPresent(SpellModifiers.COLOR, stack, 0)) {
            ISpellModifier[] mods = SpellUtils.instance.getModifiersForStage(stack, 0);
            int ordinalCount = 0;
            for (ISpellModifier mod : mods) {
                if (mod instanceof Colour) {
                    byte[] meta = SpellUtils.instance.getModifierMetadataFromStack(stack, mod, 0, ordinalCount++);
                    color = (int) mod.getModifier(SpellModifiers.COLOR, null, null, null, meta);
                }
            }
        }
        if (beam != null) {
            if (beam.isDead || beam.getDistanceSqToEntity(caster) > 4) {
                beams.remove(caster.getEntityId());
            } else {
                beam.setBeamLocationAndTarget(startX, startY, startZ, beamHitVec.xCoord, beamHitVec.yCoord, beamHitVec.zCoord);
            }
        } else {
            if (affinity == Affinity.LIGHTNING) {
                AMCore.instance.proxy.particleManager.BoltFromEntityToPoint(world, caster, beamHitVec.xCoord, beamHitVec.yCoord, beamHitVec.zCoord, 1, color == -1 ? affinity.color : color);
            } else {
                beam = (AMBeam) AMCore.instance.proxy.particleManager.BeamFromEntityToPoint(world, caster, beamHitVec.xCoord, beamHitVec.yCoord, beamHitVec.zCoord, color == -1 ? affinity.color : color);
                if (beam != null) {
                    if (AMCore.instance.proxy.getProxyUtils().isLocalPlayerInFirstPerson())
                        beam.setFirstPersonPlayerCast();
                    beams.put(caster.getEntityId(), beam);
                }
            }
        }
        for (int i = 0; i < AMCore.config.getGFXLevel() + 1; ++i) {
            AMParticle particle = (AMParticle) AMCore.proxy.particleManager.spawn(world, AMParticleIcons.instance.getParticleForAffinity(affinity), beamHitVec.xCoord, beamHitVec.yCoord, beamHitVec.zCoord);
            if (particle != null) {
                particle.setMaxAge(2);
                particle.setParticleScale(0.1f);
                particle.setIgnoreMaxAge(false);
                if (color != -1)
                    particle.setRGBColorI(color);
                particle.AddParticleController(new ParticleMoveOnHeading(particle, world.rand.nextDouble() * 360, world.rand.nextDouble() * 360, world.rand.nextDouble() * 0.2 + 0.02f, 1, false));
            }
        }
    }
    if (result != null && spellVec != null && shouldApplyEffect) {
        ItemStack newItemStack = SpellUtils.instance.popStackStage(stack);
        return SpellHelper.instance.applyStackStage(newItemStack, caster, target, spellVec.xCoord, spellVec.yCoord, spellVec.zCoord, mop != null ? mop.sideHit : 0, world, true, giveXP, 0);
    } else {
        return SpellCastResult.SUCCESS_REDUCE_MANA;
    }
}
Also used : Entity(net.minecraft.entity.Entity) AMParticle(am2.particles.AMParticle) ISpellModifier(am2.api.spell.component.interfaces.ISpellModifier) Colour(am2.spell.modifiers.Colour) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) EntityDragonPart(net.minecraft.entity.boss.EntityDragonPart) Vec3(net.minecraft.util.Vec3) EntityLivingBase(net.minecraft.entity.EntityLivingBase) SpellCastResult(am2.api.spell.enums.SpellCastResult) Affinity(am2.api.spell.enums.Affinity) AMBeam(am2.particles.AMBeam) ItemStack(net.minecraft.item.ItemStack) ParticleMoveOnHeading(am2.particles.ParticleMoveOnHeading)

Example 47 with Vec3

use of net.minecraft.util.Vec3 in project ArsMagica2 by Mithion.

the class AMEventHandler method onEntityJump.

@SubscribeEvent
public void onEntityJump(LivingJumpEvent event) {
    if (event.entityLiving.isPotionActive(BuffList.agility.id)) {
        event.entityLiving.motionY *= 1.5f;
    }
    if (event.entityLiving.isPotionActive(BuffList.leap.id)) {
        Entity velocityTarget = event.entityLiving;
        if (event.entityLiving.ridingEntity != null) {
            if (event.entityLiving.ridingEntity instanceof EntityMinecart) {
                event.entityLiving.ridingEntity.setPosition(event.entityLiving.ridingEntity.posX, event.entityLiving.ridingEntity.posY + 1.5, event.entityLiving.ridingEntity.posZ);
            }
            velocityTarget = event.entityLiving.ridingEntity;
        }
        double yVelocity = 0;
        double xVelocity = 0;
        double zVelocity = 0;
        Vec3 vec = event.entityLiving.getLookVec().normalize();
        switch(event.entityLiving.getActivePotionEffect(BuffList.leap).getAmplifier() + 1) {
            case BuffPowerLevel.Low:
                yVelocity = 0.4;
                xVelocity = velocityTarget.motionX * 1.08 * Math.abs(vec.xCoord);
                zVelocity = velocityTarget.motionZ * 1.08 * Math.abs(vec.zCoord);
                break;
            case BuffPowerLevel.Medium:
                yVelocity = 0.7;
                xVelocity = velocityTarget.motionX * 1.25 * Math.abs(vec.xCoord);
                zVelocity = velocityTarget.motionZ * 1.25 * Math.abs(vec.zCoord);
                break;
            case BuffPowerLevel.High:
                yVelocity = 1;
                xVelocity = velocityTarget.motionX * 1.75 * Math.abs(vec.xCoord);
                zVelocity = velocityTarget.motionZ * 1.75 * Math.abs(vec.zCoord);
                break;
            default:
                break;
        }
        float maxHorizontalVelocity = 1.45f;
        if (event.entityLiving.ridingEntity != null && (event.entityLiving.ridingEntity instanceof EntityMinecart || event.entityLiving.ridingEntity instanceof EntityBoat) || event.entityLiving.isPotionActive(BuffList.haste.id)) {
            maxHorizontalVelocity += 25;
            xVelocity *= 2.5;
            zVelocity *= 2.5;
        }
        if (xVelocity > maxHorizontalVelocity) {
            xVelocity = maxHorizontalVelocity;
        } else if (xVelocity < -maxHorizontalVelocity) {
            xVelocity = -maxHorizontalVelocity;
        }
        if (zVelocity > maxHorizontalVelocity) {
            zVelocity = maxHorizontalVelocity;
        } else if (zVelocity < -maxHorizontalVelocity) {
            zVelocity = -maxHorizontalVelocity;
        }
        if (ExtendedProperties.For(event.entityLiving).getIsFlipped()) {
            yVelocity *= -1;
        }
        velocityTarget.addVelocity(xVelocity, yVelocity, zVelocity);
    }
    if (event.entityLiving.isPotionActive(BuffList.entangled.id)) {
        event.entityLiving.motionY = 0;
    }
    if (event.entityLiving instanceof EntityPlayer) {
        ItemStack boots = ((EntityPlayer) event.entityLiving).inventory.armorInventory[0];
        if (boots != null && boots.getItem() == ItemsCommonProxy.enderBoots && event.entityLiving.isSneaking()) {
            ExtendedProperties.For(event.entityLiving).toggleFlipped();
        }
        if (ExtendedProperties.For(event.entityLiving).getFlipRotation() > 0)
            ((EntityPlayer) event.entityLiving).addVelocity(0, -2 * event.entityLiving.motionY, 0);
    }
}
Also used : Vec3(net.minecraft.util.Vec3) EntityBoat(net.minecraft.entity.item.EntityBoat) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) EntityMinecart(net.minecraft.entity.item.EntityMinecart) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 48 with Vec3

use of net.minecraft.util.Vec3 in project ArsMagica2 by Mithion.

the class TileEntitySlipstreamGenerator method playerIsValid.

private boolean playerIsValid(EntityPlayer player) {
    if (player == null || player.isDead)
        return false;
    float tolerance = 0.2f;
    AxisAlignedBB bb = AxisAlignedBB.getBoundingBox(xCoord - tolerance, yCoord + 1, zCoord - tolerance, xCoord + 1 + tolerance, yCoord + 1 + this.EFFECT_HEIGHT, zCoord + 1 + tolerance);
    Vec3 myLoc = Vec3.createVectorHelper(xCoord + 0.5, yCoord + 1, zCoord + 0.5);
    Vec3 playerLoc = Vec3.createVectorHelper(player.posX, player.posY, player.posZ);
    return bb.intersectsWith(player.boundingBox) && worldObj.rayTraceBlocks(myLoc, playerLoc, true) == null;
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) Vec3(net.minecraft.util.Vec3)

Example 49 with Vec3

use of net.minecraft.util.Vec3 in project ArsMagica2 by Mithion.

the class EntityManaVortex method onUpdate.

@Override
public void onUpdate() {
    this.ticksExisted++;
    this.rotation += 5;
    if (!this.worldObj.isRemote && (this.isDead || this.ticksExisted >= getTicksToExist())) {
        this.setDead();
        return;
    }
    if (this.getTicksToExist() - this.ticksExisted <= 20) {
        this.scale -= 1f / 20f;
    } else if (this.scale < 0.99f) {
        this.scale = (float) (Math.sin((float) this.ticksExisted / 50));
    }
    if (getTicksToExist() - this.ticksExisted <= 5 && !hasGoneBoom) {
        hasGoneBoom = true;
        if (!worldObj.isRemote) {
            List players = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, this.boundingBox.expand(3 + Math.floor(this.ticksExisted / 50), 2, 3 + Math.floor(this.ticksExisted / 50)));
            float damage = this.dataWatcher.getWatchableObjectFloat(DW_MANA_STOLEN) * 0.005f;
            if (damage > 100)
                damage = 100;
            Object[] playerArray = players.toArray();
            for (Object o : playerArray) {
                EntityLivingBase e = (EntityLivingBase) o;
                MovingObjectPosition mop = this.worldObj.rayTraceBlocks(Vec3.createVectorHelper(this.posX, this.posY, this.posZ), Vec3.createVectorHelper(e.posX, e.posY + e.getEyeHeight(), e.posZ), false);
                if (mop == null)
                    e.attackEntityFrom(DamageSources.causeEntityPhysicalDamage(this), damage);
            }
        } else {
            for (int i = 0; i < 360; i += AMCore.config.FullGFX() ? 5 : AMCore.config.LowGFX() ? 10 : 20) {
                AMParticle effect = (AMParticle) AMCore.instance.proxy.particleManager.spawn(worldObj, "ember", this.posX, this.posY, this.posZ);
                if (effect != null) {
                    effect.setIgnoreMaxAge(true);
                    effect.AddParticleController(new ParticleMoveOnHeading(effect, i, 0, 0.7f, 1, false));
                    effect.setRGBColorF(0.24f, 0.24f, 0.8f);
                    effect.noClip = false;
                    effect.AddParticleController(new ParticleFadeOut(effect, 1, false).setFadeSpeed(0.05f).setKillParticleOnFinish(true));
                    effect.AddParticleController(new ParticleLeaveParticleTrail(effect, "ember", false, 5, 1, false).addControllerToParticleList(new ParticleMoveOnHeading(effect, i, 0, 0.1f, 1, false)).addControllerToParticleList(new ParticleFadeOut(effect, 1, false).setFadeSpeed(0.1f).setKillParticleOnFinish(true)).setParticleRGB_F(0.24f, 0.24f, 0.8f).addRandomOffset(0.2f, 0.2f, 0.2f));
                }
            }
        }
    }
    if (getTicksToExist() - this.ticksExisted > 30) {
        //get all players within 5 blocks
        List<EntityLivingBase> players = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, this.boundingBox.expand(3 + Math.floor(this.ticksExisted / 50), 2, 3 + Math.floor(this.ticksExisted / 50)));
        Object[] playerArray = players.toArray();
        Vec3 thisPos = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
        for (Object o : playerArray) {
            EntityLivingBase e = (EntityLivingBase) o;
            MovingObjectPosition mop = this.worldObj.rayTraceBlocks(Vec3.createVectorHelper(this.posX, this.posY, this.posZ), Vec3.createVectorHelper(e.posX, e.posY + e.getEyeHeight(), e.posZ), false);
            if (mop != null)
                continue;
            Vec3 playerPos = Vec3.createVectorHelper(e.posX, e.posY + e.getEyeHeight(), e.posZ);
            if (worldObj.isRemote) {
                if (AMCore.config.NoGFX()) {
                    break;
                }
                if (AMCore.config.LowGFX() && (this.ticksExisted % 4) != 0) {
                    break;
                }
                AMParticle effect = (AMParticle) AMCore.instance.proxy.particleManager.spawn(worldObj, "ember", e.posX, e.posY + (e.getEyeHeight() / 2), e.posZ);
                if (effect != null) {
                    effect.AddParticleController(new ParticleArcToEntity(effect, 1, this, false).generateControlPoints().setKillParticleOnFinish(true));
                    effect.setRGBColorF(0.24f, 0.24f, 0.8f);
                    effect.setIgnoreMaxAge(true);
                }
            }
            float manaStolen = ExtendedProperties.For(e).getMaxMana() * 0.01f;
            float curMana = ExtendedProperties.For(e).getCurrentMana();
            if (manaStolen > curMana)
                manaStolen = curMana;
            this.dataWatcher.updateObject(DW_MANA_STOLEN, this.dataWatcher.getWatchableObjectFloat(DW_MANA_STOLEN) + manaStolen);
            ExtendedProperties.For(e).setCurrentMana(ExtendedProperties.For(e).getCurrentMana() - manaStolen);
            AMVector3 movement = MathUtilities.GetMovementVectorBetweenEntities(e, this);
            float speed = -0.075f;
            e.addVelocity(movement.x * speed, movement.y * speed, movement.z * speed);
        }
    }
}
Also used : AMVector3(am2.api.math.AMVector3) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) Vec3(net.minecraft.util.Vec3) EntityLivingBase(net.minecraft.entity.EntityLivingBase) List(java.util.List)

Example 50 with Vec3

use of net.minecraft.util.Vec3 in project ArsMagica2 by Mithion.

the class JumpBoost method applyEffect.

@Override
public boolean applyEffect(EntityPlayer player, World world, ItemStack stack, ImbuementApplicationTypes matchedType, Object... params) {
    if (matchedType == ImbuementApplicationTypes.ON_JUMP) {
        Vec3 vec = player.getLookVec().normalize();
        double yVelocity = 1;
        double xVelocity = player.motionX * 3.5 * Math.abs(vec.xCoord);
        double zVelocity = player.motionZ * 3.5 * Math.abs(vec.zCoord);
        float maxHorizontalVelocity = 1.45f;
        if (ExtendedProperties.For(player).getIsFlipped()) {
            yVelocity *= -1;
        }
        player.addVelocity(xVelocity, yVelocity, zVelocity);
    } else if (matchedType == ImbuementApplicationTypes.ON_TICK) {
        ExtendedProperties.For(player).setFallProtection(20);
    }
    return true;
}
Also used : Vec3(net.minecraft.util.Vec3)

Aggregations

Vec3 (net.minecraft.util.Vec3)58 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)19 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)12 Entity (net.minecraft.entity.Entity)11 EntityPlayer (net.minecraft.entity.player.EntityPlayer)11 ItemStack (net.minecraft.item.ItemStack)7 ArrayList (java.util.ArrayList)5 Random (java.util.Random)5 EntityItem (net.minecraft.entity.item.EntityItem)5 TileEntity (net.minecraft.tileentity.TileEntity)5 List (java.util.List)4 Block (net.minecraft.block.Block)4 EntityLivingBase (net.minecraft.entity.EntityLivingBase)4 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)4 ChunkPosition (net.minecraft.world.ChunkPosition)3 World (net.minecraft.world.World)3 Linear (com.microsoft.Malmo.Schemas.AnimationDecorator.Linear)2 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)2 IBlockState (net.minecraft.block.state.IBlockState)2 BlockPos (net.minecraft.util.BlockPos)2