use of net.minecraft.util.text.ITextComponent in project SpongeCommon by SpongePowered.
the class MixinPlayerList method disconnectClient.
private void disconnectClient(NetworkManager netManager, Optional<Text> disconnectMessage, @Nullable GameProfile profile) {
ITextComponent reason;
if (disconnectMessage.isPresent()) {
reason = SpongeTexts.toComponent(disconnectMessage.get());
} else {
reason = new TextComponentTranslation("disconnect.disconnected");
}
try {
LOGGER.info("Disconnecting " + (profile != null ? profile.toString() + " (" + netManager.getRemoteAddress().toString() + ")" : String.valueOf(netManager.getRemoteAddress() + ": " + reason.getUnformattedText())));
netManager.sendPacket(new SPacketDisconnect(reason));
netManager.closeChannel(reason);
} catch (Exception exception) {
LOGGER.error("Error whilst disconnecting player", exception);
}
}
use of net.minecraft.util.text.ITextComponent in project SpongeCommon by SpongePowered.
the class MixinTextComponentBase method toLegacy.
@Override
public String toLegacy(char code) {
StringBuilder builder = new StringBuilder();
ResolvedChatStyle current = null;
Style previous = null;
for (ITextComponent component : withChildren()) {
Style newStyle = component.getStyle();
ResolvedChatStyle style = resolve(current, previous, newStyle);
previous = newStyle;
if (current == null || (current.color != style.color) || (current.bold && !style.bold) || (current.italic && !style.italic) || (current.underlined && !style.underlined) || (current.strikethrough && !style.strikethrough) || (current.obfuscated && !style.obfuscated)) {
if (style.color != null) {
apply(builder, code, style.color);
} else if (current != null) {
apply(builder, code, RESET);
}
apply(builder, code, BOLD, style.bold);
apply(builder, code, ITALIC, style.italic);
apply(builder, code, UNDERLINE, style.underlined);
apply(builder, code, STRIKETHROUGH, style.strikethrough);
apply(builder, code, OBFUSCATED, style.obfuscated);
} else {
apply(builder, code, BOLD, current.bold != style.bold);
apply(builder, code, ITALIC, current.italic != style.italic);
apply(builder, code, UNDERLINE, current.underlined != style.underlined);
apply(builder, code, STRIKETHROUGH, current.strikethrough != style.strikethrough);
apply(builder, code, OBFUSCATED, current.obfuscated != style.obfuscated);
}
current = style;
builder.append(component.getUnformattedComponentText());
}
return builder.toString();
}
use of net.minecraft.util.text.ITextComponent in project SpongeCommon by SpongePowered.
the class SpongeTexts method fixActionBarFormatting.
public static ITextComponent fixActionBarFormatting(ITextComponent component) {
if (!component.getSiblings().isEmpty()) {
List<ITextComponent> children = component.getSiblings();
for (int i = 0; i < children.size(); i++) {
children.set(i, fixActionBarFormatting(children.get(i)));
}
}
TextComponentString result = new TextComponentString(((IMixinTextComponent) component).getLegacyFormatting());
result.appendSibling(component);
return result;
}
use of net.minecraft.util.text.ITextComponent in project SpongeCommon by SpongePowered.
the class TextComponentIterator method init.
private ITextComponent init() {
this.children = this.component.childrenIterator();
ITextComponent result = this.component;
this.component = null;
// initialize currentChildIterator so that the following call to 'hasNext()' will properly return 'false' if necessary
if (this.children.hasNext()) {
this.setCurrentChildIterator();
}
return result;
}
use of net.minecraft.util.text.ITextComponent in project Almura by AlmuraDev.
the class MixinTileEntitySignRenderer method render.
/**
* @author Grinch - Steven Downer
* @reason Do not render signposts past a configurable length. Fairly decent client optimization.
*/
@Overwrite
public void render(TileEntitySign te, double x, double y, double z, float partialTicks, int destroyStage, float val) {
final ClientConfiguration config = StaticAccess.config.get();
Block block = te.getBlockType();
GlStateManager.pushMatrix();
float f = 0.6666667F;
if (block == Blocks.STANDING_SIGN) {
GlStateManager.translate((float) x + 0.5F, (float) y + 0.5F, (float) z + 0.5F);
float f1 = (float) (te.getBlockMetadata() * 360) / 16.0F;
GlStateManager.rotate(-f1, 0.0F, 1.0F, 0.0F);
this.model.signStick.showModel = true;
} else {
int k = te.getBlockMetadata();
float f2 = 0.0F;
if (k == 2) {
f2 = 180.0F;
}
if (k == 4) {
f2 = 90.0F;
}
if (k == 5) {
f2 = -90.0F;
}
GlStateManager.translate((float) x + 0.5F, (float) y + 0.5F, (float) z + 0.5F);
GlStateManager.rotate(-f2, 0.0F, 1.0F, 0.0F);
GlStateManager.translate(0.0F, -0.3125F, -0.4375F);
this.model.signStick.showModel = false;
}
if (destroyStage >= 0) {
this.bindTexture(DESTROY_STAGES[destroyStage]);
GlStateManager.matrixMode(5890);
GlStateManager.pushMatrix();
GlStateManager.scale(4.0F, 2.0F, 1.0F);
GlStateManager.translate(0.0625F, 0.0625F, 0.0625F);
GlStateManager.matrixMode(5888);
} else {
this.bindTexture(SIGN_TEXTURE);
}
GlStateManager.enableRescaleNormal();
GlStateManager.pushMatrix();
GlStateManager.scale(0.6666667F, -0.6666667F, -0.6666667F);
this.model.renderSign();
GlStateManager.popMatrix();
FontRenderer fontrenderer = this.getFontRenderer();
float f3 = 0.010416667F;
GlStateManager.translate(0.0F, 0.33333334F, 0.046666667F);
GlStateManager.scale(0.010416667F, -0.010416667F, 0.010416667F);
GlStateManager.glNormal3f(0.0F, 0.0F, -0.010416667F);
GlStateManager.depthMask(false);
int i = 0;
// Almura start
boolean renderText = te.signText.length > 0;
if (renderText) {
// Greater than 0 means the client has selected a non-Vanilla render distance
if (config.client.signTextRenderDistance > 0) {
EntityLivingBase viewer = (EntityLivingBase) Minecraft.getMinecraft().getRenderViewEntity();
if (viewer == null) {
viewer = Minecraft.getMinecraft().player;
}
if (viewer == null || !te.hasWorld() || te.getDistanceSq(viewer.posX, viewer.posY, viewer.posZ) > (config.client.signTextRenderDistance * 16)) {
renderText = false;
}
}
}
if (renderText && destroyStage < 0) {
// Almura End
for (int j = 0; j < te.signText.length; ++j) {
if (te.signText[j] != null) {
ITextComponent itextcomponent = te.signText[j];
List<ITextComponent> list = GuiUtilRenderComponents.splitText(itextcomponent, 90, fontrenderer, false, true);
String s = list != null && !list.isEmpty() ? ((ITextComponent) list.get(0)).getFormattedText() : "";
if (j == te.lineBeingEdited) {
s = "> " + s + " <";
fontrenderer.drawString(s, -fontrenderer.getStringWidth(s) / 2, j * 10 - te.signText.length * 5, 0);
} else {
fontrenderer.drawString(s, -fontrenderer.getStringWidth(s) / 2, j * 10 - te.signText.length * 5, 0);
}
}
}
}
GlStateManager.depthMask(true);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.popMatrix();
if (destroyStage >= 0) {
GlStateManager.matrixMode(5890);
GlStateManager.popMatrix();
GlStateManager.matrixMode(5888);
}
}
Aggregations