Rename
This commit is contained in:
74
src/main/java/exopandora/worldhandler/text/EnumColor.java
Normal file
74
src/main/java/exopandora/worldhandler/text/EnumColor.java
Normal file
@@ -0,0 +1,74 @@
|
||||
package exopandora.worldhandler.format;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
/**
|
||||
* XXX To be replaced with TextFormatting
|
||||
*/
|
||||
@Deprecated
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public enum EnumColor
|
||||
{
|
||||
DEFAULT("reset", "r"),
|
||||
YELLOW("yellow", "e"),
|
||||
GOLD("gold", "6"),
|
||||
DARK_RED("dark_red", "4"),
|
||||
RED("red", "c"),
|
||||
LIGHT_PURPLE("light_purple", "d"),
|
||||
DARK_PURPLE("dark_purple", "5"),
|
||||
BLUE("blue", "9"),
|
||||
DARK_BLUE("dark_blue", "1"),
|
||||
DARK_AQUA("dark_aqua", "3"),
|
||||
AQUA("aqua", "b"),
|
||||
GREEN("green", "a"),
|
||||
DARK_GREEN("dark_green", "2"),
|
||||
BLACK("black", "0"),
|
||||
DARK_GRAY("dark_gray", "8"),
|
||||
GRAY("gray", "7"),
|
||||
WHITE("white", "f"),
|
||||
|
||||
OBFUSCATED("obfuscated", "k"),
|
||||
BOLD("bold", "l"),
|
||||
STRIKETHROUGH("strikethrough", "m"),
|
||||
UNDERLINE("underline", "n"),
|
||||
ITALIC("italic", "o");
|
||||
|
||||
private String name;
|
||||
private String prefix;
|
||||
|
||||
private EnumColor(String name, String prefix)
|
||||
{
|
||||
this.name = name;
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getPrefix()
|
||||
{
|
||||
return this.prefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "\u00A7" + this.prefix;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static EnumColor getColorFromId(int id)
|
||||
{
|
||||
if(id >= 0 && id < EnumColor.values().length)
|
||||
{
|
||||
return EnumColor.values()[id];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
70
src/main/java/exopandora/worldhandler/text/SignText.java
Normal file
70
src/main/java/exopandora/worldhandler/text/SignText.java
Normal file
@@ -0,0 +1,70 @@
|
||||
package exopandora.worldhandler.format.text;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class SignText
|
||||
{
|
||||
private static final Gson GSON = new GsonBuilder().registerTypeAdapter(JsonSignLine.class, new JsonSignLineSerializer()).create();
|
||||
|
||||
private ColoredString text = new ColoredString();
|
||||
private String command;
|
||||
private final int line;
|
||||
|
||||
public SignText(int line)
|
||||
{
|
||||
this.line = line;
|
||||
}
|
||||
|
||||
public int getLine()
|
||||
{
|
||||
return this.line;
|
||||
}
|
||||
|
||||
public ColoredString getColoredString()
|
||||
{
|
||||
return this.text;
|
||||
}
|
||||
|
||||
public void setColoredString(ColoredString coloredString)
|
||||
{
|
||||
this.text = coloredString;
|
||||
}
|
||||
|
||||
public String getCommand()
|
||||
{
|
||||
return this.command;
|
||||
}
|
||||
|
||||
public void setCommand(String command)
|
||||
{
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
public boolean hasCommand()
|
||||
{
|
||||
return this.command != null && !this.command.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
if(!this.text.isSpecial() && !this.hasCommand())
|
||||
{
|
||||
return this.text.getText();
|
||||
}
|
||||
|
||||
JsonSignLine line = new JsonSignLine(this.text);
|
||||
|
||||
if(this.hasCommand())
|
||||
{
|
||||
line.setClickEvent(new JsonClickEvent("run_command", FormattedString.getPreformattedString(this.command)));
|
||||
}
|
||||
|
||||
return GSON.toJson(line);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package exopandora.worldhandler.format;
|
||||
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class TextFormatting
|
||||
{
|
||||
public static String shortenString(String str, int maxWidth, FontRenderer fontRenderer)
|
||||
{
|
||||
return TextFormatting.shortenString(str, "", maxWidth, fontRenderer);
|
||||
}
|
||||
|
||||
public static String shortenString(String str, String prefix, int maxWidth, FontRenderer fontRenderer)
|
||||
{
|
||||
String display = prefix;
|
||||
|
||||
if(fontRenderer.getStringWidth(prefix + str) > (maxWidth - fontRenderer.getStringWidth(prefix)))
|
||||
{
|
||||
for(int x = 0; x < str.length(); x++)
|
||||
{
|
||||
if(fontRenderer.getStringWidth(display + str.charAt(x) + "...") < maxWidth)
|
||||
{
|
||||
display += str.charAt(x);
|
||||
}
|
||||
else
|
||||
{
|
||||
display += "...";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
display += str;
|
||||
}
|
||||
|
||||
return display;
|
||||
}
|
||||
|
||||
public static String getTotalTimePlayed(long tick)
|
||||
{
|
||||
int days = 0;
|
||||
int hours = 0;
|
||||
int minutes = 0;
|
||||
int seconds = 0;
|
||||
|
||||
seconds = (int) (tick / 20);
|
||||
|
||||
if(seconds > 60)
|
||||
{
|
||||
int min = MathHelper.floor(seconds / 60);
|
||||
seconds = seconds % 60;
|
||||
minutes = min;
|
||||
}
|
||||
|
||||
if(minutes > 60)
|
||||
{
|
||||
int hrs = MathHelper.floor(minutes / 60);
|
||||
minutes = minutes % 60;
|
||||
hours = hrs;
|
||||
}
|
||||
|
||||
if(hours > 24)
|
||||
{
|
||||
int day = MathHelper.floor(hours / 24);
|
||||
hours = hours % 24;
|
||||
days = day;
|
||||
}
|
||||
|
||||
return String.format("%d:%02d:%02d:%02d", days, hours, minutes, seconds);
|
||||
}
|
||||
|
||||
public static int getHour(long tick)
|
||||
{
|
||||
int hour = MathHelper.floor((tick + 6000) / 1000F) % 24;
|
||||
|
||||
return hour;
|
||||
}
|
||||
|
||||
public static int getMinute(long tick)
|
||||
{
|
||||
int hour = MathHelper.floor((tick + 6000F) / 1000F);
|
||||
int minute = MathHelper.floor((tick + 6000F - hour * 1000) * 6 / 100);
|
||||
|
||||
return minute;
|
||||
}
|
||||
|
||||
public static String formatWorldTime(long tick)
|
||||
{
|
||||
int hour = TextFormatting.getHour(tick);
|
||||
int minute = TextFormatting.getMinute(tick);
|
||||
|
||||
return String.format("%02d:%02d", hour, minute);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user