2 Commits

Author SHA1 Message Date
Zacharias
1321bb3cca Update readme.md 2023-08-31 11:16:31 +02:00
47e475cecb Alpha version!
Started to add speed type string to the visual speedometer
Chaged some ways of reading or copying data
2023-08-31 11:09:40 +02:00
6 changed files with 112 additions and 80 deletions

View File

@@ -40,6 +40,13 @@ public class Client {
"speedometer.key.category"
);
public static final KeyMapping SPEED_KEY = new KeyMapping(
"speedometer.key.speedKey",
InputConstants.Type.KEYSYM,
InputConstants.KEY_UP,
"speedometer.key.category"
);
private static final ArrayList<Double> speeds = new ArrayList<>();
private static boolean speedometerVisualDisplayFailed = false;
public static BufferedImage img = null;
@@ -62,19 +69,22 @@ public class Client {
}
});
//KeyMappingRegistry.register(SPEED_KEY);
ClientTickEvent.CLIENT_POST.register(minecraft -> {
if(SPEED_KEY.consumeClick()){
if(minecraft.player != null) {
minecraft.player.addDeltaMovement(new Vec3(1, 0, 0));
}
}
});
Config.initialize();
Config.save();
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 +153,22 @@ 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();
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);
g2d.setColor(new Color(138, 0, 0));
g2d.setFont(new Font(g2d.getFont().getName(), Font.PLAIN, 15));
g2d.drawString(SpeedTypes.getName(speedType).getString(), img.getWidth()/2-27,img.getHeight()/2+25);
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 +176,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 +213,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 +237,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 +260,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 +279,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 +295,7 @@ public class Client {
defaultValues(event, type, passerPose);
}
//
int xPos;
try{
@@ -320,11 +325,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 +339,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);
}
}

View File

@@ -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");
@@ -128,6 +129,7 @@ public class Config {
}catch (Exception e){
throw new RuntimeException(e);
}
counter=0;
}
public static SpeedTypes getSpeedType(){
@@ -175,6 +177,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 +219,7 @@ public class Config {
if(Config.has("yPosition")) {
return Config.getString("yPosition");
}else{
return "H-15";
return "H-3";
}
}
@@ -218,7 +227,7 @@ public class Config {
if(Config.has("xPosition")) {
return Config.getString("xPosition");
}else{
return "W-70";
return "W-3";
}
}

View File

@@ -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;
}
}

View File

@@ -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();
}
}

View File

@@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx8G
minecraft_version=1.20.1
archives_base_name=speedometer
mod_version=4
mod_version=5-alpha
maven_group=me.zacharias
architectury_version=9.1.10

View File

@@ -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