Search in sources :

Example 36 with AMVector3

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

the class AffinityHelper method onEntityLivingBase.

@SubscribeEvent
public void onEntityLivingBase(LivingUpdateEvent event) {
    EntityLivingBase ent = event.entityLiving;
    if (ent instanceof EntityEnderman) {
        if (ent.getLastAttacker() != ent.getAITarget() && ent.getAITarget() instanceof EntityPlayer) {
            AffinityData affinityData = AffinityData.For(ent.getAITarget());
            float enderDepth = affinityData.getAffinityDepth(Affinity.ENDER);
            if (enderDepth == 1.0f) {
                ent.setRevengeTarget(null);
            }
        }
    }
    if (!(ent instanceof EntityPlayer))
        return;
    AffinityData affinityData = AffinityData.For(ent);
    affinityData.tickDiminishingReturns();
    float waterDepth = affinityData.getAffinityDepth(Affinity.WATER);
    float fireDepth = affinityData.getAffinityDepth(Affinity.FIRE);
    float natureDepth = affinityData.getAffinityDepth(Affinity.NATURE);
    float iceDepth = affinityData.getAffinityDepth(Affinity.ICE);
    float lifeDepth = affinityData.getAffinityDepth(Affinity.LIFE);
    float enderDepth = affinityData.getAffinityDepth(Affinity.ENDER);
    float lightningDepth = affinityData.getAffinityDepth(Affinity.LIGHTNING);
    AffinityModifiers.instance.applySpeedModifiersBasedOnDepth((EntityPlayer) ent, natureDepth, iceDepth, lightningDepth);
    AffinityModifiers.instance.applyHealthModifiers((EntityPlayer) ent, enderDepth, waterDepth, fireDepth, lightningDepth);
    applyFulmintion((EntityPlayer) ent, lightningDepth);
    if (lightningDepth >= 0.5f) {
        ent.stepHeight = 1.014f;
    } else if (ent.stepHeight == 1.014f) {
        ent.stepHeight = 0.5f;
    }
    affinityData.accumulatedLifeRegen += 0.025 * lifeDepth;
    if (affinityData.accumulatedLifeRegen > 1.0f) {
        affinityData.accumulatedLifeRegen -= 1.0f;
        ent.heal(1);
    }
    if (natureDepth == 1.0f) {
        if (ent.worldObj.canBlockSeeTheSky((int) ent.posX, (int) ent.posY, (int) ent.posZ) && ent.worldObj.isDaytime()) {
            affinityData.accumulatedHungerRegen += 0.02f;
            if (affinityData.accumulatedHungerRegen > 1.0f) {
                ((EntityPlayer) ent).getFoodStats().addStats(1, 0.025f);
                affinityData.accumulatedHungerRegen -= 1;
            }
        } else {
            ((EntityPlayer) ent).addExhaustion(0.025f);
        }
        if (ent.isCollidedHorizontally) {
            if (!ent.isSneaking()) {
                float movement = ExtendedProperties.For(ent).getIsFlipped() ? -0.25f : 0.25f;
                ent.moveEntity(0, movement, 0);
                ent.motionY = 0;
            } else {
                ent.motionY *= 0.79999999;
            }
            ent.fallDistance = 0;
        }
    }
    // Ender Affinity
    if (enderDepth >= 0.75f && affinityData.hasActivatedNightVision()) {
        if (!ent.worldObj.isRemote && (!ent.isPotionActive(Potion.nightVision.id) || ent.getActivePotionEffect(Potion.nightVision).getDuration() <= 220)) {
            ent.addPotionEffect(new PotionEffect(Potion.nightVision.id, 300, 1));
        }
    }
    if (ent.onGround)
        affinityData.setLastGroundPosition(new AMVector3(ent));
    affinityData.tickCooldown();
    if (ent.isInWater()) {
        float earthDepth = affinityData.getAffinityDepth(Affinity.EARTH);
        if (earthDepth > 0.25f && ent.motionY > -0.3f) {
            ent.addVelocity(0, -0.01f * earthDepth, 0);
        }
        if (waterDepth > 0.5f) {
            if (!ent.isPotionActive(BuffList.swiftSwim.id) || ent.getActivePotionEffect(BuffList.swiftSwim).getDuration() < 10) {
                ent.addPotionEffect(new BuffEffectSwiftSwim(100, waterDepth > 0.75f ? 2 : 1));
            }
        }
        if (waterDepth > 0.4 && ent.worldObj.rand.nextInt(20) < 4)
            ent.setAir(ent.getAir() + 1);
        if (!ent.worldObj.isRemote && ent.worldObj.rand.nextInt(100) < 5) {
            ent.setAir(ent.getAir() + 1);
            byte[] data = new AMDataWriter().add(ent.getEntityId()).add(ent.getAir()).generate();
            AMNetHandler.INSTANCE.sendPacketToClientPlayer((EntityPlayerMP) ent, AMPacketIDs.SYNC_AIR_CHANGE, data);
        }
        boolean waterMovementFlag = false;
        if ((ent instanceof EntityPlayer && ((EntityPlayer) ent).inventory.armorInventory[1] != null && ((EntityPlayer) ent).inventory.armorInventory[1].getItem() == ItemsCommonProxy.waterGuardianOrbs)) {
            waterMovementFlag = true;
            if (!ent.worldObj.isRemote && (!ent.isPotionActive(BuffList.waterBreathing) || ent.getActivePotionEffect(BuffList.waterBreathing).getDuration() <= 200))
                ent.addPotionEffect(new BuffEffectWaterBreathing(400, 2));
        }
        if (waterDepth > 0.5f || waterMovementFlag) {
            applyReverseWaterMovement(ent);
        }
    }
    if (ent.worldObj.isRaining() && !ent.worldObj.isRemote && ent.worldObj.getBiomeGenForCoords((int) Math.floor(ent.posX), (int) Math.floor(ent.posZ)).canSpawnLightningBolt()) {
        float airDepth = affinityData.getAffinityDepth(Affinity.AIR);
        if (airDepth > 0.5f && airDepth < 0.85f && !ent.worldObj.isRemote && ent.worldObj.rand.nextInt(100) < 10) {
            if (!ent.isSneaking() && !ent.isPotionActive(BuffList.gravityWell) && !ent.isInsideOfMaterial(Material.water) && ent.isWet()) {
                double velX = ent.worldObj.rand.nextDouble() - 0.5;
                double velY = ent.worldObj.rand.nextDouble() - 0.5;
                double velZ = ent.worldObj.rand.nextDouble() - 0.5;
                ent.addVelocity(velX, velY, velZ);
                AMNetHandler.INSTANCE.sendVelocityAddPacket(ent.worldObj, ent, velX, velY, velZ);
            }
        }
    }
    if (ent.isSneaking()) {
        if (iceDepth >= 0.5f) {
            makeIceBridge((EntityPlayer) ent, iceDepth);
        }
    }
}
Also used : PotionEffect(net.minecraft.potion.PotionEffect) AffinityData(am2.playerextensions.AffinityData) AMDataWriter(am2.network.AMDataWriter) AMVector3(am2.api.math.AMVector3) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityEnderman(net.minecraft.entity.monster.EntityEnderman) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 37 with AMVector3

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

the class AffinityHelper method makeIceBridge.

private void makeIceBridge(EntityPlayer ent, float iceDepth) {
    AMVector3[] blocks = MathUtilities.GetHorizontalBlocksInFrontOfCharacter(ent, 1, (int) Math.round(ent.posX), (int) Math.floor(ent.posY) - 1, (int) Math.round(ent.posZ));
    for (int i = 0; i < blocks.length; ++i) {
        AMVector3 current = blocks[i];
        for (int n = -1; n <= 1; ++n) {
            for (int p = -1; p <= 1; ++p) {
                Block block = ent.worldObj.getBlock((int) current.x + n, (int) current.y, (int) current.z + p);
                if (iceDepth == 1.0f && block == Blocks.lava)
                    ent.worldObj.setBlock((int) current.x + n, (int) current.y, (int) current.z + p, Blocks.obsidian);
                else if (iceDepth == 1.0f && block == Blocks.flowing_lava)
                    ent.worldObj.setBlock((int) current.x + n, (int) current.y, (int) current.z + p, Blocks.cobblestone);
                else if (block == Blocks.water)
                    ent.worldObj.setBlock((int) current.x + n, (int) current.y, (int) current.z + p, Blocks.ice);
                else if (block == Blocks.flowing_water)
                    ent.worldObj.setBlock((int) current.x + n, (int) current.y, (int) current.z + p, Blocks.ice);
                block = ent.worldObj.getBlock((int) current.x + n, (int) current.y + 1, (int) current.z + p);
                if (block == Blocks.fire) {
                    ent.worldObj.setBlock((int) current.x + n, (int) current.y + 1, (int) current.z + p, Blocks.air);
                }
            }
        }
    }
}
Also used : AMVector3(am2.api.math.AMVector3) Block(net.minecraft.block.Block)

Example 38 with AMVector3

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

the class AMClientEventHandler method renderPriorityText.

private void renderPriorityText(DrawBlockHighlightEvent event, TileEntityCrystalMarker te) {
    int meta = event.player.worldObj.getBlockMetadata(event.target.blockX, event.target.blockY, event.target.blockZ);
    if (// no priority for these blocks
    meta == BlockCrystalMarker.META_IN)
        return;
    Block block = event.player.worldObj.getBlock(event.target.blockX, event.target.blockY, event.target.blockZ);
    float yOff = 0.5f;
    String priString = String.format(StatCollector.translateToLocal("am2.tooltip.priority"), String.format("%d", te.getPriority()));
    AMVector3 boundsOffset = new AMVector3(block.getBlockBoundsMinX() + (block.getBlockBoundsMaxX() - block.getBlockBoundsMinX()) / 2, block.getBlockBoundsMinY() + (block.getBlockBoundsMaxY() - block.getBlockBoundsMinY()) / 2, block.getBlockBoundsMinZ() + (block.getBlockBoundsMaxZ() - block.getBlockBoundsMinZ()) / 2);
    AMVector3 offset = new AMVector3(event.target.blockX + boundsOffset.x, event.target.blockY + boundsOffset.y, event.target.blockZ + boundsOffset.z).sub(new AMVector3((event.player.prevPosX - (event.player.prevPosX - event.player.posX) * event.partialTicks), (event.player.prevPosY - (event.player.prevPosY - event.player.posY) * event.partialTicks) + event.player.getEyeHeight(), (event.player.prevPosZ - (event.player.prevPosZ - event.player.posZ) * event.partialTicks)));
    offset = offset.normalize();
    AMVector3 drawPos = new AMVector3(event.target.blockX + block.getBlockBoundsMaxX() - offset.x - (event.player.prevPosX - (event.player.prevPosX - event.player.posX) * event.partialTicks), event.target.blockY + yOff - (event.player.prevPosY - (event.player.prevPosY - event.player.posY) * event.partialTicks) + block.getBlockBoundsMaxY() * 0.8f, event.target.blockZ + block.getBlockBoundsMaxZ() - offset.z - (event.player.prevPosZ - (event.player.prevPosZ - event.player.posZ) * event.partialTicks));
    if (event.target.blockY > event.player.posY - 0.5) {
        drawPos.y = (float) (event.target.blockY - yOff - (event.player.prevPosY - (event.player.prevPosY - event.player.posY) * event.partialTicks) - block.getBlockBoundsMaxY() * 0.2f);
    }
    GL11.glPushAttrib(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_LIGHTING_BIT);
    RenderUtilities.drawTextInWorldAtOffset(priString, drawPos.x, drawPos.y, drawPos.z, 0xFFFFFF);
    GL11.glPopAttrib();
}
Also used : AMVector3(am2.api.math.AMVector3) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 39 with AMVector3

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

the class LightningBolt method renderBolt.

private void renderBolt(Tessellator tessellator, float partialframe, float cosyaw, float cospitch, float sinyaw, float cossinpitch, int pass) {
    AMVector3 playervec = new AMVector3(sinyaw * -cospitch, -cossinpitch / cosyaw, cosyaw * cospitch);
    float boltage = this.main.particleAge >= 0 ? this.main.particleAge / this.main.particleMaxAge : 0.0F;
    float mainalpha = 1.0F;
    if (pass == 0)
        mainalpha = (1.0F - boltage) * 0.9F;
    else if (pass == 1)
        mainalpha = 1.0F - boltage * 0.6F;
    else
        mainalpha = 1.0F - boltage * 0.3F;
    int renderlength = (int) ((this.main.particleAge + partialframe + (int) (this.main.length * 3.0F)) / (int) (this.main.length * 3.0F) * this.main.numsegments0);
    for (Iterator iterator = this.main.segments.iterator(); iterator.hasNext(); ) {
        LightningBoltCommon.Segment rendersegment = (LightningBoltCommon.Segment) iterator.next();
        if (rendersegment.segmentno <= renderlength) {
            float width = 0.03F * (getRelativeViewVector(rendersegment.startpoint.point).length() / 10.0F + 1.0F) * (1.0F + rendersegment.light) * 0.5F;
            if (width > 0.05F)
                width = 0.05F;
            if (pass == 1)
                width += 0.025f;
            else if (pass == 1)
                width += 0.05f;
            AMVector3 diff1 = AMVector3.crossProduct(playervec, rendersegment.prevdiff).scale(width / rendersegment.sinprev);
            AMVector3 diff2 = AMVector3.crossProduct(playervec, rendersegment.nextdiff).scale(width / rendersegment.sinnext);
            AMVector3 startvec = rendersegment.startpoint.point;
            AMVector3 endvec = rendersegment.endpoint.point;
            float rx1 = (float) (startvec.x - interpPosX);
            float ry1 = (float) (startvec.y - interpPosY);
            float rz1 = (float) (startvec.z - interpPosZ);
            float rx2 = (float) (endvec.x - interpPosX);
            float ry2 = (float) (endvec.y - interpPosY);
            float rz2 = (float) (endvec.z - interpPosZ);
            tessellator.setColorRGBA_F(this.particleRed, this.particleGreen, this.particleBlue, mainalpha * rendersegment.light);
            tessellator.addVertexWithUV(rx2 - diff2.x, ry2 - diff2.y, rz2 - diff2.z, 0.5D, 0.0D);
            tessellator.addVertexWithUV(rx1 - diff1.x, ry1 - diff1.y, rz1 - diff1.z, 0.5D, 0.0D);
            tessellator.addVertexWithUV(rx1 + diff1.x, ry1 + diff1.y, rz1 + diff1.z, 0.5D, 1.0D);
            tessellator.addVertexWithUV(rx2 + diff2.x, ry2 + diff2.y, rz2 + diff2.z, 0.5D, 1.0D);
            if (rendersegment.next == null) {
                AMVector3 roundend = rendersegment.endpoint.point.copy().add(rendersegment.diff.copy().normalize().scale(width));
                float rx3 = (float) (roundend.x - interpPosX);
                float ry3 = (float) (roundend.y - interpPosY);
                float rz3 = (float) (roundend.z - interpPosZ);
                tessellator.addVertexWithUV(rx3 - diff2.x, ry3 - diff2.y, rz3 - diff2.z, 0.0D, 0.0D);
                tessellator.addVertexWithUV(rx2 - diff2.x, ry2 - diff2.y, rz2 - diff2.z, 0.5D, 0.0D);
                tessellator.addVertexWithUV(rx2 + diff2.x, ry2 + diff2.y, rz2 + diff2.z, 0.5D, 1.0D);
                tessellator.addVertexWithUV(rx3 + diff2.x, ry3 + diff2.y, rz3 + diff2.z, 0.0D, 1.0D);
            }
            if (rendersegment.prev == null) {
                AMVector3 roundend = rendersegment.startpoint.point.copy().sub(rendersegment.diff.copy().normalize().scale(width));
                float rx3 = (float) (roundend.x - interpPosX);
                float ry3 = (float) (roundend.y - interpPosY);
                float rz3 = (float) (roundend.z - interpPosZ);
                tessellator.addVertexWithUV(rx1 - diff1.x, ry1 - diff1.y, rz1 - diff1.z, 0.5D, 0.0D);
                tessellator.addVertexWithUV(rx3 - diff1.x, ry3 - diff1.y, rz3 - diff1.z, 0.0D, 0.0D);
                tessellator.addVertexWithUV(rx3 + diff1.x, ry3 + diff1.y, rz3 + diff1.z, 0.0D, 1.0D);
                tessellator.addVertexWithUV(rx1 + diff1.x, ry1 + diff1.y, rz1 + diff1.z, 0.5D, 1.0D);
            }
        }
    }
}
Also used : AMVector3(am2.api.math.AMVector3) Iterator(java.util.Iterator)

Example 40 with AMVector3

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

the class LightningBoltCommon method fractal.

public void fractal(int splits, float amount, float splitchance, float splitlength, float splitangle) {
    if (this.finalized)
        return;
    ArrayList oldsegments = this.segments;
    this.segments = new ArrayList();
    Segment prev = null;
    for (Iterator iterator = oldsegments.iterator(); iterator.hasNext(); ) {
        Segment segment = (Segment) iterator.next();
        prev = segment.prev;
        AMVector3 subsegment = segment.diff.copy().scale(1.0F / splits);
        BoltPoint[] newpoints = new BoltPoint[splits + 1];
        AMVector3 startpoint = segment.startpoint.point;
        newpoints[0] = segment.startpoint;
        newpoints[splits] = segment.endpoint;
        for (int i = 1; i < splits; i++) {
            AMVector3 randoff = AMVector3.getPerpendicular(segment.diff).rotate(this.rand.nextFloat() * 360.0F, segment.diff);
            randoff.scale((this.rand.nextFloat() - 0.5F) * amount);
            AMVector3 basepoint = startpoint.copy().add(subsegment.copy().scale(i));
            newpoints[i] = new BoltPoint(basepoint, randoff);
        }
        for (int i = 0; i < splits; i++) {
            Segment next = new Segment(newpoints[i], newpoints[(i + 1)], segment.light, segment.segmentno * splits + i, segment.splitno);
            next.prev = prev;
            if (prev != null)
                prev.next = next;
            if ((i != 0) && (this.rand.nextFloat() < splitchance)) {
                AMVector3 splitrot = AMVector3.xCrossProduct(next.diff).rotate(this.rand.nextFloat() * 360.0F, next.diff);
                AMVector3 diff = next.diff.copy().rotate((this.rand.nextFloat() * 0.66F + 0.33F) * splitangle, splitrot).scale(splitlength);
                this.numsplits += 1;
                this.splitparents.put(Integer.valueOf(this.numsplits), Integer.valueOf(next.splitno));
                Segment split = new Segment(newpoints[i], new BoltPoint(newpoints[(i + 1)].basepoint, newpoints[(i + 1)].offsetvec.copy().add(diff)), segment.light / 2.0F, next.segmentno, this.numsplits);
                split.prev = prev;
                this.segments.add(split);
            }
            prev = next;
            this.segments.add(next);
        }
        if (segment.next != null) {
            segment.next.prev = prev;
        }
    }
    this.numsegments0 *= splits;
}
Also used : AMVector3(am2.api.math.AMVector3)

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