Search in sources :

Example 56 with SubscribeEvent

use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project ArsMagica2 by Mithion.

the class PlayerTracker method onPlayerLogin.

@SubscribeEvent
public void onPlayerLogin(PlayerLoggedInEvent event) {
    if (hasAA(event.player)) {
        AMNetHandler.INSTANCE.requestClientAuras((EntityPlayerMP) event.player);
    }
    int[] disabledSkills = SkillTreeManager.instance.getDisabledSkillIDs();
    AMDataWriter writer = new AMDataWriter();
    writer.add(AMCore.config.getSkillTreeSecondaryTierCap()).add(disabledSkills);
    writer.add(AMCore.config.getManaCap());
    byte[] data = writer.generate();
    AMNetHandler.INSTANCE.syncLoginData((EntityPlayerMP) event.player, data);
    if (ServerTickHandler.lastWorldName != null)
        AMNetHandler.INSTANCE.syncWorldName((EntityPlayerMP) event.player, ServerTickHandler.lastWorldName);
}
Also used : EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) AMDataWriter(am2.network.AMDataWriter) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 57 with SubscribeEvent

use of cpw.mods.fml.common.eventhandler.SubscribeEvent 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 58 with SubscribeEvent

use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project ArsMagica2 by Mithion.

the class AffinityHelper method onEntityFall.

@SubscribeEvent
public void onEntityFall(LivingFallEvent event) {
    EntityLivingBase ent = event.entityLiving;
    if (!(ent instanceof EntityPlayer))
        return;
    AffinityData affinityData = AffinityData.For(ent);
    float earthDepth = affinityData.getAffinityDepth(Affinity.EARTH);
    if (earthDepth > 0.25f) {
        event.distance += 1.25 * (earthDepth);
    }
    float airDepth = affinityData.getAffinityDepth(Affinity.AIR);
    if (airDepth >= 0.5f) {
        event.distance -= 2 * (airDepth);
        if (event.distance < 0)
            event.distance = 0;
    }
}
Also used : EntityLivingBase(net.minecraft.entity.EntityLivingBase) AffinityData(am2.playerextensions.AffinityData) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 59 with SubscribeEvent

use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project ArsMagica2 by Mithion.

the class AffinityHelper method onEntityHurt.

@SubscribeEvent
public void onEntityHurt(LivingHurtEvent event) {
    EntityLivingBase ent = event.entityLiving;
    AffinityData affinityData = AffinityData.For(ent);
    if (event.source.getSourceOfDamage() instanceof EntityPlayer) {
        float attackerFireDepth = AffinityData.For((EntityLivingBase) event.source.getSourceOfDamage()).getAffinityDepth(Affinity.FIRE);
        if (attackerFireDepth > 0.8f && ((EntityPlayer) event.source.getSourceOfDamage()).getCurrentEquippedItem() == null) {
            ent.setFire(4);
            event.ammount += 3;
        }
        float attackerLightningDepth = AffinityData.For((EntityLivingBase) event.source.getSourceOfDamage()).getAffinityDepth(Affinity.LIGHTNING);
        if (attackerLightningDepth > 0.75f && !ent.worldObj.isRemote && ((EntityPlayer) event.source.getSourceOfDamage()).getCurrentEquippedItem() == null) {
            EntityLightningBolt elb = new EntityLightningBolt(ent.worldObj, ent.posX, ent.posY, ent.posZ);
            elb.setPosition(ent.posX, ent.posY, ent.posZ);
            ent.worldObj.addWeatherEffect(elb);
        }
    }
    if (!(ent instanceof EntityPlayer))
        return;
    float earthDepth = affinityData.getAffinityDepth(Affinity.EARTH);
    if (earthDepth > 0.25f) {
        float reduction = 0.1f * earthDepth;
        event.ammount -= event.ammount * reduction;
    }
    float arcaneDepth = affinityData.getAffinityDepth(Affinity.ARCANE);
    if (arcaneDepth > 0.25f) {
        event.ammount *= 1.1f;
    }
    float waterDepth = affinityData.getAffinityDepth(Affinity.WATER);
    if (waterDepth > 0.9f && event.source.getSourceOfDamage() instanceof EntityEnderman) {
        event.source.getSourceOfDamage().attackEntityFrom(DamageSource.drown, 2);
    }
    float fireDepth = affinityData.getAffinityDepth(Affinity.FIRE);
    if (event.source.isFireDamage()) {
        float reduction = 1 - (0.6f * fireDepth);
        event.ammount = event.ammount * reduction;
    }
    float enderDepth = affinityData.getAffinityDepth(Affinity.ENDER);
    if (event.source == DamageSource.magic || event.source == DamageSource.wither) {
        float reduction = 1 - (0.75f * enderDepth);
        event.ammount = event.ammount * reduction;
    }
    if (event.source.getSourceOfDamage() instanceof EntityLivingBase) {
        float natureDepth = affinityData.getAffinityDepth(Affinity.NATURE);
        if (natureDepth == 1.0f) {
            ((EntityLivingBase) event.source.getSourceOfDamage()).attackEntityFrom(DamageSource.cactus, 3);
        } else if (natureDepth >= 0.75f) {
            ((EntityLivingBase) event.source.getSourceOfDamage()).attackEntityFrom(DamageSource.cactus, 2);
        } else if (natureDepth >= 0.5f) {
            ((EntityLivingBase) event.source.getSourceOfDamage()).attackEntityFrom(DamageSource.cactus, 1);
        }
        float iceDepth = affinityData.getAffinityDepth(Affinity.ICE);
        BuffEffectFrostSlowed effect = null;
        if (iceDepth == 1.0f) {
            effect = new BuffEffectFrostSlowed(200, 2);
        } else if (iceDepth >= 0.75f) {
            effect = new BuffEffectFrostSlowed(160, 1);
        } else if (iceDepth >= 0.5f) {
            effect = new BuffEffectFrostSlowed(100, 0);
        }
        if (effect != null) {
            ((EntityLivingBase) event.source.getSourceOfDamage()).addPotionEffect(effect);
        }
    }
    if (event.ammount == 0)
        event.setCanceled(true);
}
Also used : EntityLivingBase(net.minecraft.entity.EntityLivingBase) AffinityData(am2.playerextensions.AffinityData) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityLightningBolt(net.minecraft.entity.effect.EntityLightningBolt) EntityEnderman(net.minecraft.entity.monster.EntityEnderman) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 60 with SubscribeEvent

use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project ArsMagica2 by Mithion.

the class AMClientEventHandler method onPlayerRender.

@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onPlayerRender(RenderPlayerEvent.Pre event) {
    ItemStack chestPlate = event.entityPlayer.inventory.armorInventory[2];
    ModelBiped mainModel = ReflectionHelper.getPrivateValue(RenderPlayer.class, event.renderer, "field_77109_a", "modelBipedMain");
    boolean holdingItem = false;
    if (event.entityPlayer.getCurrentEquippedItem() != null)
        holdingItem = true;
    if (!AMCore.proxy.playerTracker.hasCLS(event.entityPlayer.getUniqueID().toString())) {
        if (chestPlate != null && chestPlate.getItem() == ItemsCommonProxy.earthGuardianArmor) {
            if (mainModel != null) {
                mainModel.bipedLeftArm.isHidden = true;
                mainModel.bipedRightArm.isHidden = !holdingItem;
            }
        } else {
            if (mainModel != null) {
                mainModel.bipedLeftArm.isHidden = false;
                mainModel.bipedRightArm.isHidden = false;
            }
        }
    }
    double dX = AMCore.proxy.getLocalPlayer().posX - event.entityPlayer.posX;
    double dY = AMCore.proxy.getLocalPlayer().posY - event.entityPlayer.posY;
    double dZ = AMCore.proxy.getLocalPlayer().posZ - event.entityPlayer.posZ;
    double dpX = AMCore.proxy.getLocalPlayer().prevPosX - event.entityPlayer.prevPosX;
    double dpY = AMCore.proxy.getLocalPlayer().prevPosY - event.entityPlayer.prevPosY;
    double dpZ = AMCore.proxy.getLocalPlayer().prevPosZ - event.entityPlayer.prevPosZ;
    double transX = dpX + (dX - dpX) * event.partialRenderTick;
    double transY = dpY + (dY - dpY) * event.partialRenderTick;
    double transZ = dpZ + (dZ - dpZ) * event.partialRenderTick;
    if (ExtendedProperties.For(event.entityPlayer).getFlipRotation() > 0) {
        GL11.glPushMatrix();
        GL11.glTranslated(-transX, -transY, -transZ);
        GL11.glRotatef(ExtendedProperties.For(event.entityPlayer).getFlipRotation(), 0, 0, 1.0f);
        GL11.glTranslated(transX, transY, transZ);
        float offset = event.entityPlayer.height * (ExtendedProperties.For(event.entityPlayer).getFlipRotation() / 180.0f);
        GL11.glTranslatef(0, -offset, 0);
    }
    float shrink = ExtendedProperties.For(event.entityPlayer).getShrinkPct();
    if (shrink > 0) {
        GL11.glPushMatrix();
        GL11.glTranslatef(0, 0 - 0.5f * shrink, 0);
        GL11.glScalef(1 - 0.5f * shrink, 1 - 0.5f * shrink, 1 - 0.5f * shrink);
    }
}
Also used : ModelBiped(net.minecraft.client.model.ModelBiped) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Aggregations

SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)138 EntityPlayer (net.minecraft.entity.player.EntityPlayer)57 ItemStack (net.minecraft.item.ItemStack)48 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)18 Minecraft (net.minecraft.client.Minecraft)14 EntityLivingBase (net.minecraft.entity.EntityLivingBase)14 World (net.minecraft.world.World)14 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)12 ArrayList (java.util.ArrayList)10 EntityItem (net.minecraft.entity.item.EntityItem)10 SideOnly (cpw.mods.fml.relauncher.SideOnly)9 ChunkPosition (net.minecraft.world.ChunkPosition)9 ChatComponentText (net.minecraft.util.ChatComponentText)8 PlayerPointer (riskyken.armourersWorkshop.common.data.PlayerPointer)8 Block (net.minecraft.block.Block)7 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)6 AffinityData (am2.playerextensions.AffinityData)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 ChunkCoordIntPair (net.minecraft.world.ChunkCoordIntPair)5