Search in sources :

Example 96 with SubscribeEvent

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

the class AMEventHandler method onEntityJump.

@SubscribeEvent
public void onEntityJump(LivingJumpEvent event) {
    if (event.entityLiving.isPotionActive(BuffList.agility.id)) {
        event.entityLiving.motionY *= 1.5f;
    }
    if (event.entityLiving.isPotionActive(BuffList.leap.id)) {
        Entity velocityTarget = event.entityLiving;
        if (event.entityLiving.ridingEntity != null) {
            if (event.entityLiving.ridingEntity instanceof EntityMinecart) {
                event.entityLiving.ridingEntity.setPosition(event.entityLiving.ridingEntity.posX, event.entityLiving.ridingEntity.posY + 1.5, event.entityLiving.ridingEntity.posZ);
            }
            velocityTarget = event.entityLiving.ridingEntity;
        }
        double yVelocity = 0;
        double xVelocity = 0;
        double zVelocity = 0;
        Vec3 vec = event.entityLiving.getLookVec().normalize();
        switch(event.entityLiving.getActivePotionEffect(BuffList.leap).getAmplifier()) {
            case BuffPowerLevel.Low:
                yVelocity = 0.4;
                xVelocity = velocityTarget.motionX * 1.08 * Math.abs(vec.xCoord);
                zVelocity = velocityTarget.motionZ * 1.08 * Math.abs(vec.zCoord);
                break;
            case BuffPowerLevel.Medium:
                yVelocity = 0.7;
                xVelocity = velocityTarget.motionX * 1.25 * Math.abs(vec.xCoord);
                zVelocity = velocityTarget.motionZ * 1.25 * Math.abs(vec.zCoord);
                break;
            case BuffPowerLevel.High:
                yVelocity = 1;
                xVelocity = velocityTarget.motionX * 1.75 * Math.abs(vec.xCoord);
                zVelocity = velocityTarget.motionZ * 1.75 * Math.abs(vec.zCoord);
                break;
            default:
                break;
        }
        float maxHorizontalVelocity = 1.45f;
        if (event.entityLiving.ridingEntity != null && (event.entityLiving.ridingEntity instanceof EntityMinecart || event.entityLiving.ridingEntity instanceof EntityBoat) || event.entityLiving.isPotionActive(BuffList.haste.id)) {
            maxHorizontalVelocity += 25;
            xVelocity *= 2.5;
            zVelocity *= 2.5;
        }
        if (xVelocity > maxHorizontalVelocity) {
            xVelocity = maxHorizontalVelocity;
        } else if (xVelocity < -maxHorizontalVelocity) {
            xVelocity = -maxHorizontalVelocity;
        }
        if (zVelocity > maxHorizontalVelocity) {
            zVelocity = maxHorizontalVelocity;
        } else if (zVelocity < -maxHorizontalVelocity) {
            zVelocity = -maxHorizontalVelocity;
        }
        if (ExtendedProperties.For(event.entityLiving).getIsFlipped()) {
            yVelocity *= -1;
        }
        velocityTarget.addVelocity(xVelocity, yVelocity, zVelocity);
    }
    if (event.entityLiving.isPotionActive(BuffList.entangled.id)) {
        event.entityLiving.motionY = 0;
    }
    if (event.entityLiving instanceof EntityPlayer) {
        ItemStack boots = ((EntityPlayer) event.entityLiving).inventory.armorInventory[0];
        if (boots != null && boots.getItem() == ItemsCommonProxy.enderBoots && event.entityLiving.isSneaking()) {
            ExtendedProperties.For(event.entityLiving).toggleFlipped();
        }
        if (ExtendedProperties.For(event.entityLiving).getFlipRotation() > 0)
            ((EntityPlayer) event.entityLiving).addVelocity(0, -2 * event.entityLiving.motionY, 0);
    }
}
Also used : Vec3(net.minecraft.util.Vec3) EntityBoat(net.minecraft.entity.item.EntityBoat) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) EntityMinecart(net.minecraft.entity.item.EntityMinecart) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 97 with SubscribeEvent

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

the class AMEventHandler method onEndermanTeleport.

@SubscribeEvent
public void onEndermanTeleport(EnderTeleportEvent event) {
    EntityLivingBase ent = event.entityLiving;
    ArrayList<Long> keystoneKeys = KeystoneUtilities.instance.GetKeysInInvenory(ent);
    TileEntityAstralBarrier blockingBarrier = DimensionUtilities.GetBlockingAstralBarrier(event.entityLiving.worldObj, (int) event.targetX, (int) event.targetY, (int) event.targetZ, keystoneKeys);
    if (ent.isPotionActive(BuffList.astralDistortion.id) || blockingBarrier != null) {
        event.setCanceled(true);
        if (blockingBarrier != null) {
            blockingBarrier.onEntityBlocked(ent);
        }
        return;
    }
    if (!ent.worldObj.isRemote && ent instanceof EntityEnderman && ent.worldObj.rand.nextDouble() < 0.01f) {
        EntityFlicker flicker = new EntityFlicker(ent.worldObj);
        flicker.setPosition(ent.posX, ent.posY, ent.posZ);
        flicker.setFlickerType(Affinity.ENDER);
        ent.worldObj.spawnEntityInWorld(flicker);
    }
}
Also used : TileEntityAstralBarrier(am2.blocks.tileentities.TileEntityAstralBarrier) EntityFlicker(am2.entities.EntityFlicker) EntityEnderman(net.minecraft.entity.monster.EntityEnderman) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 98 with SubscribeEvent

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

the class AMEventHandler method onPlayerPickupItem.

@SubscribeEvent
public void onPlayerPickupItem(EntityItemPickupEvent event) {
    if (event.entityPlayer == null)
        return;
    if (!event.entityPlayer.worldObj.isRemote && ExtendedProperties.For(event.entityPlayer).getMagicLevel() <= 0 && event.item.getEntityItem().getItem() == ItemsCommonProxy.arcaneCompendium) {
        event.entityPlayer.addChatMessage(new ChatComponentText("You have unlocked the secrets of the arcane!"));
        AMNetHandler.INSTANCE.sendCompendiumUnlockPacket((EntityPlayerMP) event.entityPlayer, "shapes", true);
        AMNetHandler.INSTANCE.sendCompendiumUnlockPacket((EntityPlayerMP) event.entityPlayer, "components", true);
        AMNetHandler.INSTANCE.sendCompendiumUnlockPacket((EntityPlayerMP) event.entityPlayer, "modifiers", true);
        ExtendedProperties.For(event.entityPlayer).setMagicLevelWithMana(1);
        ExtendedProperties.For(event.entityPlayer).forceSync();
        return;
    }
    if (event.item.getEntityItem().getItem() == ItemsCommonProxy.spell) {
        if (event.entityPlayer.worldObj.isRemote) {
            AMNetHandler.INSTANCE.sendCompendiumUnlockPacket((EntityPlayerMP) event.entityPlayer, "spell_book", false);
        }
    } else {
        Item item = event.item.getEntityItem().getItem();
        int meta = event.item.getEntityItem().getItemDamage();
        if (event.entityPlayer.worldObj.isRemote && item.getUnlocalizedName() != null && (AMCore.proxy.items.getArsMagicaItems().contains(item)) || (item instanceof ItemBlock && AMCore.proxy.blocks.getArsMagicaBlocks().contains(((ItemBlock) item).field_150939_a))) {
            AMNetHandler.INSTANCE.sendCompendiumUnlockPacket((EntityPlayerMP) event.entityPlayer, item.getUnlocalizedName().replace("item.", "").replace("arsmagica2:", "").replace("tile.", "") + ((meta > -1) ? "@" + meta : ""), false);
        }
    }
}
Also used : Item(net.minecraft.item.Item) EntityItem(net.minecraft.entity.item.EntityItem) ItemBlock(net.minecraft.item.ItemBlock) ChatComponentText(net.minecraft.util.ChatComponentText) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 99 with SubscribeEvent

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

the class AMWorldEventHandler method onChunkLoaded.

@SubscribeEvent
public void onChunkLoaded(ChunkDataEvent.Load event) {
    int dimensionID = event.world.provider.dimensionId;
    ChunkCoordIntPair chunkLocation = event.getChunk().getChunkCoordIntPair();
    NBTTagCompound compound = (NBTTagCompound) event.getData().getTag("ArsMagica2");
    if (AMCore.config.retroactiveWorldgen() && (compound == null || !compound.hasKey(genKey))) {
        LogHelper.info("Detected a chunk that requires retrogen.  Adding to retrogen list.");
        AMCore.proxy.addQueuedRetrogen(dimensionID, chunkLocation);
    }
}
Also used : ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 100 with SubscribeEvent

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

the class AMWorldEventHandler method onChunkSaved.

@SubscribeEvent
public void onChunkSaved(ChunkDataEvent.Save event) {
    NBTTagCompound compound = new NBTTagCompound();
    if (event.getData().hasKey("ArsMagica2")) {
        compound = event.getData().getCompoundTag("ArsMagica2");
    }
    compound.setBoolean(genKey, true);
    event.getData().setTag("ArsMagica2", compound);
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) 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