Search in sources :

Example 61 with AMVector3

use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.

the class EntitySpellProjectile method entityInit.

//=========================================================================
@Override
protected void entityInit() {
    this.dataWatcher.addObject(DW_BOUNCE_COUNTER, 0);
    this.dataWatcher.addObject(DW_GRAVITY, 0);
    this.dataWatcher.addObject(DW_EFFECT, new ItemStack(ItemsCommonProxy.spell));
    this.dataWatcher.addObject(DW_ICON_NAME, "arcane");
    this.dataWatcher.addObject(DW_PIERCE_COUNT, 0);
    this.dataWatcher.addObject(DW_COLOR, 0xFFFFFF);
    this.dataWatcher.addObject(DW_SHOOTER, 0);
    this.dataWatcher.addObject(DW_TARGETGRASS, (byte) 0);
    this.dataWatcher.addObject(DW_HOMING, (byte) 0);
    this.dataWatcher.addObject(DW_HOMING_TARGET, -1);
    blockhits = new ArrayList<AMVector3>();
    entityHits = new ArrayList<Integer>();
}
Also used : AMVector3(am2.api.math.AMVector3) ItemStack(net.minecraft.item.ItemStack)

Example 62 with AMVector3

use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.

the class EntitySpellProjectile method HitObject.

protected void HitObject(MovingObjectPosition movingobjectposition, boolean pierce) {
    if (movingobjectposition.entityHit != null) {
        if (movingobjectposition.entityHit == getShootingEntity() || getShootingEntity() == null)
            return;
        Entity e = movingobjectposition.entityHit;
        if (e instanceof EntityDragonPart && ((EntityDragonPart) e).entityDragonObj instanceof EntityLivingBase)
            e = (EntityLivingBase) ((EntityDragonPart) e).entityDragonObj;
        if (e instanceof EntityLivingBase && getShootingEntity() != null && !this.entityHits.contains(movingobjectposition.entityHit.getEntityId())) {
            SpellHelper.instance.applyStageToEntity(this.getEffectStack(), getShootingEntity(), this.worldObj, e, 0, true);
            SpellHelper.instance.applyStackStage(SpellUtils.instance.popStackStage(getEffectStack()), getShootingEntity(), (EntityLivingBase) e, movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord, 0, worldObj, false, true, 0);
            this.entityHits.add(movingobjectposition.entityHit.getEntityId());
        }
    } else {
        AMVector3 blockLoc = new AMVector3(movingobjectposition.blockX, movingobjectposition.blockY, movingobjectposition.blockZ);
        if (getShootingEntity() != null && !this.blockhits.contains(blockLoc)) {
            SpellHelper.instance.applyStageToGround(getEffectStack(), getShootingEntity(), worldObj, movingobjectposition.blockX, movingobjectposition.blockY, movingobjectposition.blockZ, movingobjectposition.sideHit, movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord, 0, true);
            SpellHelper.instance.applyStackStage(SpellUtils.instance.popStackStage(getEffectStack()), getShootingEntity(), getShootingEntity(), movingobjectposition.blockX, movingobjectposition.blockY, movingobjectposition.blockZ, movingobjectposition.sideHit, worldObj, false, true, 0);
            this.blockhits.add(blockLoc);
        }
    }
    this.setNumPierces(this.getNumPierces() - 1);
    if (!worldObj.isRemote && !pierce) {
        this.setDead();
    }
}
Also used : Entity(net.minecraft.entity.Entity) AMVector3(am2.api.math.AMVector3) EntityDragonPart(net.minecraft.entity.boss.EntityDragonPart) EntityLivingBase(net.minecraft.entity.EntityLivingBase)

Example 63 with AMVector3

use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.

the class EntitySpellProjectile method onUpdate.

@Override
public void onUpdate() {
    //super.onUpdate();
    if (!worldObj.isRemote && (getShootingEntity() == null || getShootingEntity().isDead)) {
        setDead();
    } else {
        ticksExisted++;
        int maxTicksToLive = maxTicksToExist > -1 ? maxTicksToExist : 100;
        if (ticksExisted >= maxTicksToLive && !worldObj.isRemote) {
            setDead();
            return;
        }
    }
    //TODO Fix homing
    if (this.dataWatcher.getWatchableObjectByte(DW_HOMING) != (byte) 0 && this.ticksExisted > 10) {
        if (this.dataWatcher.getWatchableObjectInt(DW_HOMING_TARGET) == -1) {
            findHomingTarget();
        } else {
            EntityLivingBase homingTarget = getHomingEntity();
            //AMCore.log.info("%.2f, %.2f, %.2f", posX, posY, posZ);
            LogHelper.trace("Homing Target: " + getHomingEntity());
            if (homingTarget != null && new AMVector3(this).distanceSqTo(new AMVector3(homingTarget)) > 2) {
                this.moveTowards(homingTarget, 60, 60);
            }
        }
    }
    Vec3 vec3d = Vec3.createVectorHelper(posX, posY, posZ);
    Vec3 vec3d1 = Vec3.createVectorHelper(posX + motionX, posY + motionY, posZ + motionZ);
    MovingObjectPosition movingobjectposition = null;
    movingobjectposition = worldObj.rayTraceBlocks(vec3d, vec3d1, true);
    vec3d = Vec3.createVectorHelper(posX, posY, posZ);
    vec3d1 = Vec3.createVectorHelper(posX + motionX, posY + motionY, posZ + motionZ);
    if (movingobjectposition != null) {
        vec3d1 = Vec3.createVectorHelper(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord);
    }
    Entity entity = null;
    List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.addCoord(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D));
    double d = 0.0D;
    for (int j = 0; j < list.size(); j++) {
        Entity entity1 = (Entity) list.get(j);
        if (!entity1.canBeCollidedWith() || entity1.isEntityEqual(getShootingEntity())) {
            continue;
        }
        float f2 = 0.3F;
        AxisAlignedBB axisalignedbb = entity1.boundingBox.expand(f2, f2, f2);
        MovingObjectPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec3d, vec3d1);
        if (movingobjectposition1 == null) {
            continue;
        }
        double d1 = vec3d.distanceTo(movingobjectposition1.hitVec);
        if (d1 < d || d == 0.0D) {
            entity = entity1;
            d = d1;
        }
    }
    if (entity != null) {
        if (entity instanceof EntityDragonPart && ((EntityDragonPart) entity).entityDragonObj != null && ((EntityDragonPart) entity).entityDragonObj instanceof EntityLivingBase) {
            entity = (EntityLivingBase) ((EntityDragonPart) entity).entityDragonObj;
        }
        movingobjectposition = new MovingObjectPosition(entity);
    }
    if (movingobjectposition != null) {
        boolean doHit = true;
        boolean pierce = this.getNumPierces() > 0;
        if (movingobjectposition.typeOfHit == MovingObjectType.ENTITY && movingobjectposition.entityHit != null && movingobjectposition.entityHit instanceof EntityLivingBase) {
            EntityLivingBase ent = (EntityLivingBase) movingobjectposition.entityHit;
            if (ent.isPotionActive(BuffList.spellReflect.id) && !pierce) {
                doHit = false;
                this.setShootingEntity(ent);
                this.motionX = -this.motionX;
                this.motionY = -this.motionY;
                this.motionZ = -this.motionZ;
                if (!worldObj.isRemote)
                    ent.removePotionEffect(BuffList.spellReflect.id);
                setBounces(originalBounceCount);
                if (worldObj.isRemote) {
                    for (int i = 0; i < 13; ++i) {
                        AMParticle effect = (AMParticle) AMCore.instance.proxy.particleManager.spawn(worldObj, "hr_lensflare", ent.posX + rand.nextDouble() - 0.5, ent.posY + ent.getEyeHeight() + rand.nextDouble() - 0.5, ent.posZ + rand.nextDouble() - 0.5);
                        if (effect != null) {
                            EntityPlayer player = AMCore.instance.proxy.getLocalPlayer();
                            effect.setIgnoreMaxAge(true);
                            if (player != null && ent != player) {
                                effect.setParticleScale(1.5f);
                            }
                            effect.setRGBColorF(0.5f + rand.nextFloat() * 0.5f, 0.2f, 0.5f + rand.nextFloat() * 0.5f);
                            effect.AddParticleController(new ParticleHoldPosition(effect, 100, 1, false));
                        }
                    }
                }
            }
        } else if (movingobjectposition.typeOfHit == MovingObjectType.BLOCK && getBounces() > 0) {
            doHit = false;
            switch(movingobjectposition.sideHit) {
                case 0:
                case 1:
                    motionY = motionY * friction_coefficient * -1;
                    break;
                case 2:
                case 3:
                    motionZ = motionZ * friction_coefficient * -1;
                    break;
                case 4:
                case 5:
                    motionX = motionX * friction_coefficient * -1;
                    break;
            }
            this.setBounces(getBounces() - 1);
        }
        if (movingobjectposition.typeOfHit == MovingObjectType.BLOCK) {
            Block block = worldObj.getBlock(movingobjectposition.blockX, movingobjectposition.blockY, movingobjectposition.blockZ);
            AxisAlignedBB bb = block.getCollisionBoundingBoxFromPool(worldObj, movingobjectposition.blockX, movingobjectposition.blockY, movingobjectposition.blockZ);
            if (bb == null && !SpellUtils.instance.modifierIsPresent(SpellModifiers.TARGET_NONSOLID_BLOCKS, getEffectStack(), 0))
                doHit = false;
        }
        if (doHit)
            HitObject(movingobjectposition, pierce);
    }
    if (getGravity() < 0 && motionY > GRAVITY_TERMINAL_VELOCITY) {
        this.motionY += getGravity();
    } else if (getGravity() > 0 && motionY < -GRAVITY_TERMINAL_VELOCITY) {
        this.motionY -= getGravity();
    }
    posX += motionX;
    posY += motionY;
    posZ += motionZ;
    float f = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
    rotationYaw = (float) (Math.atan2(motionX, motionZ));
    for (rotationPitch = (float) (Math.atan2(motionY, f)); rotationPitch - prevRotationPitch < -180F; prevRotationPitch -= 360F) {
    }
    for (; rotationPitch - prevRotationPitch >= 180F; prevRotationPitch += 360F) {
    }
    for (; rotationYaw - prevRotationYaw < -180F; prevRotationYaw -= 360F) {
    }
    for (; rotationYaw - prevRotationYaw >= 180F; prevRotationYaw += 360F) {
    }
    rotationPitch = prevRotationPitch + (rotationPitch - prevRotationPitch) * 0.2F;
    rotationYaw = prevRotationYaw + (rotationYaw - prevRotationYaw) * 0.2F;
    float f1 = 0.95F;
    if (isInWater()) {
        for (int k = 0; k < 4; k++) {
            float f3 = 0.25F;
            worldObj.spawnParticle("bubble", posX - motionX * f3, posY - motionY * f3, posZ - motionZ * f3, motionX, motionY, motionZ);
        }
        f1 = 0.8F;
    }
    if (!AMCore.config.NoGFX() && worldObj.isRemote && this.getShootingEntity() instanceof EntityPlayer) {
        if (this.particleType == null || this.particleType.isEmpty())
            particleType = AMParticleIcons.instance.getSecondaryParticleForAffinity(SpellUtils.instance.mainAffinityFor(getEffectStack()));
        AMParticle particle = (AMParticle) AMCore.proxy.particleManager.spawn(worldObj, particleType, this.posX, this.posY, this.posZ);
        if (particle != null) {
            particle.addRandomOffset(0.3f, 0.3f, 0.3f);
            particle.AddParticleController(new ParticleFloatUpward(particle, 0.1f, 0, 1, false));
            particle.setMaxAge(10);
            particle.setParticleScale(0.05f);
        }
    }
    setPosition(posX, posY, posZ);
}
Also used : Entity(net.minecraft.entity.Entity) AMParticle(am2.particles.AMParticle) ParticleHoldPosition(am2.particles.ParticleHoldPosition) ParticleFloatUpward(am2.particles.ParticleFloatUpward) AMVector3(am2.api.math.AMVector3) EntityDragonPart(net.minecraft.entity.boss.EntityDragonPart) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) ArrayList(java.util.ArrayList) BuffList(am2.buffs.BuffList) List(java.util.List)

Example 64 with AMVector3

use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.

the class EntityThrownRock method HitObject.

protected void HitObject(MovingObjectPosition movingobjectposition) {
    if (worldObj.isRemote) {
        return;
    }
    if (getIsShootingStar()) {
        AMNetHandler.INSTANCE.sendStarImpactToClients(posX, posY + ((movingobjectposition.typeOfHit == MovingObjectType.ENTITY) ? -movingobjectposition.entityHit.getEyeHeight() : 1.5f), posZ, worldObj, this.getSpellStack());
        List<EntityLivingBase> ents = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, boundingBox.expand(5, 5, 5));
        for (EntityLivingBase e : ents) {
            if (e == throwingEntity)
                continue;
            if (this.getEntitySenses().canSee(e))
                SpellHelper.instance.attackTargetSpecial(null, e, DamageSources.causeEntityMagicDamage(throwingEntity), damage);
        }
    } else {
        if (movingobjectposition.entityHit != null && movingobjectposition.entityHit instanceof EntityLivingBase) {
            if (movingobjectposition.entityHit == throwingEntity || throwingEntity == null)
                return;
            if (throwingEntity != null) {
                movingobjectposition.entityHit.attackEntityFrom(DamageSource.causeMobDamage(throwingEntity), 10);
            }
        } else if (movingobjectposition.typeOfHit == MovingObjectType.BLOCK) {
            if (this.getIsMoonstoneMeteor()) {
                if (this.target == null) {
                    this.target = new AMVector3(movingobjectposition.hitVec);
                }
                this.worldObj.newExplosion(this, this.target.x, this.target.y, this.target.z, 0.8f, false, AMCore.config.moonstoneMeteorsDestroyTerrain());
                int numOres = rand.nextInt(6) + 1;
                for (int i = 0; i < numOres; ++i) {
                    generateSurfaceOreAtOffset(worldObj, (int) Math.floor(this.target.x), (int) Math.floor(this.target.y), (int) Math.floor(this.target.z), i == 0);
                }
                if (this.worldObj.isRemote) {
                    for (Object player : worldObj.playerEntities) if (((EntityPlayer) player).getDistanceSqToEntity(this) < 4096)
                        CompendiumUnlockHandler.unlockEntry("moonstone_meteors");
                }
            }
        }
    }
    setDead();
}
Also used : AMVector3(am2.api.math.AMVector3) EntityLivingBase(net.minecraft.entity.EntityLivingBase)

Example 65 with AMVector3

use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.

the class EntityAISpellmaking method updateTask.

@Override
public void updateTask() {
    AMVector3 targetLocation = host.getSearchLocation();
    AMVector3 dropLocation = host.getDropLocation();
    AMVector3 hostLocation = new AMVector3(host);
    ItemStack searchItem = host.getSearchItem();
    if (searchItem.getItem() == ItemsCommonProxy.essence && searchItem.getItemDamage() > ItemsCommonProxy.essence.META_MAX) {
        TileEntityCraftingAltar altar = host.getAltarTarget();
        if (altar.switchIsOn())
            return;
        BlockCoord bc = altar.getSwitchLocation();
        if (action_state == 0 && host.getNavigator().noPath()) {
            host.getNavigator().tryMoveToXYZ(altar.xCoord + bc.x, altar.yCoord + bc.y, altar.zCoord + bc.z, MOVE_SPEED);
        } else if (action_state == 0 && hostLocation.distanceSqTo(new AMVector3(altar.xCoord + bc.x, altar.yCoord + bc.y, altar.zCoord + bc.z)) < DISTANCE_THRESHOLD) {
            action_state = 1;
            altar.flipSwitch();
            wait_counter = 0;
        } else if (action_state == 1 && wait_counter < WAIT_TIME) {
            wait_counter++;
        } else if (action_state == 1 && wait_counter >= WAIT_TIME) {
            resetTask();
        }
    } else {
        if (action_state == 0 && host.getNavigator().noPath()) {
            //no item and too far away to grab			
            host.getNavigator().tryMoveToXYZ(targetLocation.x, targetLocation.y, targetLocation.z, MOVE_SPEED);
        } else if (action_state == 0 && hostLocation.distanceSqTo(targetLocation) < DISTANCE_THRESHOLD) {
            host.getNavigator().clearPathEntity();
            TileEntity te = host.worldObj.getTileEntity((int) targetLocation.x, (int) targetLocation.y, (int) targetLocation.z);
            if (te == null || !(te instanceof IInventory)) {
                resetTask();
                return;
            }
            ((IInventory) te).openInventory();
            if (!host.worldObj.isRemote)
                InventoryUtilities.deductFromInventory(((IInventory) te), host.getSearchItem(), 1);
            host.setHeldItem(host.getSearchItem());
            action_state = 1;
        } else if (action_state == 1 && host.getNavigator().noPath() && wait_counter < WAIT_TIME) {
            wait_counter++;
        } else if (action_state == 1 && host.getNavigator().noPath() && wait_counter >= WAIT_TIME) {
            wait_counter = 0;
            TileEntity te = host.worldObj.getTileEntity((int) targetLocation.x, (int) targetLocation.y, (int) targetLocation.z);
            if (te == null || !(te instanceof IInventory)) {
                resetTask();
                return;
            }
            ((IInventory) te).closeInventory();
            host.getNavigator().tryMoveToXYZ(dropLocation.x, dropLocation.y, dropLocation.z, MOVE_SPEED);
        } else if (action_state == 1 && hostLocation.distanceSqTo(dropLocation) < DISTANCE_THRESHOLD) {
            host.getNavigator().clearPathEntity();
            if (!host.worldObj.isRemote) {
                EntityItem droppedItem = host.entityDropItem(host.getSearchItem(), 0f);
                host.setHeldItem(new ItemStack(Items.paper));
            }
            action_state = 2;
        } else if (action_state == 2 && wait_counter < WAIT_TIME) {
            wait_counter++;
        } else if (action_state == 2 && wait_counter >= WAIT_TIME) {
            resetTask();
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) AMVector3(am2.api.math.AMVector3) TileEntityCraftingAltar(am2.blocks.tileentities.TileEntityCraftingAltar) ItemStack(net.minecraft.item.ItemStack) BlockCoord(am2.api.blocks.MultiblockStructureDefinition.BlockCoord) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

AMVector3 (am2.api.math.AMVector3)113 TileEntity (net.minecraft.tileentity.TileEntity)21 EntityPlayer (net.minecraft.entity.player.EntityPlayer)16 EntityLivingBase (net.minecraft.entity.EntityLivingBase)15 ArrayList (java.util.ArrayList)11 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)11 IPowerNode (am2.api.power.IPowerNode)10 Block (net.minecraft.block.Block)9 Entity (net.minecraft.entity.Entity)9 ItemStack (net.minecraft.item.ItemStack)9 NBTTagList (net.minecraft.nbt.NBTTagList)9 IInventory (net.minecraft.inventory.IInventory)8 PowerTypes (am2.api.power.PowerTypes)6 AMParticle (am2.particles.AMParticle)5 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)5 TileEntityCrystalMarker (am2.blocks.tileentities.TileEntityCrystalMarker)4 EntityDragonPart (net.minecraft.entity.boss.EntityDragonPart)4 TileEntityFlickerHabitat (am2.blocks.tileentities.TileEntityFlickerHabitat)3 AMDataWriter (am2.network.AMDataWriter)3 ParticleFloatUpward (am2.particles.ParticleFloatUpward)3