Search in sources :

Example 11 with ITextComponent

use of net.minecraft.util.text.ITextComponent in project SpongeCommon by SpongePowered.

the class MixinEntityPlayerMP method sendMessage.

@Override
public void sendMessage(ChatType type, Text message) {
    if (this.isFake) {
        // Don't bother sending messages to fake players
        return;
    }
    checkNotNull(type, "type");
    checkNotNull(message, "message");
    ITextComponent component = SpongeTexts.toComponent(message);
    if (type == ChatTypes.ACTION_BAR) {
        component = SpongeTexts.fixActionBarFormatting(component);
    }
    this.connection.sendPacket(new SPacketChat(component, (net.minecraft.util.text.ChatType) (Object) type));
}
Also used : SPacketChat(net.minecraft.network.play.server.SPacketChat) ChatType(org.spongepowered.api.text.chat.ChatType) ITextComponent(net.minecraft.util.text.ITextComponent)

Example 12 with ITextComponent

use of net.minecraft.util.text.ITextComponent in project SpongeCommon by SpongePowered.

the class LegacySerializerTest method testNestedText.

@Test
public void testNestedText() {
    ITextComponent component = new TextComponentString("first");
    component.getStyle().setColor(TextFormatting.RED);
    component.appendSibling(new TextComponentString("second"));
    TextComponentString component2 = new TextComponentString("third");
    component2.getStyle().setColor(TextFormatting.BLUE);
    component.appendSibling(component2);
    assertThat(SpongeTexts.toLegacy(component), is(COLOR_CHAR + "cfirstsecond" + COLOR_CHAR + "9third"));
}
Also used : ITextComponent(net.minecraft.util.text.ITextComponent) TextComponentString(net.minecraft.util.text.TextComponentString) Test(org.junit.Test)

Example 13 with ITextComponent

use of net.minecraft.util.text.ITextComponent in project SpongeCommon by SpongePowered.

the class LegacySerializerTest method testColoredText.

@Test
public void testColoredText() {
    ITextComponent component = new TextComponentString("test");
    component.getStyle().setColor(TextFormatting.RED);
    assertThat(SpongeTexts.toLegacy(component), is(COLOR_CHAR + "ctest"));
}
Also used : ITextComponent(net.minecraft.util.text.ITextComponent) TextComponentString(net.minecraft.util.text.TextComponentString) Test(org.junit.Test)

Example 14 with ITextComponent

use of net.minecraft.util.text.ITextComponent in project Charset by CharsetMC.

the class ProjectorHandlerBook method render.

@Override
@SideOnly(Side.CLIENT)
public void render(ItemStack stack, IProjector projector, IProjectorSurface surface) {
    // oh boy! text!
    if (stack.hasTagCompound()) {
        GlStateManager.pushMatrix();
        GlStateManager.translate(((surface.getCornerStart().x + surface.getCornerEnd().x) / 2) + surface.getScreenFacing().getFrontOffsetX() * 0.001f, ((surface.getCornerStart().y + surface.getCornerEnd().y) / 2) + surface.getScreenFacing().getFrontOffsetY() * 0.001f, ((surface.getCornerStart().z + surface.getCornerEnd().z) / 2) + surface.getScreenFacing().getFrontOffsetZ() * 0.001f);
        Orientation orientation = ProjectorHelper.INSTANCE.getOrientation(surface);
        Quaternion.fromOrientation(orientation).glRotate();
        GlStateManager.rotate(270.0f, 0, 0, 1);
        GlStateManager.rotate(270.0f, 0, 1, 0);
        GlStateManager.translate(0, 0, -ProjectorHelper.OFFSET);
        float scaleVal = 2f * surface.getWidth() / 146f;
        GlStateManager.scale(scaleVal, scaleVal, scaleVal);
        FontRenderer renderer = Minecraft.getMinecraft().fontRenderer;
        NBTTagList pages = stack.getTagCompound().getTagList("pages", Constants.NBT.TAG_STRING);
        if (pages.tagCount() > projector.getPage()) {
            String pageCount = I18n.format("book.pageIndicator", projector.getPage() + 1, pages.tagCount());
            renderer.drawString(pageCount, -73 + 129 - renderer.getStringWidth(pageCount), -90 + 15, 0xFF000000);
            String page = ((NBTTagString) pages.get(projector.getPage())).getString();
            ITextComponent fullComponent = ITextComponent.Serializer.jsonToComponent(page);
            if (fullComponent != null) {
                List<ITextComponent> components = GuiUtilRenderComponents.splitText(fullComponent, 116, renderer, true, true);
                for (int i = 0; i < components.size(); i++) {
                    renderer.drawString(components.get(i).getUnformattedText(), -73 + 16, -90 + 30 + i * renderer.FONT_HEIGHT, 0xFF000000);
                }
            }
        }
        GlStateManager.popMatrix();
        surface.restoreGLColor();
    }
    Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation("textures/gui/book.png"));
    ProjectorHelper.INSTANCE.renderTexture(surface, 20, 20 + 146, 1, 1 + 180);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) ResourceLocation(net.minecraft.util.ResourceLocation) ITextComponent(net.minecraft.util.text.ITextComponent) NBTTagString(net.minecraft.nbt.NBTTagString) FontRenderer(net.minecraft.client.gui.FontRenderer) NBTTagString(net.minecraft.nbt.NBTTagString) Orientation(pl.asie.charset.lib.utils.Orientation) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 15 with ITextComponent

use of net.minecraft.util.text.ITextComponent in project Charset by CharsetMC.

the class LockEventHandler method unlockOrRaiseError.

public static boolean unlockOrRaiseError(EntityPlayer player, TileEntity tile, Lockable lock) {
    if (player.getEntityWorld().isRemote) {
        return true;
    }
    boolean canUnlock = false;
    for (ItemStack stack : getPotentialKeys(player)) {
        if (!stack.isEmpty() && stack.getItem() instanceof IKeyItem) {
            IKeyItem key = (IKeyItem) stack.getItem();
            canUnlock = key.canUnlock(lock.getLock().getLockKey(), stack);
            if (canUnlock) {
                break;
            }
        }
    }
    if (!canUnlock) {
        ITextComponent displayName = tile.getDisplayName();
        if (displayName == null) {
            displayName = new TextComponentTranslation(tile.getBlockType().getUnlocalizedName() + ".name");
        }
        new Notice(tile, new TextComponentTranslation("container.isLocked", displayName)).sendTo(player);
        player.getEntityWorld().playSound(player, tile.getPos(), SoundEvents.BLOCK_CHEST_LOCKED, SoundCategory.BLOCKS, 1.0f, 1.0f);
    }
    return canUnlock;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) Notice(pl.asie.charset.lib.notify.Notice) IKeyItem(pl.asie.charset.api.storage.IKeyItem) ITextComponent(net.minecraft.util.text.ITextComponent) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ITextComponent (net.minecraft.util.text.ITextComponent)96 TextComponentString (net.minecraft.util.text.TextComponentString)54 EntityPlayer (net.minecraft.entity.player.EntityPlayer)26 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)25 ClickEvent (net.minecraft.util.text.event.ClickEvent)16 ItemStack (net.minecraft.item.ItemStack)11 Style (net.minecraft.util.text.Style)8 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)8 HoverEvent (net.minecraft.util.text.event.HoverEvent)7 World (net.minecraft.world.World)7 ArrayList (java.util.ArrayList)6 BlockPos (net.minecraft.util.math.BlockPos)6 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)5 RfToolsDimensionManager (mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)5 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)5 Minecraft (net.minecraft.client.Minecraft)4 Text (org.spongepowered.api.text.Text)4 MagicBook (cavern.magic.MagicBook)3 SpecialMagic (cavern.magic.SpecialMagic)3 Matcher (java.util.regex.Matcher)3