Search in sources :

Example 6 with MagicBook

use of cavern.magic.MagicBook in project Cavern2 by kegare.

the class MagicResultMessage method process.

@Override
public IMessage process(EntityPlayerMP player) {
    MagicBook book = MagicBook.get(player);
    Magic magic = book.getSpellingMagic();
    if (magic != null) {
        EnumActionResult type;
        ITextComponent message;
        if (clientResult == EnumActionResult.PASS) {
            ActionResult<ITextComponent> result = magic.fireMagic();
            type = result.getType();
            message = result.getResult();
        } else {
            type = clientResult;
            message = null;
        }
        if (type == EnumActionResult.SUCCESS) {
            ItemStack stack = book.getSpellingMagicBook();
            World world = player.getServerWorld();
            int cost = 0;
            SpecialMagic specialMagic = book.getSpecialMagic();
            if (specialMagic != null && specialMagic != magic && specialMagic.hasSpecialCost(magic)) {
                cost = specialMagic.getSpecialCost(magic);
            } else {
                cost = magic.getCost();
            }
            if (cost == 0) {
                ItemMagicBook.setLastUseTime(stack, world.getTotalWorldTime());
            } else {
                if (ItemMagicBook.consumeMana(stack, cost) > 0) {
                    ItemMagicBook.setLastUseTime(stack, world.getTotalWorldTime());
                } else {
                    player.setHeldItem(magic.getSpellingHand(), new ItemStack(Items.BOOK));
                }
            }
            SoundEvent sound = magic.getSuccessSound();
            if (sound != null) {
                world.playSound(null, player.posX, player.posY + 0.25D, player.posZ, sound, SoundCategory.PLAYERS, 1.0F, 1.0F);
            }
            if (magic.isOverload()) {
                book.setSpecialMagic(null);
            }
        }
        if (message != null) {
            player.sendStatusMessage(message, true);
        }
        magic.onCloseBook();
    }
    book.setSpellingMagic(null);
    return null;
}
Also used : SpecialMagic(cavern.magic.SpecialMagic) SoundEvent(net.minecraft.util.SoundEvent) EnumActionResult(net.minecraft.util.EnumActionResult) Magic(cavern.magic.Magic) SpecialMagic(cavern.magic.SpecialMagic) ITextComponent(net.minecraft.util.text.ITextComponent) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World) ItemMagicBook(cavern.item.ItemMagicBook) MagicBook(cavern.magic.MagicBook)

Example 7 with MagicBook

use of cavern.magic.MagicBook in project Cavern2 by kegare.

the class SpecialMagicMessage method process.

@Override
public IMessage process(EntityPlayerMP player) {
    MagicBook book = MagicBook.get(player);
    SpecialMagic magic = book.getSpecialMagic();
    if (magic != null) {
        ITextComponent message = magic.finishMagic();
        if (message != null) {
            player.sendStatusMessage(message, true);
        }
        SoundEvent sound = magic.getFinishSound();
        if (sound != null) {
            player.world.playSound(null, player.posX, player.posY + 0.25D, player.posZ, sound, SoundCategory.PLAYERS, 1.0F, 1.0F);
        }
        book.setSpecialMagic(null);
    }
    return null;
}
Also used : SpecialMagic(cavern.magic.SpecialMagic) SoundEvent(net.minecraft.util.SoundEvent) ITextComponent(net.minecraft.util.text.ITextComponent) MagicBook(cavern.magic.MagicBook)

Example 8 with MagicBook

use of cavern.magic.MagicBook in project Cavern2 by kegare.

the class MagicInvisibleMessage method process.

@Override
public IMessage process(EntityPlayerMP player) {
    MagicBook book = MagicBook.get(player);
    Magic magic = book.getSpellingMagic();
    if (magic != null) {
        if (magic.getMana() < magic.getCost()) {
            return new MagicCancelMessage();
        }
        player.setInvisible(true);
        SoundEvent sound = magic.getSuccessSound();
        if (sound != null) {
            player.world.playSound(null, player.posX, player.posY + 0.25D, player.posZ, sound, SoundCategory.PLAYERS, 1.0F, 1.0F);
        }
    }
    return null;
}
Also used : SoundEvent(net.minecraft.util.SoundEvent) Magic(cavern.magic.Magic) MagicCancelMessage(cavern.network.client.MagicCancelMessage) MagicBook(cavern.magic.MagicBook)

Aggregations

MagicBook (cavern.magic.MagicBook)8 Magic (cavern.magic.Magic)4 SoundEvent (net.minecraft.util.SoundEvent)4 MagicInfinity (cavern.magic.MagicInfinity)3 SpecialMagic (cavern.magic.SpecialMagic)3 Minecraft (net.minecraft.client.Minecraft)3 ITextComponent (net.minecraft.util.text.ITextComponent)3 ItemMagicBook (cavern.item.ItemMagicBook)2 MagicCancelMessage (cavern.network.client.MagicCancelMessage)2 ItemStack (net.minecraft.item.ItemStack)2 EnumActionResult (net.minecraft.util.EnumActionResult)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 ParticleMagicSpell (cavern.client.particle.ParticleMagicSpell)1 MagicBookMessage (cavern.network.server.MagicBookMessage)1 MagicResultMessage (cavern.network.server.MagicResultMessage)1 SpecialMagicMessage (cavern.network.server.SpecialMagicMessage)1 EnumHand (net.minecraft.util.EnumHand)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1