Search in sources :

Example 71 with ITextComponent

use of net.minecraft.util.text.ITextComponent in project Cavern2 by kegare.

the class ClientEventHooks method onPlayerLoggedIn.

@SubscribeEvent
public void onPlayerLoggedIn(PlayerLoggedInEvent event) {
    EntityPlayer player = event.player;
    if (MiningAssistConfig.miningAssistNotify) {
        MiningAssist assist = MiningAssist.byPlayer(player);
        if (assist != MiningAssist.DISABLED) {
            ITextComponent message = new TextComponentTranslation(assist.getUnlocalizedName());
            message.getStyle().setColor(TextFormatting.GRAY).setItalic(Boolean.valueOf(true));
            message = new TextComponentTranslation("cavern.miningassist.notify.message", message);
            player.sendMessage(message);
        }
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) ITextComponent(net.minecraft.util.text.ITextComponent) EntityPlayer(net.minecraft.entity.player.EntityPlayer) MiningAssist(cavern.miningassist.MiningAssist) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 72 with ITextComponent

use of net.minecraft.util.text.ITextComponent in project Cavern2 by kegare.

the class ClientEventHooks method onConnected.

@SubscribeEvent
public void onConnected(ClientConnectedToServerEvent event) {
    Minecraft mc = FMLClientHandler.instance().getClient();
    if (GeneralConfig.versionNotify) {
        ITextComponent message;
        ITextComponent name = new TextComponentString(Cavern.metadata.name);
        name.getStyle().setColor(TextFormatting.AQUA);
        if (Version.isOutdated()) {
            ITextComponent latest = new TextComponentString(Version.getLatest().toString());
            latest.getStyle().setColor(TextFormatting.YELLOW);
            message = new TextComponentTranslation("cavern.version.message", name);
            message.appendText(" : ").appendSibling(latest);
            message.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, Cavern.metadata.url));
            mc.ingameGUI.getChatGUI().printChatMessage(message);
        }
        message = null;
        if (Version.DEV_DEBUG) {
            message = new TextComponentTranslation("cavern.version.message.dev", name);
        } else if (Version.isBeta()) {
            message = new TextComponentTranslation("cavern.version.message.beta", name);
        } else if (Version.isAlpha()) {
            message = new TextComponentTranslation("cavern.version.message.alpha", name);
        }
        if (message != null) {
            mc.ingameGUI.getChatGUI().printChatMessage(message);
        }
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) Minecraft(net.minecraft.client.Minecraft) TextComponentString(net.minecraft.util.text.TextComponentString) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 73 with ITextComponent

use of net.minecraft.util.text.ITextComponent in project Cavern2 by kegare.

the class MagicEventHooks method onTick.

@SubscribeEvent
public void onTick(ClientTickEvent event) {
    if (event.phase != Phase.END) {
        return;
    }
    Minecraft mc = FMLClientHandler.instance().getClient();
    if (mc.world == null || mc.player == null || mc.currentScreen != null) {
        return;
    }
    MagicBook book = MagicBook.get(mc.player);
    boolean isMagicKeyDown = CaveKeyBindings.KEY_MAGIC_BOOK.isKeyDown();
    if (isMagicKeyDown || mc.gameSettings.keyBindUseItem.isKeyDown()) {
        ItemStack stack = book.getSpellingMagicBook();
        Magic magic = book.getSpellingMagic();
        if (spellingResult != null && spellingResult != EnumActionResult.PASS) {
            if (!sendResult) {
                if (magic != null) {
                    if (spellingResult == EnumActionResult.SUCCESS) {
                        ActionResult<ITextComponent> result = magic.fireMagic();
                        CaveNetworkRegistry.sendToServer(new MagicResultMessage(result.getType()));
                        ITextComponent message = result.getResult();
                        if (message != null) {
                            mc.ingameGUI.setOverlayMessage(message, true);
                        }
                        if (magic.isOverload()) {
                            book.setSpecialMagic(null);
                        }
                    } else {
                        CaveNetworkRegistry.sendToServer(new MagicResultMessage(EnumActionResult.FAIL));
                    }
                    magic.onCloseBook();
                    SoundEvent sound = magic.getCloseSound();
                    if (sound != null) {
                        mc.getSoundHandler().playDelayedSound(PositionedSoundRecord.getMasterRecord(sound, 1.0F), 5);
                    }
                }
                book.setSpellingMagic(null);
                sendResult = true;
            }
            return;
        }
        if (book.isSpellingCanceled()) {
            spellingResult = EnumActionResult.FAIL;
            return;
        }
        if (magic == null) {
            Pair<EnumHand, ItemStack> magicBook = getMagicBook(mc.player);
            if (magicBook == null) {
                spellingResult = EnumActionResult.FAIL;
                return;
            }
            stack = magicBook.getRight();
            magic = EnumType.byItemStack(stack).createMagic(mc.world, mc.player, magicBook.getLeft());
            if (magic == null) {
                spellingResult = EnumActionResult.FAIL;
                return;
            }
            book.setSpellingMagic(magic);
            if (magic.getSpellingHand() == EnumHand.MAIN_HAND) {
                spellingSlot = mc.player.inventory.currentItem;
            }
            CaveNetworkRegistry.sendToServer(new MagicBookMessage(magic.getSpellingHand()));
        }
        boolean hasSpecialMagic = book.getSpecialMagic() != null;
        boolean infinity = hasSpecialMagic && book.getSpecialMagic() instanceof MagicInfinity;
        if (hasSpecialMagic && magic instanceof SpecialMagic) {
            spellingResult = EnumActionResult.FAIL;
            return;
        }
        if (!mc.player.capabilities.isCreativeMode && ItemMagicBook.isInCoolTime(mc.player, stack)) {
            mc.ingameGUI.setOverlayMessage(new TextComponentTranslation("item.magicBook.fail.time"), false);
            spellingResult = EnumActionResult.FAIL;
            return;
        }
        if (magic.getSpellingHand() == EnumHand.MAIN_HAND) {
            mc.player.inventory.currentItem = spellingSlot;
        }
        double progress = magic.getSpellingProgress();
        if (infinity) {
            progress = MathHelper.clamp(progress * 2.5D, 0.0D, 1.0D);
        }
        if (progress >= 1.0D) {
            spellingResult = EnumActionResult.SUCCESS;
            return;
        }
        EnumActionResult result = magic.onSpelling();
        if (result != EnumActionResult.PASS) {
            spellingResult = result;
            return;
        }
        if (++spellingSoundTicks >= (infinity ? 8 : 12)) {
            SoundEvent sound = magic.getSpellingSound();
            if (sound != null) {
                mc.getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(sound, 1.0F));
            }
            spellingSoundTicks = 0;
        }
        for (int i = 0; i < 2; ++i) {
            int var1 = RANDOM.nextInt(2) * 2 - 1;
            int var2 = RANDOM.nextInt(2) * 2 - 1;
            double ptX = mc.player.posX + 0.25D * var1;
            double ptY = mc.player.posY + 0.7D + RANDOM.nextFloat();
            double ptZ = mc.player.posZ + 0.25D * var2;
            double motionX = RANDOM.nextFloat() * 1.0F * var1;
            double motionY = (RANDOM.nextFloat() - 0.25D) * 0.125D;
            double motionZ = RANDOM.nextFloat() * 1.0F * var2;
            ParticleMagicSpell particle = new ParticleMagicSpell(mc.world, ptX, ptY, ptZ, motionX, motionY, motionZ);
            mc.effectRenderer.addEffect(particle);
        }
    } else {
        Magic magic = book.getSpellingMagic();
        if (magic != null) {
            CaveNetworkRegistry.sendToServer(new MagicResultMessage(EnumActionResult.FAIL));
            magic.onCloseBook();
            SoundEvent sound = magic.getCloseSound();
            if (sound != null) {
                mc.getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(sound, 1.0F));
            }
        }
        book.setSpellingMagic(null);
        spellingResult = null;
        spellingSlot = 0;
        spellingSoundTicks = 0;
        sendResult = false;
    }
    SpecialMagic magic = book.getSpecialMagic();
    if (magic != null && magic.getEffectProgress() >= 1.0D) {
        ITextComponent message = magic.finishMagic();
        if (message != null) {
            mc.ingameGUI.setOverlayMessage(message, false);
        }
        CaveNetworkRegistry.sendToServer(new SpecialMagicMessage());
        book.setSpecialMagic(null);
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) MagicResultMessage(cavern.network.server.MagicResultMessage) Magic(cavern.magic.Magic) SpecialMagic(cavern.magic.SpecialMagic) ParticleMagicSpell(cavern.client.particle.ParticleMagicSpell) ITextComponent(net.minecraft.util.text.ITextComponent) MagicInfinity(cavern.magic.MagicInfinity) SpecialMagicMessage(cavern.network.server.SpecialMagicMessage) Minecraft(net.minecraft.client.Minecraft) SoundEvent(net.minecraft.util.SoundEvent) SpecialMagic(cavern.magic.SpecialMagic) EnumActionResult(net.minecraft.util.EnumActionResult) EnumHand(net.minecraft.util.EnumHand) MagicBookMessage(cavern.network.server.MagicBookMessage) ItemStack(net.minecraft.item.ItemStack) ItemMagicBook(cavern.item.ItemMagicBook) MagicBook(cavern.magic.MagicBook) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 74 with ITextComponent

use of net.minecraft.util.text.ITextComponent in project Cavern2 by kegare.

the class MinerStats method addPoint.

@Override
public void addPoint(int value, boolean adjust) {
    MinerStatsEvent.AddPoint event = new MinerStatsEvent.AddPoint(entityPlayer, this, value);
    if (MinecraftForge.EVENT_BUS.post(event)) {
        return;
    }
    setPoint(point + event.getNewPoint(), adjust);
    if (entityPlayer != null && value > 0 && point > 0 && point % 100 == 0) {
        entityPlayer.addExperience(entityPlayer.xpBarCap() / 2);
    }
    MinerRank current = MinerRank.get(rank);
    int max = MinerRank.values().length - 1;
    boolean promoted = false;
    while (current.getRank() < max) {
        MinerRank next = MinerRank.get(rank + 1);
        if (point >= next.getPhase()) {
            ++rank;
            promoted = true;
            current = next;
            setPoint(point - current.getPhase(), false);
        } else
            break;
    }
    if (promoted) {
        if (adjust) {
            adjustData();
        }
        if (entityPlayer != null && entityPlayer instanceof EntityPlayerMP) {
            EntityPlayerMP player = (EntityPlayerMP) entityPlayer;
            MinecraftServer server = player.mcServer;
            ITextComponent name = new TextComponentTranslation(current.getUnlocalizedName());
            name.getStyle().setBold(true);
            ITextComponent component = new TextComponentTranslation("cavern.minerrank.promoted", player.getDisplayName(), name);
            component.getStyle().setColor(TextFormatting.GRAY).setItalic(true);
            server.getPlayerList().sendMessage(component);
            double x = player.posX;
            double y = player.posY + player.getEyeHeight();
            double z = player.posZ;
            player.getServerWorld().playSound(null, x, y, z, CaveSounds.RANK_PROMOTE, SoundCategory.MASTER, 0.85F, 1.0F);
            switch(current) {
                case IRON_MINER:
                    PlayerHelper.grantAdvancement(player, "iron_miner");
                    break;
                case GOLD_MINER:
                    PlayerHelper.grantAdvancement(player, "gold_miner");
                    break;
                case HEXCITE_MINER:
                    PlayerHelper.grantAdvancement(player, "hexcite_miner");
                    break;
                case DIAMOND_MINER:
                    PlayerHelper.grantAdvancement(player, "diamond_miner");
                    break;
                default:
            }
            if (current.getRank() >= MiningAssistConfig.minerRank.getValue()) {
                PlayerHelper.grantToast(player, "mining_assist");
            }
        }
        MinecraftForge.EVENT_BUS.post(new MinerStatsEvent.PromoteRank(entityPlayer, this));
    }
}
Also used : MinerStatsEvent(cavern.api.event.MinerStatsEvent) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) ITextComponent(net.minecraft.util.text.ITextComponent) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 75 with ITextComponent

use of net.minecraft.util.text.ITextComponent 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)

Aggregations

ITextComponent (net.minecraft.util.text.ITextComponent)116 TextComponentString (net.minecraft.util.text.TextComponentString)53 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)43 EntityPlayer (net.minecraft.entity.player.EntityPlayer)20 ItemStack (net.minecraft.item.ItemStack)17 Style (net.minecraft.util.text.Style)17 ClickEvent (net.minecraft.util.text.event.ClickEvent)16 HoverEvent (net.minecraft.util.text.event.HoverEvent)9 ArrayList (java.util.ArrayList)8 BlockPos (net.minecraft.util.math.BlockPos)8 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)8 Minecraft (net.minecraft.client.Minecraft)5 StringTextComponent (net.minecraft.util.text.StringTextComponent)4 Text (org.spongepowered.api.text.Text)4 MagicBook (cavern.magic.MagicBook)3 SpecialMagic (cavern.magic.SpecialMagic)3 Matcher (java.util.regex.Matcher)3 TileEntity (net.minecraft.tileentity.TileEntity)3 SoundEvent (net.minecraft.util.SoundEvent)3 TextFormatting (net.minecraft.util.text.TextFormatting)3