Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cda526d41d | |||
|
|
1321bb3cca | ||
| 47e475cecb |
@@ -67,14 +67,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;
|
||||
}
|
||||
|
||||
@@ -143,26 +137,25 @@ public class Client {
|
||||
|
||||
//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);
|
||||
}
|
||||
|
||||
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,8 +163,8 @@ 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);
|
||||
int xPos = getPos(graphics, Config.getXPosition(), 0);
|
||||
int yPos = getPos(graphics, Config.getYPosition(), 1);
|
||||
|
||||
for(int x1 = 0; x1 < img.getWidth(); x1++){
|
||||
for(int y1 = 0; y1 < img.getHeight(); y1++){
|
||||
@@ -207,8 +200,8 @@ public class Client {
|
||||
graphics.drawString(
|
||||
Minecraft.getInstance().font,
|
||||
speedString,
|
||||
getPos(graphics, Config.getXPosition(), 0, false) - width,
|
||||
getPos(graphics, Config.getYPosition(), 1, true) - lineHeight,
|
||||
getPos(graphics, Config.getXPosition(), 0) - width,
|
||||
getPos(graphics, Config.getYPosition(), 1) - lineHeight,
|
||||
Config.getColor().getColor()
|
||||
);
|
||||
}
|
||||
@@ -231,7 +224,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 +247,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 +266,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 +282,7 @@ public class Client {
|
||||
defaultValues(event, type, passerPose);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
|
||||
int xPos;
|
||||
try{
|
||||
@@ -320,11 +312,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 +326,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import static me.zacharias.speedometer.Speedometer.MOD_ID;
|
||||
public class 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");
|
||||
@@ -108,6 +109,10 @@ public class Config {
|
||||
if(!Config.has("version")) {
|
||||
Config.put("version", configVersion);
|
||||
}
|
||||
|
||||
if(!Config.has("showVisualSpeedType")){
|
||||
Config.put("showVisualSpeedType", false);
|
||||
}
|
||||
}
|
||||
|
||||
public static void save(){
|
||||
@@ -128,6 +133,7 @@ public class Config {
|
||||
}catch (Exception e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
counter=0;
|
||||
}
|
||||
|
||||
public static SpeedTypes getSpeedType(){
|
||||
@@ -175,6 +181,13 @@ public class Config {
|
||||
}
|
||||
}
|
||||
|
||||
public static int getCounter(){
|
||||
return counter;
|
||||
}
|
||||
public static void addCounter(){
|
||||
counter++;
|
||||
}
|
||||
|
||||
/*public static String getXPositionVisual(){
|
||||
if(Config.has("xPositionVisual")) {
|
||||
return Config.getString("xPositionVisual");
|
||||
@@ -210,7 +223,7 @@ public class Config {
|
||||
if(Config.has("yPosition")) {
|
||||
return Config.getString("yPosition");
|
||||
}else{
|
||||
return "H-15";
|
||||
return "H-3";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +231,7 @@ public class Config {
|
||||
if(Config.has("xPosition")) {
|
||||
return Config.getString("xPosition");
|
||||
}else{
|
||||
return "W-70";
|
||||
return "W-3";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,6 +243,14 @@ public class Config {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean getShowVisualSpeedType() {
|
||||
if(Config.has("showVisualSpeedType")){
|
||||
return Config.getBoolean("showVisualSpeedType");
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setColor(Color color){
|
||||
Config.put("color", new JSONObject()
|
||||
.put("r", color.getRed())
|
||||
@@ -282,4 +303,8 @@ public class Config {
|
||||
public static void setImageSize(int imageSize){
|
||||
Config.put("imageSize", imageSize);
|
||||
}
|
||||
|
||||
public static void setShowVisualSpeedType(boolean showVisualSpeedType){
|
||||
Config.put("showVisualSpeedType", showVisualSpeedType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,6 +167,16 @@ public class ConfigMenu {
|
||||
.build()
|
||||
);
|
||||
|
||||
// Show visual speed type
|
||||
|
||||
category.addEntry(entryBuilder.startBooleanToggle(Component.translatable("speedometer.config.showVisualSpeedType"), Config.getShowVisualSpeedType())
|
||||
.setSaveConsumer(Config::setShowVisualSpeedType)
|
||||
.setYesNoTextSupplier(showVisualSpeedType -> Component.translatable("speedometer."+(Config.getShowVisualSpeedType()?"show":"hide")))
|
||||
.setTooltip(Component.translatable("speedometer.config.tooltip.showVisualSpeedType.line1"),
|
||||
Component.translatable("speedometer.config.tooltip.showVisualSpeedType.line2"))
|
||||
.build()
|
||||
);
|
||||
|
||||
builder.setSavingRunnable(me.zacharias.speedometer.Config::save);
|
||||
|
||||
return builder;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
"speedometer.config.yPosition": "Y Position for Meters",
|
||||
"speedometer.config.debug": "Debug",
|
||||
"speedometer.config.imageSize": "Image Size",
|
||||
"speedometer.config.showVisualSpeedType": "Show Visual Speed Type",
|
||||
|
||||
"speedometer.key.configKey": "Config Key",
|
||||
"speedometer.key.debugKey": "Debug Key",
|
||||
@@ -38,6 +39,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 +54,8 @@
|
||||
|
||||
"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.invalid": "Invalid String"
|
||||
}
|
||||
@@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx8G
|
||||
minecraft_version=1.20.1
|
||||
|
||||
archives_base_name=speedometer
|
||||
mod_version=4
|
||||
mod_version=5
|
||||
maven_group=me.zacharias
|
||||
|
||||
architectury_version=9.1.10
|
||||
|
||||
16
readme.md
16
readme.md
@@ -1,8 +1,20 @@
|
||||
# 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)
|
||||
## 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.
|
||||
So changes are that now Architectury APi is required for this mod to work
|
||||
So changes are that now Architectury APi is required for this mod to work
|
||||
|
||||
Reference in New Issue
Block a user