Fixed FloatingTextRenderer
import org.terasology.world.WorldProvider;
import java.util.Arrays;
-import java.util.List;
import java.util.Map;
-import static org.lwjgl.opengl.GL11.GL_DEPTH_TEST;
-import static org.lwjgl.opengl.GL11.glDisable;
-import static org.lwjgl.opengl.GL11.glEnable;
-import static org.lwjgl.opengl.GL11.glPopMatrix;
-import static org.lwjgl.opengl.GL11.glPushMatrix;
-import static org.lwjgl.opengl.GL11.glScaled;
-import static org.lwjgl.opengl.GL11.glTranslated;
+import static org.lwjgl.opengl.GL11.*;
@RegisterSystem(RegisterMode.CLIENT)
@@ -100,24 +93,23 @@ private void render(Iterable<EntityRef> floatingTextEntities) {
FloatingTextComponent floatingText = entity.getComponent(FloatingTextComponent.class);
- List<String> text = Arrays.asList(floatingText.text.split("\n"));
+ String[] linesOfText = floatingText.text.split("\n");
Color baseColor = floatingText.textColor;
Color shadowColor = floatingText.textShadowColor;
boolean underline = false;
- String longest = "";
- for (String s : text) {
- if (s.length() > longest.length())
- longest = s;
+ int textWidth = font.getWidth("");
+ for (String singleLine : linesOfText) {
+ if (font.getWidth(singleLine) > textWidth)
+ textWidth = font.getWidth(singleLine);
}
- int textWidth = font.getWidth(longest);
FontMeshBuilder meshBuilder = new FontMeshBuilder(underlineMaterial);
Map<Material, Mesh> meshMap = entityMeshCache.get(entity);
if (meshMap == null) {
meshMap = meshBuilder
- .createTextMesh(font, text, textWidth, HorizontalAlign.CENTER, baseColor,
+ .createTextMesh(font, Arrays.asList(linesOfText), textWidth, HorizontalAlign.CENTER, baseColor,
shadowColor, underline);
entityMeshCache.put(entity, meshMap);
}
