Search in sources :

Example 6 with ExtendedProperties

use of am2.playerextensions.ExtendedProperties in project ArsMagica2 by Mithion.

the class AMPacketProcessorServer method handlePossibleClientExpropDesync.

private void handlePossibleClientExpropDesync(byte[] data) {
    AMDataReader rdr = new AMDataReader(data, false);
    int entityID = rdr.getInt();
    EntityLivingBase e = getEntityByID(entityID);
    if (e != null && e instanceof EntityPlayer) {
        ExtendedProperties props = ExtendedProperties.For(e);
        if (!props.detectPossibleDesync()) {
            props.setFullSync();
            props.forceSync();
        }
    }
}
Also used : EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ExtendedProperties(am2.playerextensions.ExtendedProperties)

Example 7 with ExtendedProperties

use of am2.playerextensions.ExtendedProperties in project ArsMagica2 by Mithion.

the class AMPacketProcessorClient method handleSyncBetaParticles.

private void handleSyncBetaParticles(byte[] data) {
    EntityPlayer localPlayer = Minecraft.getMinecraft().thePlayer;
    if (!AMCore.proxy.playerTracker.hasAA(localPlayer))
        return;
    ExtendedProperties e = ExtendedProperties.For(localPlayer);
    AMDataWriter writer = new AMDataWriter();
    writer.add(e.getAuraIndex());
    writer.add(e.getAuraBehaviour());
    writer.add(e.getAuraScale());
    writer.add(e.getAuraAlpha());
    writer.add(e.getAuraColorRandomize());
    writer.add(e.getAuraColorDefault());
    writer.add(e.getAuraColor());
    writer.add(e.getAuraDelay());
    writer.add(e.getAuraQuantity());
    writer.add(e.getAuraSpeed());
    AMNetHandler.INSTANCE.sendPacketToServer(AMPacketIDs.SYNC_BETA_PARTICLES, writer.generate());
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) ExtendedProperties(am2.playerextensions.ExtendedProperties)

Example 8 with ExtendedProperties

use of am2.playerextensions.ExtendedProperties in project ArsMagica2 by Mithion.

the class AMEventHandler method onEntityLiving.

@SubscribeEvent
public void onEntityLiving(LivingUpdateEvent event) {
    EntityLivingBase ent = event.entityLiving;
    World world = ent.worldObj;
    BuffStatModifiers.instance.applyStatModifiersBasedOnBuffs(ent);
    ExtendedProperties extendedProperties;
    extendedProperties = ExtendedProperties.For(ent);
    extendedProperties.handleSpecialSyncData();
    extendedProperties.manaBurnoutTick();
    //archmage armor effects & infusion
    if (ent instanceof EntityPlayer) {
        if (ent.worldObj.isRemote) {
            int divisor = extendedProperties.getAuraDelay() > 0 ? extendedProperties.getAuraDelay() : 1;
            if (ent.ticksExisted % divisor == 0)
                AMCore.instance.proxy.particleManager.spawnAuraParticles(ent);
            AMCore.proxy.setViewSettings();
        }
        ArmorHelper.HandleArmorInfusion((EntityPlayer) ent);
        ArmorHelper.HandleArmorEffects((EntityPlayer) ent, world);
        extendedProperties.flipTick();
        if (extendedProperties.getIsFlipped()) {
            if (((EntityPlayer) ent).motionY < 2)
                ((EntityPlayer) ent).motionY += 0.15f;
            double posY = ent.posY + ent.height;
            if (!world.isRemote)
                posY += ent.getEyeHeight();
            if (world.rayTraceBlocks(Vec3.createVectorHelper(ent.posX, posY, ent.posZ), Vec3.createVectorHelper(ent.posX, posY + 1, ent.posZ), true) != null) {
                if (!ent.onGround) {
                    if (ent.fallDistance > 0) {
                        try {
                            Method m = ReflectionHelper.findMethod(Entity.class, ent, new String[] { "func_70069_a", "fall" }, float.class);
                            m.setAccessible(true);
                            m.invoke(ent, ent.fallDistance);
                        } catch (Throwable e) {
                            e.printStackTrace();
                        }
                        ent.fallDistance = 0;
                    }
                }
                ent.onGround = true;
            } else {
                if (ent.motionY > 0) {
                    if (world.isRemote)
                        ent.fallDistance += ent.posY - ent.prevPosY;
                    else
                        ent.fallDistance += (((EntityPlayer) ent).field_71095_bQ - ((EntityPlayer) ent).field_71096_bN) * 2;
                }
                ent.onGround = false;
            }
        }
        if (ArmorHelper.isInfusionPreset(((EntityPlayer) ent).getCurrentArmor(1), GenericImbuement.stepAssist)) {
            ent.stepHeight = 1.0111f;
        } else if (ent.stepHeight == 1.0111f) {
            ent.stepHeight = 0.5f;
        }
        IAttributeInstance attr = ent.getEntityAttribute(SharedMonsterAttributes.movementSpeed);
        if (ArmorHelper.isInfusionPreset(((EntityPlayer) ent).getCurrentArmor(0), GenericImbuement.runSpeed)) {
            if (attr.getModifier(GenericImbuement.imbuedHasteID) == null) {
                attr.applyModifier(GenericImbuement.imbuedHaste);
            }
        } else {
            if (attr.getModifier(GenericImbuement.imbuedHasteID) != null) {
                attr.removeModifier(GenericImbuement.imbuedHaste);
            }
        }
    }
    if (!ent.onGround && ent.fallDistance >= 4f && extendedProperties.getContingencyType() == ContingencyTypes.FALL && extendedProperties.getContingencyEffect() != null) {
        int distanceToGround = MathUtilities.getDistanceToGround(ent, world);
        if (distanceToGround < -8 * ent.motionY) {
            extendedProperties.procContingency();
        }
    }
    if (extendedProperties.getContingencyType() == ContingencyTypes.ON_FIRE && ent.isBurning()) {
        extendedProperties.procContingency();
    }
    if (!ent.worldObj.isRemote && ent.ticksExisted % 200 == 0) {
        extendedProperties.setSyncAuras();
    }
    //buff particles
    //if (ent.worldObj.isRemote)
    //	AMCore.instance.proxy.particleManager.spawnBuffParticles(ent);
    //data sync
    extendedProperties.handleExtendedPropertySync();
    if (ent instanceof EntityPlayer) {
        AffinityData.For(ent).handleExtendedPropertySync();
        SkillData.For((EntityPlayer) ent).handleExtendedPropertySync();
        if (ent.isPotionActive(BuffList.flight.id) || ent.isPotionActive(BuffList.levitation.id) || ((EntityPlayer) ent).capabilities.isCreativeMode) {
            extendedProperties.hadFlight = true;
            if (ent.isPotionActive(BuffList.levitation)) {
                if (((EntityPlayer) ent).capabilities.isFlying) {
                    float factor = 0.4f;
                    ent.motionX *= factor;
                    ent.motionZ *= factor;
                    ent.motionY *= 0.0001f;
                }
            }
        } else if (extendedProperties.hadFlight) {
            ((EntityPlayer) ent).capabilities.allowFlying = false;
            ((EntityPlayer) ent).capabilities.isFlying = false;
            extendedProperties.hadFlight = false;
        }
    }
    if (ent.isPotionActive(BuffList.agility.id)) {
        ent.stepHeight = 1.01f;
    } else if (ent.stepHeight == 1.01f) {
        ent.stepHeight = 0.5f;
    }
    if (!ent.worldObj.isRemote && EntityUtilities.isSummon(ent) && !EntityUtilities.isTileSpawnedAndValid(ent)) {
        int owner = EntityUtilities.getOwner(ent);
        Entity ownerEnt = ent.worldObj.getEntityByID(owner);
        if (!EntityUtilities.decrementSummonDuration(ent)) {
            ent.attackEntityFrom(DamageSources.unsummon, 5000);
        }
        if (owner == -1 || ownerEnt == null || ownerEnt.isDead || ownerEnt.getDistanceSqToEntity(ent) > 900) {
            if (ent instanceof EntityLiving && !((EntityLiving) ent).getCustomNameTag().equals("")) {
                EntityUtilities.setOwner(ent, null);
                EntityUtilities.setSummonDuration(ent, -1);
                EntityUtilities.revertAI((EntityCreature) ent);
            } else {
                ent.attackEntityFrom(DamageSources.unsummon, 5000);
            }
        }
    }
    //leap buff
    if (event.entityLiving.isPotionActive(BuffList.leap)) {
        int amplifier = event.entityLiving.getActivePotionEffect(BuffList.leap).getAmplifier() + 1;
        switch(amplifier) {
            case BuffPowerLevel.Low:
                extendedProperties.setFallProtection(8);
                break;
            case BuffPowerLevel.Medium:
                extendedProperties.setFallProtection(20);
                break;
            case BuffPowerLevel.High:
                extendedProperties.setFallProtection(45);
                break;
            default:
                break;
        }
    }
    if (event.entityLiving.isPotionActive(BuffList.gravityWell)) {
        if (event.entityLiving.motionY < 0 && event.entityLiving.motionY > -3f) {
            event.entityLiving.motionY *= 1.59999999999999998D;
        }
    }
    // (isSneaking calls DataWatcher which are slow, so we test it late)
    if (event.entityLiving.isPotionActive(BuffList.slowfall) || event.entityLiving.isPotionActive(BuffList.shrink) || (ent instanceof EntityPlayer && AffinityData.For(ent).getAffinityDepth(Affinity.NATURE) == 1.0f && !ent.isSneaking())) {
        if (!event.entityLiving.onGround && event.entityLiving.motionY < 0.0D) {
            event.entityLiving.motionY *= 0.79999999999999998D;
        }
    }
    //watery grave
    if (event.entityLiving.isPotionActive(BuffList.wateryGrave)) {
        if (event.entityLiving.isInWater()) {
            double pullVel = -0.5f;
            pullVel *= (event.entityLiving.getActivePotionEffect(BuffList.wateryGrave).getAmplifier() + 1);
            if (event.entityLiving.motionY > pullVel)
                event.entityLiving.motionY -= 0.1;
        }
    }
    //mana link pfx
    if (ent.worldObj.isRemote)
        extendedProperties.spawnManaLinkParticles();
    if (ent.ticksExisted % 20 == 0)
        extendedProperties.cleanupManaLinks();
    if (world.isRemote) {
        AMCore.proxy.sendLocalMovementData(ent);
    }
}
Also used : IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Method(java.lang.reflect.Method) World(net.minecraft.world.World) ExtendedProperties(am2.playerextensions.ExtendedProperties) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 9 with ExtendedProperties

use of am2.playerextensions.ExtendedProperties in project ArsMagica2 by Mithion.

the class ArmorEventHandler method doInfusions.

private void doInfusions(ImbuementApplicationTypes type, Event event, EntityPlayer player) {
    ExtendedProperties props = ExtendedProperties.For(player);
    for (int i = 0; i < 4; ++i) {
        IArmorImbuement[] infusions = ArmorHelper.getInfusionsOnArmor(player, i);
        int cd = props.armorProcCooldowns[i];
        for (IArmorImbuement inf : infusions) {
            if (inf == null)
                continue;
            if (inf.getApplicationTypes().contains(type)) {
                if (cd == 0 || inf.canApplyOnCooldown()) {
                    if (inf.applyEffect(player, player.worldObj, player.getCurrentArmor(i), type, event)) {
                        if (inf.getCooldown() > 0) {
                            if (props.armorProcCooldowns[i] < inf.getCooldown()) {
                                props.armorProcCooldowns[i] = inf.getCooldown();
                                if (player instanceof EntityPlayerMP)
                                    AMCore.proxy.blackoutArmorPiece((EntityPlayerMP) player, i, inf.getCooldown());
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) IArmorImbuement(am2.api.items.armor.IArmorImbuement) ExtendedProperties(am2.playerextensions.ExtendedProperties)

Example 10 with ExtendedProperties

use of am2.playerextensions.ExtendedProperties in project ArsMagica2 by Mithion.

the class FallProtection method applyEffect.

@Override
public boolean applyEffect(EntityPlayer player, World world, ItemStack stack, ImbuementApplicationTypes matchedType, Object... params) {
    if (world.isRemote)
        return false;
    int distanceToGround = MathUtilities.getDistanceToGround(player, world);
    ExtendedProperties extendedProperties = ExtendedProperties.For(player);
    if (player.fallDistance >= extendedProperties.getFallProtection() + 4f && distanceToGround < -8 * player.motionY) {
        if (!player.isPotionActive(BuffList.slowfall.id) && !player.capabilities.isFlying) {
            BuffEffectSlowfall sf = new BuffEffectSlowfall(distanceToGround * 3, 1);
            player.addPotionEffect(sf);
            stack.damageItem((int) (player.fallDistance * 6), player);
            player.fallDistance = 0;
            return true;
        }
    }
    return false;
}
Also used : BuffEffectSlowfall(am2.buffs.BuffEffectSlowfall) ExtendedProperties(am2.playerextensions.ExtendedProperties)

Aggregations

ExtendedProperties (am2.playerextensions.ExtendedProperties)26 EntityPlayer (net.minecraft.entity.player.EntityPlayer)16 EntityLivingBase (net.minecraft.entity.EntityLivingBase)10 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)4 AMVector2 (am2.api.math.AMVector2)3 ItemStack (net.minecraft.item.ItemStack)3 IArmorImbuement (am2.api.items.armor.IArmorImbuement)1 BuffEffectSlowfall (am2.buffs.BuffEffectSlowfall)1 ItemSpellBook (am2.items.ItemSpellBook)1 AMDataWriter (am2.network.AMDataWriter)1 ParticleExpandingCollapsingRingAtPoint (am2.particles.ParticleExpandingCollapsingRingAtPoint)1 AffinityData (am2.playerextensions.AffinityData)1 RiftStorage (am2.playerextensions.RiftStorage)1 SkillData (am2.playerextensions.SkillData)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Minecraft (net.minecraft.client.Minecraft)1 EntityRenderer (net.minecraft.client.renderer.EntityRenderer)1 IAttributeInstance (net.minecraft.entity.ai.attributes.IAttributeInstance)1 EntityItemFrame (net.minecraft.entity.item.EntityItemFrame)1