Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
965a3ea62d | ||
|
|
a36058459f | ||
|
|
962c2f5f2b | ||
| cda526d41d | |||
|
|
1321bb3cca | ||
| 47e475cecb |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -116,3 +116,8 @@ run/
|
||||
|
||||
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
||||
!gradle-wrapper.jar
|
||||
|
||||
# Gradle files
|
||||
gradlew
|
||||
gradlew.bat
|
||||
gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
@@ -15,10 +15,8 @@ import net.minecraft.world.entity.vehicle.Boat;
|
||||
import net.minecraft.world.entity.vehicle.Minecart;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
@@ -67,14 +65,8 @@ public class Client {
|
||||
|
||||
ClientGuiEvent.RENDER_HUD.register(Client::render);
|
||||
|
||||
try {
|
||||
img = ImageIO.read(Objects.requireNonNull(Speedometer.class.getResourceAsStream("/assets/speedometer/meter/meter-19.png")));
|
||||
}catch (NullPointerException | IOException e){
|
||||
LOGGER.warn("Can't load speedometer icon. speedometer visual display is disabled");
|
||||
speedometerVisualDisplayFailed = true;
|
||||
}
|
||||
|
||||
if(img == null){
|
||||
LOGGER.info("Loading speedometer ");
|
||||
if(!MeterImages.LARGE.initiate()){
|
||||
speedometerVisualDisplayFailed = true;
|
||||
}
|
||||
|
||||
@@ -139,30 +131,39 @@ public class Client {
|
||||
}/100;
|
||||
double i = (v *(316-45))+45;
|
||||
|
||||
int yPos = getPos(graphics, Config.getYPosition(), 1);
|
||||
int xPos = getPos(graphics, Config.getXPosition(), 0);
|
||||
|
||||
int lineHeight = Minecraft.getInstance().font.lineHeight;
|
||||
|
||||
if(Config.getVisualSpeedometer() && !speedometerVisualDisplayFailed){
|
||||
|
||||
//double v = speedTypeSpeed / speedType.gatMaxVisual();
|
||||
|
||||
MeterImages meterImage = null;
|
||||
int minDiff = 10000;
|
||||
img = ImageHandler.clone(MeterImages.LARGE.getImage());
|
||||
|
||||
for(MeterImages meterImage1 : MeterImages.values()){
|
||||
int diff = Math.abs(meterImage1.getSize()-Config.getImageSize());
|
||||
if(minDiff > diff && meterImage1.getImage() != null){
|
||||
minDiff = diff;
|
||||
meterImage = meterImage1;
|
||||
}
|
||||
Graphics2D g2d = img.createGraphics();
|
||||
|
||||
g2d.setColor(new Color(138, 0, 0));
|
||||
g2d.setFont(new Font(g2d.getFont().getName(), Font.PLAIN, 15));
|
||||
|
||||
if(Config.getShowVisualSpeedType()) {
|
||||
g2d.drawString(SpeedTypes.getName(speedType).getString(), img.getWidth() / 2 - 27, img.getHeight() / 2 + 25);
|
||||
}
|
||||
if(Config.getShowSpeedType()){
|
||||
String speedString = SpeedTypes.getName(speedType).getString();
|
||||
int width = Minecraft.getInstance().font.width(speedString);
|
||||
drawString(graphics, xPos - width, yPos - Config.getImageSize() - lineHeight - 1, speedString, Config.getColor().getColor());
|
||||
}
|
||||
|
||||
img = meterImage.getImage();
|
||||
|
||||
int radius = Config.getImageSize()/2-4;
|
||||
|
||||
int x3 = (int) Math.round(radius*Math.cos(Math.toRadians(i+90)))+(Config.getImageSize()/2);
|
||||
int y3 = (int) Math.round(radius*Math.sin(Math.toRadians(i+90)))+(Config.getImageSize()/2);
|
||||
|
||||
BufferedImage img = ImageHandler.scale(Client.img, Config.getImageSize(), Config.getImageSize());
|
||||
Graphics2D g2d = img.createGraphics();
|
||||
|
||||
int radius = img.getWidth()/2-4;
|
||||
|
||||
int x3 = (int) Math.round(radius*Math.cos(Math.toRadians(i+90)))+(img.getWidth()/2);
|
||||
int y3 = (int) Math.round(radius*Math.sin(Math.toRadians(i+90)))+(img.getHeight()/2);
|
||||
|
||||
g2d = img.createGraphics();
|
||||
|
||||
g2d.setColor(new Color(138, 0, 0));
|
||||
|
||||
@@ -170,9 +171,6 @@ public class Client {
|
||||
|
||||
g2d.drawLine(x3,y3,img.getWidth()/2,img.getHeight()/2);
|
||||
|
||||
int xPos = getPos(graphics, Config.getXPosition(), 0, false);
|
||||
int yPos = getPos(graphics, Config.getYPosition(), 1, true);
|
||||
|
||||
for(int x1 = 0; x1 < img.getWidth(); x1++){
|
||||
for(int y1 = 0; y1 < img.getHeight(); y1++){
|
||||
int x2 = x1 + xPos - img.getWidth();
|
||||
@@ -203,12 +201,11 @@ public class Client {
|
||||
// k -> color RGB int
|
||||
String speedString = format + " " + SpeedTypes.getName(speedType).getString();
|
||||
int width = Minecraft.getInstance().font.width(speedString);
|
||||
int lineHeight = Minecraft.getInstance().font.lineHeight;
|
||||
graphics.drawString(
|
||||
Minecraft.getInstance().font,
|
||||
speedString,
|
||||
getPos(graphics, Config.getXPosition(), 0, false) - width,
|
||||
getPos(graphics, Config.getYPosition(), 1, true) - lineHeight,
|
||||
xPos - width,
|
||||
yPos - lineHeight,
|
||||
Config.getColor().getColor()
|
||||
);
|
||||
}
|
||||
@@ -231,7 +228,8 @@ public class Client {
|
||||
"Velocity total average: " + speed + "\n" +
|
||||
"Velocity total in " + speedType.name() + ": " + speedTypeSpeed + "\n" +
|
||||
"Percentage point of visual speedometer: " + v + "\n" +
|
||||
"Degree end point: " + (i+45);
|
||||
"Degree end point: " + (i+45) +"\n" +
|
||||
(Config.getVisualSpeedometer()?"Visual Size: ":"Textual display") + Config.getImageSize();
|
||||
|
||||
Color color = new Color(255, 255, 255);
|
||||
|
||||
@@ -253,9 +251,7 @@ public class Client {
|
||||
);
|
||||
}
|
||||
|
||||
static boolean flag = true;
|
||||
|
||||
private static int getPos(GuiGraphics event, String input, int type, boolean changeFlag) {
|
||||
private static int getPos(GuiGraphics event, String input, int type) {
|
||||
ArrayList<String> passerPose = new ArrayList<>();
|
||||
final char[] s = input.toCharArray();
|
||||
try{
|
||||
@@ -274,7 +270,7 @@ public class Client {
|
||||
passerPose.add("/");
|
||||
}else if(s[i] == '/'){
|
||||
passerPose.add("/");
|
||||
}else if(testIfInt(s[i])){
|
||||
}else if(Character.isDigit(s[i])){
|
||||
try{
|
||||
Integer.parseInt(passerPose.get(i-1));
|
||||
passerPose.add(i-1,passerPose.get(i-1)+s[i]);
|
||||
@@ -290,7 +286,7 @@ public class Client {
|
||||
defaultValues(event, type, passerPose);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
|
||||
int xPos;
|
||||
try{
|
||||
@@ -320,11 +316,12 @@ public class Client {
|
||||
xPos /= Integer.parseInt(s2);
|
||||
}
|
||||
}
|
||||
if((Platform.isDevelopmentEnvironment() || Config.isDebug()) && flag) {
|
||||
if((Config.isDebug()) && Config.getCounter() < 2) {
|
||||
LOGGER.info("Selected speed type: "+SpeedTypes.getName(Config.getSpeedType()).getString()+"\n"+
|
||||
Arrays.toString(passerPose.toArray())+"\n\n"+
|
||||
xPos);
|
||||
flag = !changeFlag;
|
||||
xPos+"\n\n"+
|
||||
(type==0?Config.getXPosition():Config.getYPosition()));
|
||||
Config.addCounter();
|
||||
}
|
||||
return xPos;
|
||||
}
|
||||
@@ -333,19 +330,11 @@ public class Client {
|
||||
if(type == 0){
|
||||
passerPose.add(String.valueOf(event.guiWidth()));
|
||||
passerPose.add("-");
|
||||
passerPose.add("70");
|
||||
passerPose.add("3");
|
||||
}else if(type == 1){
|
||||
passerPose.add(String.valueOf(event.guiHeight()));
|
||||
passerPose.add("-");
|
||||
passerPose.add("15");
|
||||
passerPose.add("3");
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean testIfInt(char c) {
|
||||
int i = Integer.parseInt(Character.toString(c));
|
||||
return (i == 0 || i == 1 || i == 2 ||
|
||||
i == 3 || i == 4 || i == 5 ||
|
||||
i == 6 || i == 7 || i == 8 ||
|
||||
i == 9);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,46 +10,47 @@ import me.shedaniel.math.Color;
|
||||
import static me.zacharias.speedometer.Speedometer.MOD_ID;
|
||||
|
||||
public class Config {
|
||||
private static JSONObject Config;
|
||||
private static JSONObject config;
|
||||
public static final float configVersion = 3f;
|
||||
private static int counter = 0;
|
||||
|
||||
public static void initialize(){
|
||||
if(Config != null) throw new RuntimeException("Already Initialized");
|
||||
File config = new File(Platform.getConfigFolder().toString()+"/"+MOD_ID+"/config.json");
|
||||
if(!config.exists()){
|
||||
if(config != null) throw new RuntimeException("Already Initialized");
|
||||
File configFile = new File(Platform.getConfigFolder().toString()+"/"+MOD_ID+"/config.json");
|
||||
if(!configFile.exists()){
|
||||
try {
|
||||
config.getParentFile().mkdir();
|
||||
config.createNewFile();
|
||||
configFile.getParentFile().mkdir();
|
||||
configFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Config = new JSONObject();
|
||||
config = new JSONObject();
|
||||
|
||||
defualt();
|
||||
}else {
|
||||
try {
|
||||
BufferedReader in = new BufferedReader(new FileReader(config));
|
||||
BufferedReader in = new BufferedReader(new FileReader(configFile));
|
||||
String tmp;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
while((tmp = in.readLine()) != null){
|
||||
builder.append(tmp);
|
||||
}
|
||||
Config = new JSONObject(builder.toString());
|
||||
if(Config.has("version")){
|
||||
if(Config.getFloat("version")!=configVersion){
|
||||
if(Config.getFloat("version") > configVersion){
|
||||
config = new JSONObject(builder.toString());
|
||||
if(config.has("version")){
|
||||
if(config.getFloat("version")!=configVersion){
|
||||
if(config.getFloat("version") > configVersion){
|
||||
defualt();
|
||||
|
||||
save();
|
||||
}else if(Config.getFloat("version") < configVersion){
|
||||
Config = new JSONObject();
|
||||
}else if(config.getFloat("version") < configVersion){
|
||||
config = new JSONObject();
|
||||
|
||||
defualt();
|
||||
save();
|
||||
}
|
||||
}
|
||||
}else{
|
||||
Config = new JSONObject();
|
||||
config = new JSONObject();
|
||||
defualt();
|
||||
save();
|
||||
}
|
||||
@@ -60,53 +61,48 @@ public class Config {
|
||||
}
|
||||
|
||||
private static void defualt() {
|
||||
if(!Config.has("speed")) {
|
||||
Config.put("speed", SpeedTypes.BlockPS);
|
||||
if(!config.has("speed")) {
|
||||
config.put("speed", SpeedTypes.BlockPS);
|
||||
}
|
||||
if(!Config.has("useKnot")) {
|
||||
Config.put("useKnot", false);
|
||||
if(!config.has("useKnot")) {
|
||||
config.put("useKnot", false);
|
||||
}
|
||||
if(!Config.has("color")) {
|
||||
Config.put("color", new JSONObject()
|
||||
if(!config.has("color")) {
|
||||
config.put("color", new JSONObject()
|
||||
.put("r", 16)
|
||||
.put("g", 146)
|
||||
.put("b", 158)
|
||||
);
|
||||
}
|
||||
if(!Config.has("visualSpeedometer")) {
|
||||
Config.put("visualSpeedometer", false);
|
||||
if(!config.has("visualSpeedometer")) {
|
||||
config.put("visualSpeedometer", false);
|
||||
}
|
||||
|
||||
/*if(!Config.has("xPositionVisual")) {
|
||||
Config.put("xPositionVisual", "W-3");
|
||||
if(!config.has("xPosition")) {
|
||||
config.put("xPosition", "W-3");
|
||||
}
|
||||
if(!Config.has("yPositionVisual")) {
|
||||
Config.put("yPositionVisual", "H-3");
|
||||
}
|
||||
if(!Config.has("xPositionText")) {
|
||||
Config.put("xPositionText", "W-3");
|
||||
}
|
||||
if(!Config.has("yPositionText")) {
|
||||
Config.put("yPositionText", "H-3");
|
||||
}*/
|
||||
|
||||
if(!Config.has("xPosition")) {
|
||||
Config.put("xPosition", "W-3");
|
||||
}
|
||||
if(!Config.has("yPosition")) {
|
||||
Config.put("yPosition", "H-3");
|
||||
if(!config.has("yPosition")) {
|
||||
config.put("yPosition", "H-3");
|
||||
}
|
||||
|
||||
if(!Config.has("debug")) {
|
||||
Config.put("debug", false);
|
||||
if(!config.has("debug")) {
|
||||
config.put("debug", false);
|
||||
}
|
||||
|
||||
if(!Config.has("imagSize")) {
|
||||
Config.put("imageSize", 19);
|
||||
if(!config.has("imagSize")) {
|
||||
config.put("imageSize", 19);
|
||||
}
|
||||
|
||||
if(!Config.has("version")) {
|
||||
Config.put("version", configVersion);
|
||||
if(!config.has("version")) {
|
||||
config.put("version", configVersion);
|
||||
}
|
||||
|
||||
if(!config.has("showVisualSpeedType")){
|
||||
config.put("showVisualSpeedType", false);
|
||||
}
|
||||
|
||||
if(!config.has("showSpeedType")){
|
||||
config.put("showSpeedType", false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,33 +118,34 @@ public class Config {
|
||||
}
|
||||
try {
|
||||
BufferedWriter out = new BufferedWriter(new FileWriter(config));
|
||||
out.write(Config.toString(4));
|
||||
out.write(Config.config.toString(4));
|
||||
out.flush();
|
||||
out.close();
|
||||
}catch (Exception e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
counter=0;
|
||||
}
|
||||
|
||||
public static SpeedTypes getSpeedType(){
|
||||
if(Config.has("speed")){
|
||||
return Config.getEnum(SpeedTypes.class, "speed");
|
||||
if(config.has("speed")){
|
||||
return config.getEnum(SpeedTypes.class, "speed");
|
||||
}else{
|
||||
return SpeedTypes.BlockPS;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean getUseKnot() {
|
||||
if(Config.has("useKnot")){
|
||||
return Config.getBoolean("useKnot");
|
||||
if(config.has("useKnot")){
|
||||
return config.getBoolean("useKnot");
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static Color getColor(){
|
||||
if(Config.has("color")){
|
||||
JSONObject color = Config.getJSONObject("color");
|
||||
if(config.has("color")){
|
||||
JSONObject color = config.getJSONObject("color");
|
||||
return Color.ofRGB(
|
||||
color.getInt("r"),
|
||||
color.getInt("g"),
|
||||
@@ -160,78 +157,70 @@ public class Config {
|
||||
}
|
||||
|
||||
public static boolean isDebug() {
|
||||
if(Config.has("debug")){
|
||||
return Config.getBoolean("debug");
|
||||
if(config.has("debug")){
|
||||
return config.getBoolean("debug");
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean getVisualSpeedometer(){
|
||||
if(Config.has("visualSpeedometer")){
|
||||
return Config.getBoolean("visualSpeedometer");
|
||||
if(config.has("visualSpeedometer")){
|
||||
return config.getBoolean("visualSpeedometer");
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*public static String getXPositionVisual(){
|
||||
if(Config.has("xPositionVisual")) {
|
||||
return Config.getString("xPositionVisual");
|
||||
}else{
|
||||
return "W-23";
|
||||
}
|
||||
public static int getCounter(){
|
||||
return counter;
|
||||
}
|
||||
|
||||
public static String getYPositionVisual() {
|
||||
if (Config.has("yPositionVisual")) {
|
||||
return Config.getString("yPositionVisual");
|
||||
} else {
|
||||
return "H-23";
|
||||
}
|
||||
public static void addCounter(){
|
||||
counter++;
|
||||
}
|
||||
public static String getXPositionText(){
|
||||
if(Config.has("xPositionText")) {
|
||||
return Config.getString("xPositionText");
|
||||
}else{
|
||||
return "W-70";
|
||||
}
|
||||
}
|
||||
|
||||
public static String getYPositionText(){
|
||||
if(Config.has("yPositionText")) {
|
||||
return Config.getString("yPositionText");
|
||||
}else{
|
||||
return "H-15";
|
||||
}
|
||||
}*/
|
||||
|
||||
public static String getYPosition(){
|
||||
if(Config.has("yPosition")) {
|
||||
return Config.getString("yPosition");
|
||||
if(config.has("yPosition")) {
|
||||
return config.getString("yPosition");
|
||||
}else{
|
||||
return "H-15";
|
||||
return "H-3";
|
||||
}
|
||||
}
|
||||
|
||||
public static String getXPosition(){
|
||||
if(Config.has("xPosition")) {
|
||||
return Config.getString("xPosition");
|
||||
if(config.has("xPosition")) {
|
||||
return config.getString("xPosition");
|
||||
}else{
|
||||
return "W-70";
|
||||
return "W-3";
|
||||
}
|
||||
}
|
||||
|
||||
public static int getImageSize(){
|
||||
if(Config.has("imageSize")){
|
||||
return Config.getInt("imageSize");
|
||||
if(config.has("imageSize")){
|
||||
return config.getInt("imageSize");
|
||||
}else {
|
||||
return 19;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean getShowVisualSpeedType() {
|
||||
if(config.has("showVisualSpeedType")){
|
||||
return config.getBoolean("showVisualSpeedType");
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean getShowSpeedType(){
|
||||
if(config.has("getShowSpeedType")){
|
||||
return config.getBoolean("showSpeedType");
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setColor(Color color){
|
||||
Config.put("color", new JSONObject()
|
||||
config.put("color", new JSONObject()
|
||||
.put("r", color.getRed())
|
||||
.put("g", color.getGreen())
|
||||
.put("b", color.getBlue())
|
||||
@@ -239,47 +228,38 @@ public class Config {
|
||||
}
|
||||
|
||||
public static void setUseKnot(boolean useKnot){
|
||||
Config.put("useKnot", useKnot);
|
||||
config.put("useKnot", useKnot);
|
||||
}
|
||||
|
||||
public static void setSpeedType(SpeedTypes speedType) {
|
||||
Config.put("speed", speedType);
|
||||
config.put("speed", speedType);
|
||||
}
|
||||
|
||||
public static void setVisualSpeedometer(boolean visualSpeedometer){
|
||||
Config.put("visualSpeedometer", visualSpeedometer);
|
||||
config.put("visualSpeedometer", visualSpeedometer);
|
||||
}
|
||||
|
||||
/*
|
||||
public static void setXPositionVisual(String xPositionVisual){
|
||||
Config.put("xPositionVisual", xPositionVisual);
|
||||
}
|
||||
|
||||
public static void setYPositionVisual(String yPositionVisual){
|
||||
Config.put("yPositionVisual", yPositionVisual);
|
||||
}
|
||||
|
||||
public static void setXPositionText(String xPositionText){
|
||||
Config.put("xPositionText", xPositionText);
|
||||
}
|
||||
|
||||
public static void setYPositionText(String yPositionText){
|
||||
Config.put("yPositionText", yPositionText);
|
||||
}*/
|
||||
|
||||
public static void setXPosition(String xPosition){
|
||||
Config.put("xPosition", xPosition);
|
||||
config.put("xPosition", xPosition);
|
||||
}
|
||||
|
||||
public static void setYPosition(String yPosition){
|
||||
Config.put("yPosition", yPosition);
|
||||
config.put("yPosition", yPosition);
|
||||
}
|
||||
|
||||
public static void setDebug(boolean debug){
|
||||
Config.put("debug", debug);
|
||||
config.put("debug", debug);
|
||||
}
|
||||
|
||||
public static void setImageSize(int imageSize){
|
||||
Config.put("imageSize", imageSize);
|
||||
config.put("imageSize", imageSize);
|
||||
}
|
||||
|
||||
public static void setShowVisualSpeedType(boolean showVisualSpeedType){
|
||||
config.put("showVisualSpeedType", showVisualSpeedType);
|
||||
}
|
||||
|
||||
public static void setShowSpeedType(boolean showSpeedType){
|
||||
config.put("showSpeedType", showSpeedType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package me.zacharias.speedometer;
|
||||
import me.shedaniel.clothconfig2.api.ConfigBuilder;
|
||||
import me.shedaniel.clothconfig2.api.ConfigCategory;
|
||||
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
@@ -46,79 +47,6 @@ public class ConfigMenu {
|
||||
String xRegex = "W*w*S*s*\\+*-*\\**/*[0-9]*";
|
||||
String yRegex = "H*h*S*s*\\+*-*\\**/*[0-9]*";
|
||||
|
||||
// Text Placement
|
||||
/*
|
||||
category.addEntry(entryBuilder.startStringDropdownMenu(Component.translatable("speedometer.config.xPosition.text"), Config.getXPositionText())
|
||||
.setSaveConsumer(Config::setXPositionText)
|
||||
.setErrorSupplier(xPosition -> {
|
||||
if(xPosition.matches(xRegex)){
|
||||
return Optional.empty();
|
||||
}else{
|
||||
return Optional.of(Component.translatable("speedometer.invalid"));
|
||||
}
|
||||
})
|
||||
.setTooltip(
|
||||
Component.translatable("speedometer.config.tooltip.xPosition.line1"),
|
||||
Component.translatable("speedometer.config.tooltip.xPosition.line2"),
|
||||
Component.translatable("speedometer.config.tooltip.xPosition.line3")
|
||||
)
|
||||
.build()
|
||||
);
|
||||
|
||||
category.addEntry(entryBuilder.startStringDropdownMenu(Component.translatable("speedometer.config.yPosition.text"), Config.getYPositionText())
|
||||
.setSaveConsumer(Config::setYPositionText)
|
||||
.setErrorSupplier(yPosition -> {
|
||||
if(yPosition.matches(yRegex)){
|
||||
return Optional.empty();
|
||||
}else{
|
||||
return Optional.of(Component.translatable("speedometer.invalid"));
|
||||
}
|
||||
})
|
||||
.setTooltip(
|
||||
Component.translatable("speedometer.config.tooltip.yPosition.line1"),
|
||||
Component.translatable("speedometer.config.tooltip.yPosition.line2"),
|
||||
Component.translatable("speedometer.config.tooltip.yPosition.line3")
|
||||
)
|
||||
.build()
|
||||
);
|
||||
|
||||
// Visual location
|
||||
|
||||
category.addEntry(entryBuilder.startStringDropdownMenu(Component.translatable("speedometer.config.xPosition.visual"), Config.getXPositionVisual())
|
||||
.setSaveConsumer(Config::setXPositionVisual)
|
||||
.setErrorSupplier(xPosition -> {
|
||||
if(xPosition.matches(xRegex)){
|
||||
return Optional.empty();
|
||||
}else{
|
||||
return Optional.of(Component.translatable("speedometer.invalid"));
|
||||
}
|
||||
})
|
||||
.setTooltip(
|
||||
Component.translatable("speedometer.config.tooltip.xPosition.line1"),
|
||||
Component.translatable("speedometer.config.tooltip.xPosition.line2"),
|
||||
Component.translatable("speedometer.config.tooltip.xPosition.line3")
|
||||
)
|
||||
.build()
|
||||
);
|
||||
|
||||
|
||||
category.addEntry(entryBuilder.startStringDropdownMenu(Component.translatable("speedometer.config.yPosition.visual"), Config.getYPositionVisual())
|
||||
.setSaveConsumer(Config::setYPositionVisual)
|
||||
.setErrorSupplier(yPosition -> {
|
||||
if(yPosition.matches(yRegex)){
|
||||
return Optional.empty();
|
||||
}else{
|
||||
return Optional.of(Component.translatable("speedometer.invalid"));
|
||||
}
|
||||
})
|
||||
.setTooltip(
|
||||
Component.translatable("speedometer.config.tooltip.yPosition.line1"),
|
||||
Component.translatable("speedometer.config.tooltip.yPosition.line2"),
|
||||
Component.translatable("speedometer.config.tooltip.yPosition.line3")
|
||||
)
|
||||
.build()
|
||||
);*/
|
||||
|
||||
category.addEntry(entryBuilder.startStringDropdownMenu(Component.translatable("speedometer.config.xPosition"), Config.getXPosition())
|
||||
.setSaveConsumer(Config::setXPosition)
|
||||
.setErrorSupplier(xPosition -> {
|
||||
@@ -160,6 +88,25 @@ public class ConfigMenu {
|
||||
.build()
|
||||
);
|
||||
|
||||
// Show visual speed type
|
||||
|
||||
category.addEntry(entryBuilder.startBooleanToggle(Component.translatable("speedometer.config.showSpeedType"), Config.getShowSpeedType())
|
||||
.setSaveConsumer(Config::setShowSpeedType)
|
||||
.setYesNoTextSupplier(showSpeedType -> Component.translatable("speedometer."+(showSpeedType?"show":"hide")))
|
||||
.setTooltip(Component.translatable("speedometer.config.tooltip.showSpeedType.line1"))
|
||||
.build()
|
||||
);
|
||||
|
||||
category.addEntry(entryBuilder.startBooleanToggle(Component.translatable("speedometer.config.showVisualSpeedType"), Config.getShowVisualSpeedType())
|
||||
.setSaveConsumer(Config::setShowVisualSpeedType)
|
||||
.setYesNoTextSupplier(showVisualSpeedType -> Component.translatable("speedometer."+(showVisualSpeedType?"show":"hide")).withStyle(ChatFormatting.DARK_RED))
|
||||
.setTooltip(Component.translatable("speedometer.config.tooltip.showVisualSpeedType.line1"),
|
||||
Component.translatable("speedometer.config.tooltip.showVisualSpeedType.line2"))
|
||||
.build()
|
||||
);
|
||||
|
||||
|
||||
|
||||
category.addEntry(entryBuilder.startBooleanToggle(Component.translatable("speedometer.config.debug"),Config.isDebug())
|
||||
.setSaveConsumer(Config::setDebug)
|
||||
.setYesNoTextSupplier(isDebug -> Component.translatable("speedometer.debug."+isDebug))
|
||||
|
||||
@@ -11,4 +11,16 @@ public class ImageHandler {
|
||||
g2d.drawImage(img1,0,0,null);
|
||||
return out;
|
||||
}
|
||||
|
||||
public static BufferedImage clone(BufferedImage image) {
|
||||
BufferedImage out = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g2d = out.createGraphics();
|
||||
for(int x = 0; x < image.getWidth(); x++){
|
||||
for(int y = 0; y < image.getWidth(); y++){
|
||||
g2d.setColor(new Color(image.getRGB(x,y)));
|
||||
g2d.fillRect(x,y,1,1);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
@@ -4,44 +4,49 @@ import net.minecraft.network.chat.Component;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
import static me.zacharias.speedometer.Speedometer.LOGGER;
|
||||
|
||||
public enum MeterImages {
|
||||
LARGE(Component.translatable("speedometer.meter.large"), () -> {
|
||||
try {
|
||||
return ImageIO.read(Objects.requireNonNull(Speedometer.class.getResourceAsStream("/assets/speedometer/meter/meter-115.png")));
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}, 115),
|
||||
SMALL(Component.translatable("speedometer.meter.small"), () -> {
|
||||
try {
|
||||
return ImageIO.read(Objects.requireNonNull(Speedometer.class.getResourceAsStream("/assets/speedometer/meter/meter-19.png")));
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}, 19),
|
||||
MEDIUM(Component.translatable("speedometer.meter.small"), () -> {
|
||||
try {
|
||||
return ImageIO.read(Objects.requireNonNull(Speedometer.class.getResourceAsStream("/assets/speedometer/meter/meter-67.png")));
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}, 67)
|
||||
LARGE(Component.translatable("speedometer.meter.large"), "/assets/speedometer/meter/meter-115.png", 115),
|
||||
SMALL(Component.translatable("speedometer.meter.small"), "/assets/speedometer/meter/meter-19.png", 19),
|
||||
MEDIUM(Component.translatable("speedometer.meter.small"), "/assets/speedometer/meter/meter-67.png", 67)
|
||||
|
||||
;
|
||||
|
||||
private final Component name;
|
||||
private final BufferedImage image;
|
||||
private final String meterIcon;
|
||||
private BufferedImage image;
|
||||
private final int size;
|
||||
|
||||
MeterImages(Component name, Loader icon, int size) {
|
||||
MeterImages(Component name, String meterIcon, int size) {
|
||||
this.name = name;
|
||||
this.image = icon.load();
|
||||
this.size = size;
|
||||
this.meterIcon = meterIcon;
|
||||
}
|
||||
|
||||
public boolean initiate(){
|
||||
if(image != null){
|
||||
LOGGER.warn("Already loaded \""+meterIcon+"\"");
|
||||
}
|
||||
try{
|
||||
LOGGER.info("Loading speedometer \""+meterIcon+"\"");
|
||||
image = ImageIO.read(Objects.requireNonNull(Speedometer.class.getResourceAsStream(meterIcon)));
|
||||
LOGGER.info("Loaded speedometer \""+meterIcon+"\"");
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
image = new BufferedImage(0,0, BufferedImage.TYPE_INT_ARGB);
|
||||
LOGGER.warn("Failed to load speedometer \""+meterIcon+"\"");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public BufferedImage getImage() {
|
||||
if(image == null){
|
||||
LOGGER.warn("\""+meterIcon+"\" has not ben loaded yet!");
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
@@ -52,8 +57,4 @@ public enum MeterImages {
|
||||
public Component getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
private interface Loader{
|
||||
BufferedImage load();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class Speedometer
|
||||
|
||||
|
||||
if(Platform.getEnvironment() != Env.CLIENT) {
|
||||
LOGGER.error("You're running speedometer on somthing other then a client, this is not supported");
|
||||
LOGGER.error("You're running speedometer on something other then a client, this is not supported");
|
||||
try {
|
||||
for (File f : Objects.requireNonNull(Platform.getModsFolder().toFile().listFiles())) {
|
||||
if (f.getName().startsWith("speedometer")) {
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
"speedometer.config.yPosition": "Y Position for Meters",
|
||||
"speedometer.config.debug": "Debug",
|
||||
"speedometer.config.imageSize": "Image Size",
|
||||
"speedometer.config.showVisualSpeedType": "\u00A74⨻\u00A7rShow Visual Speed Type",
|
||||
"speedometer.config.showSpeedType": "Show Visual Speed Type",
|
||||
|
||||
"speedometer.key.configKey": "Config Key",
|
||||
"speedometer.key.debugKey": "Debug Key",
|
||||
@@ -38,6 +40,9 @@
|
||||
"speedometer.debug.true": "\u00A74Yes",
|
||||
"speedometer.debug.false": "\u00A74No",
|
||||
|
||||
"speedometer.show": "Show",
|
||||
"speedometer.hide": "Hide",
|
||||
|
||||
"speedometer.config.tooltip.xPosition.line1": "W = the width of the screen",
|
||||
"speedometer.config.tooltip.xPosition.line2": "w = half the width of the screen",
|
||||
"speedometer.config.tooltip.xPosition.line3": "s = the width of the text or image",
|
||||
@@ -50,5 +55,10 @@
|
||||
|
||||
"speedometer.config.tooltip.imageSize": "Size of the image. This sets both the height and width",
|
||||
|
||||
"speedometer.config.tooltip.showVisualSpeedType.line1": "This setting doesn't work fully.",
|
||||
"speedometer.config.tooltip.showVisualSpeedType.line2": "I(the developer) discourages the use of this setting since it doesn't work on smaller sises and the fps breaks at larger",
|
||||
|
||||
"speedometer.config.tooltip.showSpeedType.line1": "This setting shows the speed type above the visual meter which is better then within the visual meter",
|
||||
|
||||
"speedometer.invalid": "Invalid String"
|
||||
}
|
||||
@@ -6,7 +6,9 @@
|
||||
"3.0": "Added size setting for visual speedometer, changed how the visual speedometer location is set",
|
||||
"3.1": "Fixed error in language file",
|
||||
"3.2": "Correct checker for Client or Server environment, updated dependencies, added dependency check in mod data file, added a renamer to rename the mod file if it's on a server",
|
||||
"4.0": "Removed the Size part of the position string, combined the visual and text location strings, updated config version to 3, fixed bug where the text would start to drift of screen if you where too fast"
|
||||
"4.0": "Removed the Size part of the position string, combined the visual and text location strings, updated config version to 3, fixed bug where the text would start to drift of screen if you where too fast",
|
||||
"5.0": "Visual speed display has been added",
|
||||
"5.1": "Added second speed display"
|
||||
},
|
||||
"1.20": {
|
||||
"1.0": "First version",
|
||||
@@ -14,13 +16,15 @@
|
||||
"3.0": "Added size setting for visual speedometer, changed how the visual speedometer location is set",
|
||||
"3.1": "Fixed error in language file",
|
||||
"3.2": "Correct checker for Client or Server environment, updated dependencies, added dependency check in mod data file, added a renamer to rename the mod file if it's on a server",
|
||||
"4.0": "Removed the Size part of the position string, combined the visual and text location strings, updated config version to 3, fixed bug where the text would start to drift of screen if you where too fast"
|
||||
"4.0": "Removed the Size part of the position string, combined the visual and text location strings, updated config version to 3, fixed bug where the text would start to drift of screen if you where too fast",
|
||||
"5.0": "Visual speed display has been added",
|
||||
"5.1": "Added second speed display"
|
||||
},
|
||||
"promos": {
|
||||
"1.20.1-latest": "4.0",
|
||||
"1.20.1-recommended": "4.0",
|
||||
"1.20.1-latest": "5.1",
|
||||
"1.20.1-recommended": "5.1",
|
||||
|
||||
"1.20-latest": "4.0",
|
||||
"1.20-recommended": "4.0"
|
||||
"1.20-latest": "5.1",
|
||||
"1.20-recommended": "5.1"
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx8G
|
||||
minecraft_version=1.20.1
|
||||
|
||||
archives_base_name=speedometer
|
||||
mod_version=4
|
||||
mod_version=5.1
|
||||
maven_group=me.zacharias
|
||||
|
||||
architectury_version=9.1.10
|
||||
|
||||
17
readme.md
17
readme.md
@@ -1,7 +1,22 @@
|
||||
# Speedometer
|
||||
This is a simple mod for forge and fabric that displays your current speed
|
||||
|
||||
This mod is a newer version of [speedometer-forge](https://github.com/zaze06/speedometer-forge)
|
||||
## Credits to
|
||||
[org.json](https://www.json.org/json-en.html) *Included due to problems whit ForgeGradle*
|
||||
|
||||
## Compile your own version?
|
||||
1. Download source code
|
||||
* Run `git clone https://github.com/zaze06/Speedometer`
|
||||
* Download the source code from GitHub page [master.zip](https://github.com/zaze06/Speedometer/archive/refs/heads/master.zip)
|
||||
* unzip the folder
|
||||
2. Open the folder
|
||||
3. Run `gradlew build`(Windows cmd) or `./gradlew build`(Linux, MacOS, Windows powershell)
|
||||
4. the compiled version will be in
|
||||
* Fabic: `fabric/build/libs`
|
||||
* Forge: `forge/build/libs`
|
||||
|
||||
|
||||
# This mod is a newer version of [speedometer-forge](https://github.com/zaze06/speedometer-forge)
|
||||
|
||||
## Changes from old forge version?
|
||||
This was just a project I choose for trying the Architectury API for abstraction.
|
||||
|
||||
Reference in New Issue
Block a user