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));
}
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"));
}
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"));
}
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);
}
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;
}
Aggregations