fabric.mod.json:
neoforge.mods.toml: > Updated minumum version of mods and load order *.java: > cleaned up some code Updated to version 6.2.2 Fixed bug in Client.java for the position parser
This commit is contained in:
@@ -37,7 +37,7 @@ public class Client {
|
||||
);
|
||||
|
||||
private static final ArrayList<Double> speeds = new ArrayList<>();
|
||||
private static boolean speedometerVisualDisplayFailed = false;
|
||||
|
||||
|
||||
public static void init(){
|
||||
|
||||
@@ -59,7 +59,7 @@ public class Client {
|
||||
}
|
||||
else if(Minecraft.getInstance().player != null)
|
||||
{
|
||||
Minecraft.getInstance().player.sendSystemMessage(
|
||||
Minecraft.getInstance().player.displayClientMessage(
|
||||
Component
|
||||
.translatable("speedometer.error.missing_cloth")
|
||||
.withColor(new Color(190, 0, 0).getRGB())
|
||||
@@ -68,7 +68,7 @@ public class Client {
|
||||
.literal("Open Config")
|
||||
.withStyle(ChatFormatting.UNDERLINE)
|
||||
.withStyle((style) -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, Config.getConfigPath())))
|
||||
));
|
||||
), false);
|
||||
LOGGER.warn(Component.translatable("speedometer.error.missing_cloth").getString());
|
||||
}
|
||||
else
|
||||
@@ -91,39 +91,6 @@ public class Client {
|
||||
ClientGuiEvent.RENDER_HUD.register(Client::render);
|
||||
|
||||
LOGGER.info("Finished loading speedometer");
|
||||
|
||||
/*((IPackRepository) Minecraft.getInstance().getResourcePackRepository()).addSource(new RepositorySource() {
|
||||
@Override
|
||||
public void loadPacks(Consumer<Pack> consumer) {
|
||||
consumer.accept(new Pack(new PackLocationInfo(
|
||||
"quarter_circle_speedometer",
|
||||
Component.translatable("resourcepack.speedometer.quarter_circle_speedometer"),
|
||||
new PackSource() {
|
||||
@Override
|
||||
public Component decorate(Component component) {
|
||||
return component;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldAddAutomatically() {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
Optional.empty()
|
||||
),
|
||||
new Pack.ResourcesSupplier() {
|
||||
@Override
|
||||
public PackResources openPrimary(PackLocationInfo packLocationInfo) {
|
||||
return packLocationInfo.;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackResources openFull(PackLocationInfo packLocationInfo, Pack.Metadata metadata) {
|
||||
return null;
|
||||
}
|
||||
}));
|
||||
}
|
||||
});*/
|
||||
}
|
||||
|
||||
private static void render(GuiGraphics graphics, DeltaTracker deltaTracker) {
|
||||
@@ -189,42 +156,6 @@ public class Client {
|
||||
|
||||
BufferedImage img = ImageHandler.scale(ICON.getSpeedometerIcon(speedTypeSpeed), Config.getImageSize(), Config.getImageSize());
|
||||
|
||||
/*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);
|
||||
|
||||
Graphics2D g2d = img.createGraphics();
|
||||
|
||||
g2d.setColor(new Color(138, 0, 0));
|
||||
|
||||
g2d.setStroke(new BasicStroke(2));
|
||||
|
||||
g2d.drawLine(x3,y3,img.getWidth()/2,img.getHeight()/2);
|
||||
|
||||
for(int x1 = 0; x1 < img.getWidth(); x1++){
|
||||
for(int y1 = 0; y1 < img.getHeight(); y1++){
|
||||
int x2 = x1 + xPos - img.getWidth();
|
||||
int y2 = y1 + yPos - img.getHeight();
|
||||
|
||||
int rgb = img.getRGB(x1, y1);
|
||||
|
||||
if(new Color(rgb).equals(Color.black)) continue;
|
||||
|
||||
graphics.fill(x2, y2, x2+1, y2+1, rgb);
|
||||
}
|
||||
}
|
||||
|
||||
if(i >= 360+45){
|
||||
String string = "x" + (int)Math.floor(i/(365+45));
|
||||
graphics.drawString(
|
||||
Minecraft.getInstance().font,
|
||||
string,
|
||||
xPos-Minecraft.getInstance().font.width(string),
|
||||
(int)(yPos-4.5-((double) Config.getImageSize() /2)),
|
||||
new Color(138, 0, 0).getRGB()
|
||||
);
|
||||
}*/
|
||||
for(int x1 = 0; x1 < img.getWidth(); x1++){
|
||||
for(int y1 = 0; y1 < img.getHeight(); y1++){
|
||||
int x2 = x1 + xPos - img.getWidth();
|
||||
@@ -268,8 +199,8 @@ public class Client {
|
||||
" Total: " + lSpeed + "\n" +
|
||||
"Velocity total average: " + speed + "\n" +
|
||||
"Velocity total in " + speedType.name() + ": " + speedTypeSpeed + "\n" +
|
||||
"Endpoint position: (" + Debuger.x + ", " + Debuger.y + ")\n" +
|
||||
"Percentage point of visual speedometer: " + Debuger.angle + "\n" +
|
||||
"Endpoint position: (" + Debugger.x + ", " + Debugger.y + ")\n" +
|
||||
"Percentage point of visual speedometer: " + Debugger.angle + "\n" +
|
||||
(Config.getVisualSpeedometer()?"Visual Size: "+Config.getImageSize():"Textual display");
|
||||
|
||||
Color color = new Color(255, 255, 255);
|
||||
@@ -298,36 +229,35 @@ public class Client {
|
||||
|
||||
try{
|
||||
for(int i = 0; i <s.length; i++){
|
||||
if(s[i] == 'W' || s[i] == 'H'){
|
||||
char c = s[i];
|
||||
if(c == 'W' || c == 'H'){
|
||||
if(isXPosition) passerPose.add(String.valueOf(event.guiWidth()));
|
||||
else passerPose.add(String.valueOf(event.guiHeight()));
|
||||
}else if(s[i] == 'h' || s[i] == 'w'){
|
||||
}
|
||||
else if(c == 'h' || c == 'w'){
|
||||
if(isXPosition) passerPose.add(String.valueOf(event.guiWidth() / 2));
|
||||
else passerPose.add(String.valueOf(event.guiHeight() / 2));
|
||||
}else if(s[i] == 'S' || s[i] == 's'){
|
||||
}
|
||||
else if(c == 'S' || c == 's'){
|
||||
passerPose.add(String.valueOf(width));
|
||||
}else if(s[i] == '+'){
|
||||
passerPose.add("+");
|
||||
}else if(s[i] == '-'){
|
||||
passerPose.add("-");
|
||||
}else if(s[i] == '*'){
|
||||
passerPose.add("/");
|
||||
}else if(s[i] == '/'){
|
||||
passerPose.add("/");
|
||||
}else if(Character.isDigit(s[i])){
|
||||
try{
|
||||
if(i-1 > 0 && passerPose.get(i - 1).matches("^[0-9]+$")) {
|
||||
Integer.parseInt(passerPose.get(i - 1));
|
||||
passerPose.add(i - 1, passerPose.get(i - 1) + s[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
passerPose.add(Character.toString(s[i]));
|
||||
}
|
||||
}catch (NumberFormatException e){
|
||||
passerPose.add(Character.toString(s[i]));
|
||||
}
|
||||
else if(c == '+' ||
|
||||
c == '-' ||
|
||||
c == '*' ||
|
||||
c == '/'){
|
||||
passerPose.add(Character.toString(c));
|
||||
}
|
||||
else if(Character.isDigit(c)){
|
||||
int lastIndex = i - 1;
|
||||
if(lastIndex > 0 && passerPose.get(lastIndex).matches("^[0-9]+$")) {
|
||||
passerPose.add(passerPose.removeLast() + c);
|
||||
}
|
||||
}else{
|
||||
else
|
||||
{
|
||||
passerPose.add(Character.toString(c));
|
||||
}
|
||||
}
|
||||
else{
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
@@ -342,6 +272,7 @@ public class Client {
|
||||
try{
|
||||
position = Integer.parseInt(passerPose.getFirst());
|
||||
}catch (NumberFormatException e){
|
||||
passerPose.clear();
|
||||
defaultValues(event, isXPosition, passerPose);
|
||||
position = Integer.parseInt(passerPose.getFirst());
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package me.zacharias.speedometer;
|
||||
|
||||
import dev.architectury.platform.Platform;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@@ -32,7 +31,7 @@ public class Config {
|
||||
}
|
||||
config = new JSONObject();
|
||||
|
||||
defualt();
|
||||
defaultValues();
|
||||
}else {
|
||||
try {
|
||||
BufferedReader in = new BufferedReader(new FileReader(configFile));
|
||||
@@ -62,7 +61,7 @@ public class Config {
|
||||
}
|
||||
|
||||
config = new JSONObject();
|
||||
defualt();
|
||||
defaultValues();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -72,20 +71,20 @@ public class Config {
|
||||
if(config.getFloat("version")!=configVersion){
|
||||
if(config.getFloat("version") > configVersion){
|
||||
LOGGER.warn("Config version is too new, resting");
|
||||
defualt();
|
||||
defaultValues();
|
||||
|
||||
save();
|
||||
}else if(config.getFloat("version") < configVersion){
|
||||
config = new JSONObject();
|
||||
LOGGER.warn("Config version is outdated, resting");
|
||||
|
||||
defualt();
|
||||
defaultValues();
|
||||
save();
|
||||
}
|
||||
}
|
||||
}else{
|
||||
config = new JSONObject();
|
||||
defualt();
|
||||
defaultValues();
|
||||
save();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@@ -94,7 +93,7 @@ public class Config {
|
||||
}
|
||||
}
|
||||
|
||||
private static void defualt() {
|
||||
private static void defaultValues() {
|
||||
if(!config.has("speed")) {
|
||||
config.put("speed", SpeedTypes.BlockPS);
|
||||
}
|
||||
|
||||
@@ -23,9 +23,7 @@ public class ConfigMenu {
|
||||
);
|
||||
|
||||
category.addEntry(entryBuilder.startColorField(Component.translatable("speedometer.config.color"), me.zacharias.speedometer.Config.getColorRGB())
|
||||
.setSaveConsumer2(color -> {
|
||||
me.zacharias.speedometer.Config.setColor(color.getRed(), color.getGreen(), color.getBlue());
|
||||
})
|
||||
.setSaveConsumer2(color -> Config.setColor(color.getRed(), color.getGreen(), color.getBlue()))
|
||||
.build()
|
||||
);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package me.zacharias.speedometer;
|
||||
|
||||
public class Debuger {
|
||||
public class Debugger {
|
||||
public static double angle;
|
||||
public static double x;
|
||||
public static double y;
|
||||
@@ -3,17 +3,11 @@ package me.zacharias.speedometer;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
public enum SpeedTypes {
|
||||
MPH(20),
|
||||
KMPH(200),
|
||||
MPS(10),
|
||||
BlockPS(10),
|
||||
KNOT(20);
|
||||
|
||||
private final int maxVisual;
|
||||
|
||||
SpeedTypes(int maxVisual){
|
||||
this.maxVisual = maxVisual;
|
||||
}
|
||||
MPH,
|
||||
KMPH,
|
||||
MPS,
|
||||
BlockPS,
|
||||
KNOT;
|
||||
|
||||
public static Component getName(Enum anEnum) {
|
||||
if(anEnum instanceof SpeedTypes speedType) {
|
||||
@@ -28,8 +22,4 @@ public enum SpeedTypes {
|
||||
return Component.translatable("speedometer.speed.error");
|
||||
}
|
||||
}
|
||||
|
||||
public int gatMaxVisual() {
|
||||
return maxVisual;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package me.zacharias.speedometer;
|
||||
import dev.architectury.platform.Platform;
|
||||
import dev.architectury.utils.Env;
|
||||
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.Resource;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
@@ -64,8 +63,7 @@ public class Speedometer
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
BufferedReader stream = resource.get().openAsReader();
|
||||
try(BufferedReader stream = resource.get().openAsReader()) {
|
||||
String tmp;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
while ((tmp = stream.readLine()) != null) {
|
||||
|
||||
@@ -10,14 +10,11 @@ import org.json.JSONObject;
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import static me.zacharias.speedometer.Speedometer.MOD_ID;
|
||||
|
||||
public class SpeedometerIcon {
|
||||
private BufferedImage speedometerIcon;
|
||||
private Pointer pointer;
|
||||
@@ -169,7 +166,7 @@ class Pointer
|
||||
}
|
||||
double angle = ((speed/max) * end)+start;
|
||||
if(angle > end && !overflow) angle = end;
|
||||
Debuger.angle = angle;
|
||||
Debugger.angle = angle;
|
||||
|
||||
if(Objects.nonNull(image))
|
||||
{
|
||||
@@ -183,8 +180,8 @@ class Pointer
|
||||
double angleRads = Math.toRadians(180+angle);
|
||||
int endX = (int) (Math.cos(angleRads) * length + this.start.x);
|
||||
int endY = (int) (Math.sin(angleRads) * length + this.start.y);
|
||||
Debuger.x = endX;
|
||||
Debuger.y = endY;
|
||||
Debugger.x = endX;
|
||||
Debugger.y = endY;
|
||||
|
||||
g2d.setColor(c);
|
||||
g2d.setStroke(new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
|
||||
|
||||
Reference in New Issue
Block a user