Search in sources :

Example 61 with SubscribeEvent

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

the class AMClientEventHandler method onItemTooltip.

@SubscribeEvent
public void onItemTooltip(ItemTooltipEvent event) {
    ItemStack stack = event.itemStack;
    if (stack != null && stack.getItem() instanceof ItemArmor) {
        double xp = 0;
        int armorLevel = 0;
        String[] effects = new String[0];
        if (stack.hasTagCompound()) {
            NBTTagCompound armorCompound = (NBTTagCompound) stack.stackTagCompound.getTag(AMArmor.NBT_KEY_AMPROPS);
            if (armorCompound != null) {
                xp = armorCompound.getDouble(AMArmor.NBT_KEY_TOTALXP);
                armorLevel = armorCompound.getInteger(AMArmor.NBT_KEY_ARMORLEVEL);
                String effectsList = armorCompound.getString(AMArmor.NBT_KEY_EFFECTS);
                if (effectsList != null && effectsList != "") {
                    effects = effectsList.split(AMArmor.INFUSION_DELIMITER);
                }
            }
        }
        if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
            event.toolTip.add(StatCollector.translateToLocalFormatted("am2.tooltip.armorxp", String.format("%.2f", xp)));
            event.toolTip.add(String.format(StatCollector.translateToLocal("am2.tooltip.armorlevel"), armorLevel));
            for (String s : effects) {
                event.toolTip.add(StatCollector.translateToLocal("am2.tooltip." + s));
            }
        } else {
            event.toolTip.add(StatCollector.translateToLocal("am2.tooltip.shiftForDetails"));
        }
    } else if (stack.getItem() instanceof ItemBlock) {
        if (((ItemBlock) stack.getItem()).field_150939_a == BlocksCommonProxy.manaBattery) {
            if (stack.hasTagCompound()) {
                float batteryCharge = stack.stackTagCompound.getFloat("mana_battery_charge");
                PowerTypes powerType = PowerTypes.getByID(stack.stackTagCompound.getInteger("mana_battery_powertype"));
                if (batteryCharge != 0) {
                    // TODO localize this tooltip
                    event.toolTip.add(String.format("\u00A7r\u00A79Contains \u00A75%.2f %s%s \u00A79etherium", batteryCharge, powerType.chatColor(), powerType.name()));
                }
            }
        }
    }
}
Also used : PowerTypes(am2.api.power.PowerTypes) ItemArmor(net.minecraft.item.ItemArmor) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 62 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.Post event) {
    ModelBiped mainModel = ReflectionHelper.getPrivateValue(RenderPlayer.class, event.renderer, "field_77109_a", "modelBipedMain");
    if (mainModel != null) {
        mainModel.bipedLeftArm.isHidden = false;
        mainModel.bipedRightArm.isHidden = false;
    }
    if (ExtendedProperties.For(event.entityPlayer).getFlipRotation() > 0) {
        GL11.glPopMatrix();
    }
    if (ExtendedProperties.For(event.entityPlayer).getShrinkPct() > 0) {
        GL11.glPopMatrix();
    }
    CloakUtils.renderCloakModel(event.entityPlayer, mainModel, event.partialRenderTick);
    if (event.entityPlayer == AMCore.proxy.getLocalPlayer()) {
        if (AMCore.proxy.getLocalPlayer().isPotionActive(BuffList.trueSight.id)) {
            if (AMGuiHelper.instance.playerRunesAlpha < 1)
                AMGuiHelper.instance.playerRunesAlpha += 0.01f;
        } else {
            if (AMGuiHelper.instance.playerRunesAlpha > 0)
                AMGuiHelper.instance.playerRunesAlpha -= 0.01f;
        }
        if (AMGuiHelper.instance.playerRunesAlpha > 0) {
            int runeCombo = EntityUtilities.getRuneCombo(event.entityPlayer);
            int numRunes = 0;
            for (int i = 0; i <= 16; ++i) {
                int bit = 1 << i;
                if ((runeCombo & bit) == bit) {
                    numRunes++;
                }
            }
            double step = 0.25f;
            double xOffset = -(numRunes / 2.0f) * step + ((numRunes % 2 == 0) ? step / 2f : 0);
            for (int i = 0; i <= 16; ++i) {
                int bit = 1 << i;
                if ((runeCombo & bit) == bit) {
                    RenderUtilities.DrawIconInWorldAtOffset(ItemsCommonProxy.rune.getIconFromDamage(i), xOffset, 0.5f, 0, 0.25f, 0.25f);
                    xOffset += step;
                }
            }
        }
    }
}
Also used : ModelBiped(net.minecraft.client.model.ModelBiped) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Example 63 with SubscribeEvent

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

the class AMKeyBindings method onKeyInput.

@SubscribeEvent
public void onKeyInput(KeyInputEvent event) {
    EntityPlayer clientPlayer = FMLClientHandler.instance().getClient().thePlayer;
    if (Minecraft.getMinecraft().currentScreen != null) {
        if (Minecraft.getMinecraft().currentScreen instanceof GuiInventory) {
            if (ManaToggleKey.isPressed()) {
                boolean curDisplayFlag = AMCore.config.displayManaInInventory();
                AMCore.config.setDisplayManaInInventory(!curDisplayFlag);
            }
        }
        return;
    }
    if (ShapeGroupKey.isPressed()) {
        EntityPlayer player = Minecraft.getMinecraft().thePlayer;
        ItemStack curItem = player.inventory.getStackInSlot(player.inventory.currentItem);
        if (curItem == null || (curItem.getItem() != ItemsCommonProxy.spell && curItem.getItem() != ItemsCommonProxy.spellBook && curItem.getItem() != ItemsCommonProxy.arcaneSpellbook)) {
            return;
        }
        int shapeGroup;
        if (curItem.getItem() == ItemsCommonProxy.spell) {
            shapeGroup = SpellUtils.instance.cycleShapeGroup(curItem);
        } else {
            ItemStack spellStack = ((ItemSpellBook) curItem.getItem()).GetActiveItemStack(curItem);
            if (spellStack == null) {
                return;
            }
            shapeGroup = SpellUtils.instance.cycleShapeGroup(spellStack);
            ((ItemSpellBook) curItem.getItem()).replaceAciveItemStack(curItem, spellStack);
        }
        AMNetHandler.INSTANCE.sendShapeGroupChangePacket(shapeGroup, clientPlayer.getEntityId());
    } else if (this.SpellBookNextSpellKey.isPressed()) {
        EntityPlayer player = Minecraft.getMinecraft().thePlayer;
        ItemStack curItem = player.inventory.getStackInSlot(player.inventory.currentItem);
        if (curItem == null) {
            return;
        }
        if (curItem.getItem() == ItemsCommonProxy.spellBook || curItem.getItem() == ItemsCommonProxy.arcaneSpellbook) {
            // send packet to server
            AMNetHandler.INSTANCE.sendSpellbookSlotChange(player, player.inventory.currentItem, ItemSpellBook.ID_NEXT_SPELL);
        }
    } else if (this.SpellBookPrevSpellKey.isPressed()) {
        EntityPlayer player = Minecraft.getMinecraft().thePlayer;
        ItemStack curItem = player.inventory.getStackInSlot(player.inventory.currentItem);
        if (curItem == null) {
            return;
        }
        if (curItem.getItem() == ItemsCommonProxy.spellBook || curItem.getItem() == ItemsCommonProxy.arcaneSpellbook) {
            // send packet to server
            AMNetHandler.INSTANCE.sendSpellbookSlotChange(player, player.inventory.currentItem, ItemSpellBook.ID_PREV_SPELL);
        }
    } else if (AuraCustomizationKey.isPressed()) {
        if (AMCore.proxy.playerTracker.hasAA(clientPlayer)) {
            Minecraft.getMinecraft().displayGuiScreen(new AuraCustomizationMenu());
        }
    } else if (AffinityActivationKey.isPressed()) {
        if (AffinityData.For(clientPlayer).isAbilityReady()) {
            // send packet to the server to process the ability
            AMNetHandler.INSTANCE.sendAffinityActivate();
            // activate the ability on the client
            AffinityData.For(clientPlayer).onAffinityAbility();
        }
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) AuraCustomizationMenu(am2.guis.AuraCustomizationMenu) ItemStack(net.minecraft.item.ItemStack) GuiInventory(net.minecraft.client.gui.inventory.GuiInventory) ItemSpellBook(am2.items.ItemSpellBook) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 64 with SubscribeEvent

use of cpw.mods.fml.common.eventhandler.SubscribeEvent 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();
        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;
        }
    }
    // swift swim
    if (event.entityLiving.isPotionActive(BuffList.swiftSwim)) {
        if (event.entityLiving.isInWater()) {
            if (!(event.entityLiving instanceof EntityPlayer) || !((EntityPlayer) event.entityLiving).capabilities.isFlying) {
                event.entityLiving.motionX *= (1.133f + 0.03 * event.entityLiving.getActivePotionEffect(BuffList.swiftSwim).getAmplifier());
                event.entityLiving.motionZ *= (1.133f + 0.03 * event.entityLiving.getActivePotionEffect(BuffList.swiftSwim).getAmplifier());
                if (event.entityLiving.motionY > 0) {
                    event.entityLiving.motionY *= 1.134;
                }
            }
        }
    }
    // 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 65 with SubscribeEvent

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

the class AMEventHandler method onPotionBrewed.

@SubscribeEvent
public void onPotionBrewed(PotionBrewedEvent brewEvent) {
    for (ItemStack stack : brewEvent.brewingStacks) {
        if (stack == null)
            continue;
        if (stack.getItem() instanceof ItemPotion) {
            ItemPotion ptn = ((ItemPotion) stack.getItem());
            List<PotionEffect> fx = ptn.getEffects(stack.getItemDamage());
            if (fx == null)
                return;
            for (PotionEffect pe : fx) {
                if (pe.getPotionID() == BuffList.greaterManaPotion.id) {
                    stack = InventoryUtilities.replaceItem(stack, ItemsCommonProxy.greaterManaPotion);
                    break;
                } else if (pe.getPotionID() == BuffList.epicManaPotion.id) {
                    stack = InventoryUtilities.replaceItem(stack, ItemsCommonProxy.epicManaPotion);
                    break;
                } else if (pe.getPotionID() == BuffList.legendaryManaPotion.id) {
                    stack = InventoryUtilities.replaceItem(stack, ItemsCommonProxy.legendaryManaPotion);
                    break;
                }
            }
        }
    }
}
Also used : ItemPotion(net.minecraft.item.ItemPotion) PotionEffect(net.minecraft.potion.PotionEffect) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

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