Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7dbf65446 | ||
|
|
3e282612a3 | ||
| 1a59e3dc2a | |||
| 1fc71a34a9 | |||
|
|
d1e5ef63ee | ||
|
|
32b6198f71 | ||
|
|
5c95f394a8 | ||
| 38f96cb1e9 | |||
| 95222c1c95 | |||
| f48a4aaf6c | |||
| 1589226f81 | |||
| fefd82f71f | |||
| 3638718f16 | |||
| 9ed808d33d | |||
|
|
614af5b6d6 | ||
| c644671eaf | |||
| b09ffb4639 | |||
| 481993b2e2 |
34
.github/ISSUE_TEMPLATE/bug-report.md
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
---
|
||||
name: Bug Report
|
||||
about: Report a Bug
|
||||
title: "[Bug Report, Please chage]"
|
||||
labels: ''
|
||||
assignees: zaze06
|
||||
|
||||
---
|
||||
|
||||
**What Happend**
|
||||
|
||||
|
||||
**What was Expected**
|
||||
|
||||
|
||||
**Screen Shot(s)**
|
||||
(Only if relevent)
|
||||
|
||||
**Versions**
|
||||
- Minecraft:
|
||||
- Mod Loader:
|
||||
- Speedometer:
|
||||
- Architectury:
|
||||
|
||||
**Mod Loader**
|
||||
- Fabric/Forge/NeoForge
|
||||
|
||||
**Config**
|
||||
*If needed*
|
||||
*Use [GitHub Gist](gist.gihub.com) to upload your speedometer config, located in *
|
||||
|
||||
**Logs**
|
||||
*If needed(Most of the times)*
|
||||
*Upload to [mclo.gs](https://mclo.gs/) or [GitHub Gist](gist.gihub.com)*
|
||||
22
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
Make sure your feature havent ben requested at [Feature Requests](https://github.com/zaze06/Speedometer/issues?q=label%3A%22Feature+Request%22)
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
3
.gitignore
vendored
@@ -114,6 +114,9 @@ gradle-app.setting
|
||||
# Common working directory
|
||||
run/
|
||||
|
||||
neoforge/run/
|
||||
fabric/run/
|
||||
|
||||
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
||||
!gradle-wrapper.jar
|
||||
|
||||
|
||||
6
Resourcepack/quarter_circle_speedometer/ReadMe.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
Hello there!
|
||||
|
||||
If you're reading this I assume you might be interested in making your own!
|
||||
|
||||
You're in luck, I have provided a guide. Over on GitHub on how to do it!
|
||||
Please check out https://github.com/zaze06/Speedometer/blob/master/resourcepack.md for a guide to get started
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"background": "speedometer:meter/speedometer.png",
|
||||
"start": 0,
|
||||
"end": 85,
|
||||
"maxSpeed": 120,
|
||||
"overflow": false,
|
||||
"pointer": {
|
||||
"image": "speedometer:meter/pointer.png",
|
||||
"start": "(115,115)"
|
||||
},
|
||||
"scale": 1,
|
||||
"name": "Quarter circle"
|
||||
}
|
||||
|
After Width: | Height: | Size: 652 B |
|
After Width: | Height: | Size: 1.4 KiB |
10
Resourcepack/quarter_circle_speedometer/pack.mcmeta
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"pack": {
|
||||
"pack_format": 34,
|
||||
"description": "A different speedometer",
|
||||
"supported_formats": {
|
||||
"min_inclusive": 34,
|
||||
"max_inclusive": 57
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
Resourcepack/quarter_circle_speedometer/pack.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
10
build.gradle
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id "architectury-plugin" version "3.4-SNAPSHOT"
|
||||
id "dev.architectury.loom" version "1.1-SNAPSHOT" apply false
|
||||
id "dev.architectury.loom" version "1.7-SNAPSHOT" apply false
|
||||
}
|
||||
|
||||
architectury {
|
||||
@@ -20,6 +20,7 @@ subprojects {
|
||||
mappings loom.officialMojangMappings()
|
||||
// The following line declares the yarn mappings you may select this one as well.
|
||||
// mappings "net.fabricmc:yarn:@YARN_MAPPINGS@:v2"
|
||||
//api("org.json:json:${rootProject.json_version}")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,17 +33,22 @@ allprojects {
|
||||
version = rootProject.mod_version
|
||||
group = rootProject.maven_group
|
||||
|
||||
dependencies {
|
||||
implementation ("net.kyori:adventure-text-minimessage:4.17.0")
|
||||
}
|
||||
|
||||
repositories {
|
||||
// Add repositories to retrieve artifacts from in here.
|
||||
// You should only use this when depending on other mods because
|
||||
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
|
||||
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
|
||||
// for more information about repositories.
|
||||
mavenCentral();
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
options.encoding = "UTF-8"
|
||||
options.release = 17
|
||||
options.release = 21
|
||||
}
|
||||
|
||||
java {
|
||||
|
||||
@@ -5,11 +5,11 @@ dependencies {
|
||||
// Remove the next line if you don't want to depend on the API
|
||||
modApi "dev.architectury:architectury:${rootProject.architectury_version}"
|
||||
|
||||
modApi "me.shedaniel.cloth:cloth-config-fabric:11.0.99"
|
||||
modApi "me.shedaniel.cloth:cloth-config-fabric:${rootProject.cloth_config_version}"
|
||||
}
|
||||
|
||||
architectury {
|
||||
common()
|
||||
common("fabric", "neoforge")
|
||||
}
|
||||
|
||||
publishing {
|
||||
|
||||
@@ -5,24 +5,22 @@ import dev.architectury.event.events.client.ClientGuiEvent;
|
||||
import dev.architectury.event.events.client.ClientTickEvent;
|
||||
import dev.architectury.platform.Platform;
|
||||
import dev.architectury.registry.client.keymappings.KeyMappingRegistry;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.DeltaTracker;
|
||||
import net.minecraft.client.KeyMapping;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.animal.Pig;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.vehicle.Boat;
|
||||
import net.minecraft.world.entity.vehicle.Minecart;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
|
||||
import static me.zacharias.speedometer.Speedometer.LOGGER;
|
||||
import static me.zacharias.speedometer.Speedometer.MOD_ID;
|
||||
import static me.zacharias.speedometer.Speedometer.*;
|
||||
|
||||
public class Client {
|
||||
public static final KeyMapping CONFIG_KEY = new KeyMapping(
|
||||
@@ -39,17 +37,44 @@ public class Client {
|
||||
);
|
||||
|
||||
private static final ArrayList<Double> speeds = new ArrayList<>();
|
||||
private static boolean speedometerVisualDisplayFailed = false;
|
||||
public static BufferedImage img = null;
|
||||
|
||||
|
||||
public static void init(){
|
||||
|
||||
Platform.getMod(MOD_ID).registerConfigurationScreen(parent -> ConfigMenu.getConfig(parent).build());
|
||||
|
||||
|
||||
final boolean isClothLoaded = Platform.isModLoaded("cloth_config") || Platform.isModLoaded("cloth-config");
|
||||
|
||||
if(isClothLoaded) {
|
||||
Platform.getMod(MOD_ID).registerConfigurationScreen(parent -> ConfigMenu.getConfig(parent).build());
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER.warn("Missing Cloth Config API, In game config menu will not be available");
|
||||
}
|
||||
|
||||
KeyMappingRegistry.register(CONFIG_KEY);
|
||||
ClientTickEvent.CLIENT_POST.register(minecraft -> {
|
||||
if(CONFIG_KEY.consumeClick()){
|
||||
Minecraft.getInstance().setScreen(ConfigMenu.getConfig(Minecraft.getInstance().screen).build());
|
||||
if(isClothLoaded) {
|
||||
Minecraft.getInstance().setScreen(ConfigMenu.getConfig(Minecraft.getInstance().screen).build());
|
||||
}
|
||||
else if(Minecraft.getInstance().player != null)
|
||||
{
|
||||
Minecraft.getInstance().player.displayClientMessage(
|
||||
Component
|
||||
.translatable("speedometer.error.missing_cloth")
|
||||
.withColor(new Color(190, 0, 0).getRGB())
|
||||
.append(" ")
|
||||
.append(Component
|
||||
.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
|
||||
{
|
||||
LOGGER.warn(Component.translatable("speedometer.error.missing_cloth").getString());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -65,40 +90,30 @@ public class Client {
|
||||
|
||||
ClientGuiEvent.RENDER_HUD.register(Client::render);
|
||||
|
||||
LOGGER.info("Loading speedometer ");
|
||||
if(!MeterImages.LARGE.initiate()){
|
||||
speedometerVisualDisplayFailed = true;
|
||||
}
|
||||
|
||||
LOGGER.info("Finished loading speedometer");
|
||||
}
|
||||
|
||||
private static void render(GuiGraphics graphics, float tick) {
|
||||
private static void render(GuiGraphics graphics, DeltaTracker deltaTracker) {
|
||||
if(Minecraft.getInstance().player == null) return;
|
||||
if(Minecraft.getInstance().options.hideGui) return;
|
||||
Entity entity = Minecraft.getInstance().player.getRootVehicle();
|
||||
|
||||
Vec3 vec = entity.getDeltaMovement();
|
||||
Vec3 vec = new Vec3(
|
||||
entity.getX() - entity.xOld,
|
||||
entity.getY() - entity.yOld,
|
||||
entity.getZ() - entity.zOld
|
||||
);
|
||||
|
||||
double yOffset = 0.0784000015258789D;
|
||||
double yOffset = 0D;
|
||||
double xOffset = 0D;
|
||||
double zOffset = 0D;
|
||||
double vOffset = 0D;
|
||||
|
||||
if (entity instanceof Player e) {
|
||||
if (!e.onGround() && e.isCreative()) {
|
||||
yOffset = 0;
|
||||
} else if (e.isInWater()) {
|
||||
yOffset = 0.005;
|
||||
}
|
||||
} else if (entity instanceof Boat || entity instanceof Minecart || entity instanceof Pig) {
|
||||
yOffset = 0;
|
||||
}
|
||||
|
||||
double speed = (Math.sqrt(Math.pow(vec.x + xOffset, 2) + Math.pow(vec.y + yOffset, 2) + Math.pow(vec.z + zOffset, 2)) * 20)+vOffset;
|
||||
double lSpeed = speed;
|
||||
|
||||
if (speeds.size() >= 30) {
|
||||
speeds.remove(0);
|
||||
speeds.removeFirst();
|
||||
}
|
||||
speeds.add(speed);
|
||||
speed = 0;
|
||||
@@ -121,92 +136,49 @@ public class Client {
|
||||
}
|
||||
|
||||
String format = String.format("%.2f", speedTypeSpeed);
|
||||
|
||||
String speedString = format + " " + SpeedTypes.getName(speedType).getString();
|
||||
|
||||
int width = switch ((Config.getVisualSpeedometer() && !Config.isDisableVisualSpeedometer()) ? 1 : 0){
|
||||
case 1 -> Config.getImageSize();
|
||||
case 0 -> Minecraft.getInstance().font.width(speedString);
|
||||
default -> 0;
|
||||
};
|
||||
|
||||
//double v = (Math.pow(1.0233435, speedTypeSpeed)-1)/100;
|
||||
double v = switch (speedType){
|
||||
case KMPH -> Math.pow(speedTypeSpeed,0.87)-1;
|
||||
case BlockPS, MPS -> Math.pow(speedTypeSpeed,1.25);
|
||||
case MPH -> speedTypeSpeed;
|
||||
case KNOT -> Math.pow(speedTypeSpeed,1.05);
|
||||
}/100;
|
||||
double i = (v *(316-45))+45;
|
||||
|
||||
int yPos = getPos(graphics, Config.getYPosition(), 1);
|
||||
int xPos = getPos(graphics, Config.getXPosition(), 0);
|
||||
int yPos = getPos(graphics, width, Config.getYPosition(), false);
|
||||
int xPos = getPos(graphics, width, Config.getXPosition(), true);
|
||||
|
||||
int lineHeight = Minecraft.getInstance().font.lineHeight;
|
||||
|
||||
if(Config.getVisualSpeedometer() && !speedometerVisualDisplayFailed){
|
||||
if(Config.getVisualSpeedometer() && !Config.isDisableVisualSpeedometer()){
|
||||
|
||||
//double v = speedTypeSpeed / speedType.gatMaxVisual();
|
||||
|
||||
img = ImageHandler.clone(MeterImages.LARGE.getImage());
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
BufferedImage img = ImageHandler.scale(Client.img, 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);
|
||||
|
||||
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);
|
||||
BufferedImage img = ImageHandler.scale(ICON.getSpeedometerIcon(speedTypeSpeed), Config.getImageSize(), Config.getImageSize());
|
||||
|
||||
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-(Config.getImageSize()/2)),
|
||||
new Color(138, 0, 0).getRGB()
|
||||
);
|
||||
}
|
||||
|
||||
}else {
|
||||
// i -> x
|
||||
// j -> y
|
||||
// k -> color RGB int
|
||||
String speedString = format + " " + SpeedTypes.getName(speedType).getString();
|
||||
int width = Minecraft.getInstance().font.width(speedString);
|
||||
graphics.drawString(
|
||||
Minecraft.getInstance().font,
|
||||
speedString,
|
||||
xPos - width,
|
||||
yPos - lineHeight,
|
||||
Config.getColor().getColor()
|
||||
Config.getColor().getRGB()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -227,9 +199,9 @@ public class Client {
|
||||
" Total: " + lSpeed + "\n" +
|
||||
"Velocity total average: " + speed + "\n" +
|
||||
"Velocity total in " + speedType.name() + ": " + speedTypeSpeed + "\n" +
|
||||
"Percentage point of visual speedometer: " + v + "\n" +
|
||||
"Degree end point: " + (i+45) +"\n" +
|
||||
(Config.getVisualSpeedometer()?"Visual Size: ":"Textual display") + Config.getImageSize();
|
||||
"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);
|
||||
|
||||
@@ -251,49 +223,58 @@ public class Client {
|
||||
);
|
||||
}
|
||||
|
||||
private static int getPos(GuiGraphics event, String input, int type) {
|
||||
private static int getPos(GuiGraphics event, int width, String input, boolean isXPosition) {
|
||||
ArrayList<String> passerPose = new ArrayList<>();
|
||||
final char[] s = input.toCharArray();
|
||||
|
||||
try{
|
||||
for(int i = 0; i <s.length; i++){
|
||||
if(s[i] == 'W' || s[i] == 'H'){
|
||||
if(type == 0) passerPose.add(String.valueOf(event.guiWidth()));
|
||||
else if(type == 1) passerPose.add(String.valueOf(event.guiHeight()));
|
||||
}else if(s[i] == 'h' || s[i] == 'w'){
|
||||
if(type == 0) passerPose.add(String.valueOf(event.guiWidth() / 2));
|
||||
else if(type == 1) passerPose.add(String.valueOf(event.guiHeight() / 2));
|
||||
}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{
|
||||
Integer.parseInt(passerPose.get(i-1));
|
||||
passerPose.add(i-1,passerPose.get(i-1)+s[i]);
|
||||
}catch (NumberFormatException e){
|
||||
passerPose.add(Character.toString(s[i]));
|
||||
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(c == 'h' || c == 'w'){
|
||||
if(isXPosition) passerPose.add(String.valueOf(event.guiWidth() / 2));
|
||||
else passerPose.add(String.valueOf(event.guiHeight() / 2));
|
||||
}
|
||||
else if(c == 'S' || c == 's'){
|
||||
passerPose.add(String.valueOf(width));
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
passerPose.clear();
|
||||
defaultValues(event, type, passerPose);
|
||||
defaultValues(event, isXPosition, passerPose);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
int xPos;
|
||||
int position;
|
||||
try{
|
||||
xPos = Integer.parseInt(passerPose.get(0));
|
||||
position = Integer.parseInt(passerPose.getFirst());
|
||||
}catch (NumberFormatException e){
|
||||
defaultValues(event, type, passerPose);
|
||||
xPos = Integer.parseInt(passerPose.get(0));
|
||||
passerPose.clear();
|
||||
defaultValues(event, isXPosition, passerPose);
|
||||
position = Integer.parseInt(passerPose.getFirst());
|
||||
}
|
||||
|
||||
for(int i = 1; i < passerPose.size(); i++){
|
||||
@@ -307,31 +288,34 @@ public class Client {
|
||||
}
|
||||
|
||||
if(Objects.equals(s1, "+") && !first){
|
||||
xPos += Integer.parseInt(s2);
|
||||
position += Integer.parseInt(s2);
|
||||
}else if(Objects.equals(s1, "-") && !first){
|
||||
xPos -= Integer.parseInt(s2);
|
||||
position -= Integer.parseInt(s2);
|
||||
}else if(Objects.equals(s1, "*") && !first){
|
||||
xPos *= Integer.parseInt(s2);
|
||||
position *= Integer.parseInt(s2);
|
||||
}else if(Objects.equals(s1, "/") && !first){
|
||||
xPos /= Integer.parseInt(s2);
|
||||
position /= Integer.parseInt(s2);
|
||||
}
|
||||
}
|
||||
if((Config.isDebug()) && Config.getCounter() < 2) {
|
||||
LOGGER.info("Selected speed type: "+SpeedTypes.getName(Config.getSpeedType()).getString()+"\n"+
|
||||
Arrays.toString(passerPose.toArray())+"\n\n"+
|
||||
xPos+"\n\n"+
|
||||
(type==0?Config.getXPosition():Config.getYPosition()));
|
||||
String speedDisplayType = SpeedTypes.getName(Config.getSpeedType()).getString();
|
||||
String splitRawSpeedPosition = Arrays.toString(passerPose.toArray());
|
||||
String rawSpeedPosition = isXPosition ? Config.getXPosition() : Config.getYPosition();
|
||||
LOGGER.info("Selected speed type: {}\n{}\n\n{}\n\n{}", speedDisplayType, splitRawSpeedPosition, position, rawSpeedPosition);
|
||||
Config.addCounter();
|
||||
}
|
||||
return xPos;
|
||||
return position;
|
||||
}
|
||||
|
||||
private static void defaultValues(GuiGraphics event, int type, ArrayList<String> passerPose) {
|
||||
if(type == 0){
|
||||
private static void defaultValues(GuiGraphics event, boolean isXPosition, ArrayList<String> passerPose) {
|
||||
if(isXPosition)
|
||||
{
|
||||
passerPose.add(String.valueOf(event.guiWidth()));
|
||||
passerPose.add("-");
|
||||
passerPose.add("3");
|
||||
}else if(type == 1){
|
||||
}
|
||||
else
|
||||
{
|
||||
passerPose.add(String.valueOf(event.guiHeight()));
|
||||
passerPose.add("-");
|
||||
passerPose.add("3");
|
||||
|
||||
@@ -1,22 +1,27 @@
|
||||
package me.zacharias.speedometer;
|
||||
|
||||
import dev.architectury.platform.Platform;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
|
||||
import me.shedaniel.math.Color;
|
||||
|
||||
import static me.zacharias.speedometer.Speedometer.MOD_ID;
|
||||
import static me.zacharias.speedometer.Speedometer.*;
|
||||
|
||||
public class Config {
|
||||
private static JSONObject config;
|
||||
public static final float configVersion = 3f;
|
||||
public static final float configVersion = 4f;
|
||||
private static int counter = 0;
|
||||
private static String configPath;
|
||||
private static BufferedImage speedometer;
|
||||
private static boolean disableVisualSpeedometer = false;
|
||||
|
||||
public static void initialize(){
|
||||
if(config != null) throw new RuntimeException("Already Initialized");
|
||||
File configFile = new File(Platform.getConfigFolder().toString()+"/"+MOD_ID+"/config.json");
|
||||
configPath = Platform.getConfigFolder().toString()+"/"+MOD_ID+"/config.json";
|
||||
File configFile = new File(configPath);
|
||||
if(!configFile.exists()){
|
||||
try {
|
||||
configFile.getParentFile().mkdir();
|
||||
@@ -26,7 +31,7 @@ public class Config {
|
||||
}
|
||||
config = new JSONObject();
|
||||
|
||||
defualt();
|
||||
defaultValues();
|
||||
}else {
|
||||
try {
|
||||
BufferedReader in = new BufferedReader(new FileReader(configFile));
|
||||
@@ -35,23 +40,51 @@ public class Config {
|
||||
while((tmp = in.readLine()) != null){
|
||||
builder.append(tmp);
|
||||
}
|
||||
config = new JSONObject(builder.toString());
|
||||
|
||||
try{
|
||||
config = new JSONObject(builder.toString());
|
||||
}catch (JSONException e){
|
||||
File dump = new File(Platform.getConfigFolder().toString()+"/"+MOD_ID+"/config-dump_"+formatMillisToDHMS(System.currentTimeMillis())+"_.json");
|
||||
LOGGER.error("Config is reset due to invalid content, dumping old content to {}", dump.getPath());
|
||||
if(!dump.exists()){
|
||||
dump.createNewFile();
|
||||
}
|
||||
|
||||
try{
|
||||
BufferedWriter out = new BufferedWriter(new FileWriter(dump));
|
||||
out.write(builder.toString());
|
||||
out.close();
|
||||
}catch (IOException ex)
|
||||
{
|
||||
LOGGER.error("Failed to create a dump file and write to it.", ex);
|
||||
LOGGER.warn("Dump content: \n{{}}", builder.toString());
|
||||
}
|
||||
|
||||
config = new JSONObject();
|
||||
defaultValues();
|
||||
return;
|
||||
}
|
||||
|
||||
LOGGER.info("Loaded config successfully");
|
||||
|
||||
if(config.has("version")){
|
||||
if(config.getFloat("version")!=configVersion){
|
||||
if(config.getFloat("version") > configVersion){
|
||||
defualt();
|
||||
LOGGER.warn("Config version is too new, resting");
|
||||
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) {
|
||||
@@ -60,7 +93,7 @@ public class Config {
|
||||
}
|
||||
}
|
||||
|
||||
private static void defualt() {
|
||||
private static void defaultValues() {
|
||||
if(!config.has("speed")) {
|
||||
config.put("speed", SpeedTypes.BlockPS);
|
||||
}
|
||||
@@ -104,10 +137,14 @@ public class Config {
|
||||
if(!config.has("showSpeedType")){
|
||||
config.put("showSpeedType", false);
|
||||
}
|
||||
|
||||
if(!config.has("overrideColor")) {
|
||||
config.put("overrideColor", false);
|
||||
}
|
||||
}
|
||||
|
||||
public static void save(){
|
||||
File config = new File(Platform.getConfigFolder().toString()+"/"+MOD_ID+"/config.json");
|
||||
File config = new File(configPath);
|
||||
if(!config.exists()){
|
||||
try {
|
||||
config.getParentFile().mkdir();
|
||||
@@ -126,7 +163,8 @@ public class Config {
|
||||
}
|
||||
counter=0;
|
||||
}
|
||||
|
||||
|
||||
//region Config Getters
|
||||
public static SpeedTypes getSpeedType(){
|
||||
if(config.has("speed")){
|
||||
return config.getEnum(SpeedTypes.class, "speed");
|
||||
@@ -146,16 +184,21 @@ public class Config {
|
||||
public static Color getColor(){
|
||||
if(config.has("color")){
|
||||
JSONObject color = config.getJSONObject("color");
|
||||
return Color.ofRGB(
|
||||
return new Color(
|
||||
color.getInt("r"),
|
||||
color.getInt("g"),
|
||||
color.getInt("b")
|
||||
);
|
||||
}else{
|
||||
return Color.ofRGB(16, 146, 158);
|
||||
return new Color(16, 146, 158);
|
||||
}
|
||||
}
|
||||
|
||||
public static int getColorRGB()
|
||||
{
|
||||
return getColor().getRGB() & 0xFFFFFF;
|
||||
}
|
||||
|
||||
public static boolean isDebug() {
|
||||
if(config.has("debug")){
|
||||
return config.getBoolean("debug");
|
||||
@@ -167,7 +210,9 @@ public class Config {
|
||||
public static boolean getVisualSpeedometer(){
|
||||
if(config.has("visualSpeedometer")){
|
||||
return config.getBoolean("visualSpeedometer");
|
||||
}else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -203,14 +248,6 @@ public class Config {
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
@@ -218,12 +255,37 @@ public class Config {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getConfigPath()
|
||||
{
|
||||
return configPath;
|
||||
}
|
||||
|
||||
public static BufferedImage getSpeedometer() {
|
||||
return speedometer;
|
||||
}
|
||||
|
||||
public static boolean isDisableVisualSpeedometer() {
|
||||
return disableVisualSpeedometer;
|
||||
}
|
||||
|
||||
public static void setColor(Color color){
|
||||
public static boolean isOverrideColor() {
|
||||
if(config.has("overrideColor")){
|
||||
return config.getBoolean("overrideColor");
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
//region Config Setters
|
||||
|
||||
public static void setColor(int r, int g, int b){
|
||||
config.put("color", new JSONObject()
|
||||
.put("r", color.getRed())
|
||||
.put("g", color.getGreen())
|
||||
.put("b", color.getBlue())
|
||||
.put("r", r)
|
||||
.put("g", g)
|
||||
.put("b", b)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -255,11 +317,21 @@ public class Config {
|
||||
config.put("imageSize", imageSize);
|
||||
}
|
||||
|
||||
public static void setShowVisualSpeedType(boolean showVisualSpeedType){
|
||||
config.put("showVisualSpeedType", showVisualSpeedType);
|
||||
}
|
||||
|
||||
public static void setShowSpeedType(boolean showSpeedType){
|
||||
config.put("showSpeedType", showSpeedType);
|
||||
}
|
||||
|
||||
public static void setSpeedometer(BufferedImage speedometer) {
|
||||
Config.speedometer = speedometer;
|
||||
}
|
||||
|
||||
public static void setDisableVisualSpeedometer (boolean disableVisualSpeedometer){
|
||||
Config.disableVisualSpeedometer = disableVisualSpeedometer;
|
||||
}
|
||||
|
||||
public static void setOverrideColor (boolean overrideColor)
|
||||
{
|
||||
config.put("overrideColor", overrideColor);
|
||||
}
|
||||
//endregion
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
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 me.shedaniel.clothconfig2.api.*;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
@@ -25,8 +22,8 @@ public class ConfigMenu {
|
||||
.build()
|
||||
);
|
||||
|
||||
category.addEntry(entryBuilder.startColorField(Component.translatable("speedometer.config.color"), me.zacharias.speedometer.Config.getColor())
|
||||
.setSaveConsumer2(me.zacharias.speedometer.Config::setColor)
|
||||
category.addEntry(entryBuilder.startColorField(Component.translatable("speedometer.config.color"), me.zacharias.speedometer.Config.getColorRGB())
|
||||
.setSaveConsumer2(color -> Config.setColor(color.getRed(), color.getGreen(), color.getBlue()))
|
||||
.build()
|
||||
);
|
||||
|
||||
@@ -39,6 +36,7 @@ public class ConfigMenu {
|
||||
category.addEntry(entryBuilder.startBooleanToggle(Component.translatable("speedometer.config.visualSpeedometer"), me.zacharias.speedometer.Config.getVisualSpeedometer())
|
||||
.setSaveConsumer(me.zacharias.speedometer.Config::setVisualSpeedometer)
|
||||
.setYesNoTextSupplier((visualSpeedometer -> Component.translatable("speedometer.visualSpeedometer."+visualSpeedometer)))
|
||||
.setRequirement(Requirement.isFalse(Config::isDisableVisualSpeedometer))
|
||||
.build()
|
||||
);
|
||||
|
||||
@@ -58,7 +56,8 @@ public class ConfigMenu {
|
||||
})
|
||||
.setTooltip(
|
||||
Component.translatable("speedometer.config.tooltip.xPosition.line1"),
|
||||
Component.translatable("speedometer.config.tooltip.xPosition.line2")
|
||||
Component.translatable("speedometer.config.tooltip.xPosition.line2"),
|
||||
Component.translatable("speedometer.config.tooltip.xPosition.line3")
|
||||
)
|
||||
.build()
|
||||
);
|
||||
@@ -75,7 +74,8 @@ public class ConfigMenu {
|
||||
})
|
||||
.setTooltip(
|
||||
Component.translatable("speedometer.config.tooltip.yPosition.line1"),
|
||||
Component.translatable("speedometer.config.tooltip.yPosition.line2")
|
||||
Component.translatable("speedometer.config.tooltip.yPosition.line2"),
|
||||
Component.translatable("speedometer.config.tooltip.yPosition.line3")
|
||||
)
|
||||
.build()
|
||||
);
|
||||
@@ -85,6 +85,15 @@ public class ConfigMenu {
|
||||
category.addEntry(entryBuilder.startIntField(Component.translatable("speedometer.config.imageSize"), Config.getImageSize())
|
||||
.setSaveConsumer(Config::setImageSize)
|
||||
.setTooltip(Component.translatable("speedometer.config.tooltip.imageSize"))
|
||||
.setErrorSupplier(size -> {
|
||||
if(size > 300 || size < 10)
|
||||
{
|
||||
return Optional.of(Component.translatable("speedometer.config.error.size_outofbounds"));
|
||||
}
|
||||
else {
|
||||
return Optional.empty();
|
||||
}
|
||||
})
|
||||
.build()
|
||||
);
|
||||
|
||||
@@ -97,16 +106,15 @@ public class ConfigMenu {
|
||||
.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"))
|
||||
category.addEntry(entryBuilder.startBooleanToggle(Component.translatable("speedometer.config.override_color"), Config.isOverrideColor())
|
||||
.setSaveConsumer(Config::setOverrideColor)
|
||||
.setTooltip(
|
||||
Component.translatable("speedometer.config.tooltip.override_color.line1"),
|
||||
Component.translatable("speedometer.config.tooltip.override_color.line2")
|
||||
)
|
||||
.build()
|
||||
);
|
||||
|
||||
|
||||
|
||||
category.addEntry(entryBuilder.startBooleanToggle(Component.translatable("speedometer.config.debug"),Config.isDebug())
|
||||
.setSaveConsumer(Config::setDebug)
|
||||
.setYesNoTextSupplier(isDebug -> Component.translatable("speedometer.debug."+isDebug))
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package me.zacharias.speedometer;
|
||||
|
||||
public class Debugger {
|
||||
public static double angle;
|
||||
public static double x;
|
||||
public static double y;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package me.zacharias.speedometer;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class ImageHandler {
|
||||
@@ -23,4 +24,44 @@ public class ImageHandler {
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates a BufferedImage around a specific point.
|
||||
*
|
||||
* @param image The original BufferedImage to rotate.
|
||||
* @param angle The angle to rotate in degrees (double precision).
|
||||
* @param x The x coordinate of the point to rotate around (int precision).
|
||||
* @param y The y coordinate of the point to rotate around (int precision).
|
||||
* @return A new BufferedImage containing the rotated image.
|
||||
*/
|
||||
public static BufferedImage rotateImage(BufferedImage image, double angle, int x, int y) {
|
||||
// Convert the angle from degrees to radians
|
||||
double radians = Math.toRadians(angle);
|
||||
|
||||
// Get image dimensions
|
||||
int width = image.getWidth();
|
||||
int height = image.getHeight();
|
||||
|
||||
// Create a new BufferedImage with the same width and height
|
||||
BufferedImage rotatedImage = new BufferedImage(width, height, image.getType());
|
||||
|
||||
// Create a Graphics2D object from the new image
|
||||
Graphics2D g2d = rotatedImage.createGraphics();
|
||||
|
||||
// Perform the rotation around the specified point (x, y)
|
||||
AffineTransform transform = new AffineTransform();
|
||||
// Translate the rotation point to the origin (0, 0)
|
||||
transform.translate(x, y);
|
||||
// Rotate around the origin
|
||||
transform.rotate(radians);
|
||||
// Translate back to the original position
|
||||
transform.translate(-x, -y);
|
||||
|
||||
// Draw the rotated image
|
||||
g2d.setTransform(transform);
|
||||
g2d.drawImage(image, 0, 0, null);
|
||||
g2d.dispose();
|
||||
|
||||
return rotatedImage;
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package me.zacharias.speedometer;
|
||||
|
||||
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"), "/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 String meterIcon;
|
||||
private BufferedImage image;
|
||||
private final int size;
|
||||
|
||||
MeterImages(Component name, String meterIcon, int size) {
|
||||
this.name = name;
|
||||
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;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public Component getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package me.zacharias.speedometer;
|
||||
|
||||
public class MissingPropertyException extends Exception {
|
||||
public MissingPropertyException(String field) {
|
||||
super("Missing Speedometer config field: " + field);
|
||||
}
|
||||
}
|
||||
@@ -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,17 +3,25 @@ package me.zacharias.speedometer;
|
||||
import dev.architectury.platform.Platform;
|
||||
import dev.architectury.utils.Env;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.Resource;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class Speedometer
|
||||
{
|
||||
public static final String MOD_ID = "speedometer";
|
||||
public static final Logger LOGGER = LogManager.getLogger(MOD_ID);
|
||||
public static final String VERSION = Platform.getMod(MOD_ID).getVersion();
|
||||
public static SpeedometerIcon ICON = null;
|
||||
|
||||
public static void init() {
|
||||
LOGGER.info("Loading speedometer by Allen");
|
||||
@@ -26,20 +34,65 @@ public class Speedometer
|
||||
if (f.getName().startsWith("speedometer")) {
|
||||
String fileName = "speedometer-" + VERSION + ".jar.disable";
|
||||
if(f.renameTo(new File(f.getParent(), fileName))){
|
||||
LOGGER.warn("Successfully in renaming the mod jar file to "+fileName);
|
||||
LOGGER.warn("You should remove the file from "+Platform.getModsFolder().toString());
|
||||
LOGGER.warn("Successfully in renaming the mod jar file to {}", fileName);
|
||||
LOGGER.warn("You should remove the file from {}", Platform.getModsFolder().toString());
|
||||
}else{
|
||||
LOGGER.warn("Unsuccessful in renaming mod jar");
|
||||
LOGGER.warn("You should remove the mod from "+Platform.getModsFolder().toString()+" to no longer receive this message");
|
||||
LOGGER.warn("You should remove the mod from {} to no longer receive this message", Platform.getModsFolder().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (NullPointerException e){
|
||||
LOGGER.warn("Can't disable the mod");
|
||||
LOGGER.warn("Can't disable the mod. Please delete the file!");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Client.init();
|
||||
}
|
||||
|
||||
public static void loadSpeedometers(ResourceManager resourceManager)
|
||||
{
|
||||
//List< Resource > resource = Minecraft.getInstance().getResourceManager().getResourceStack(ResourceLocation.fromNamespaceAndPath(MOD_ID, "models/speedometer.json"));
|
||||
Optional< Resource > resource = resourceManager.getResource(ResourceLocation.fromNamespaceAndPath(MOD_ID, "models/speedometer.json"));
|
||||
|
||||
if(resource.isEmpty())
|
||||
{
|
||||
Config.setDisableVisualSpeedometer(true);
|
||||
LOGGER.error("Failed to load speedometer config");
|
||||
return;
|
||||
}
|
||||
|
||||
try(BufferedReader stream = resource.get().openAsReader()) {
|
||||
String tmp;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
while ((tmp = stream.readLine()) != null) {
|
||||
builder.append(tmp);
|
||||
}
|
||||
JSONObject data = new JSONObject(builder.toString());
|
||||
if(Config.isDebug())
|
||||
{
|
||||
LOGGER.info("Loaded speedometer from {}, with speedometer name: {}", resource.get().source().packId(), data.get("name"));
|
||||
}
|
||||
ICON = new SpeedometerIcon(data, resourceManager);
|
||||
}
|
||||
catch (Exception e){
|
||||
Config.setDisableVisualSpeedometer(true);
|
||||
LOGGER.error("Failed to load speedometer config", e);
|
||||
return;
|
||||
}
|
||||
|
||||
LOGGER.info("Successfully loaded speedometer config from {}", resource.get().source().packId());
|
||||
}
|
||||
|
||||
public static String formatMillisToDHMS(long millis) {
|
||||
// Calculate the days, hours, minutes, and seconds
|
||||
long seconds = TimeUnit.MILLISECONDS.toSeconds(millis) % 60;
|
||||
long minutes = TimeUnit.MILLISECONDS.toMinutes(millis) % 60;
|
||||
long hours = TimeUnit.MILLISECONDS.toHours(millis) % 24;
|
||||
long days = TimeUnit.MILLISECONDS.toDays(millis);
|
||||
|
||||
// Format the result as DD+HH-MM-SS
|
||||
return String.format("%02d+%02d-%02d-%02d", days, hours, minutes, seconds);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
package me.zacharias.speedometer;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.Resource;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import org.joml.Vector2i;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
public class SpeedometerIcon {
|
||||
private BufferedImage speedometerIcon;
|
||||
private Pointer pointer;
|
||||
private int start;
|
||||
private int end;
|
||||
private float scale;
|
||||
private int max;
|
||||
private boolean overflow;
|
||||
private boolean g = false;
|
||||
|
||||
public SpeedometerIcon(JSONObject config, ResourceManager resourceManager) throws MissingPropertyException, IOException, JSONException
|
||||
{
|
||||
if(!config.has("background")) throw new MissingPropertyException("background");
|
||||
|
||||
String background = config.getString("background");
|
||||
|
||||
if(background.contains(":"))
|
||||
{
|
||||
background = background.replaceFirst(":", ":textures/");
|
||||
}
|
||||
else
|
||||
{
|
||||
background = "textures/"+background;
|
||||
}
|
||||
|
||||
Optional<Resource> speedometerIcon = resourceManager.getResource(ResourceLocation.read(background).getOrThrow(s -> new MissingPropertyException("background")));
|
||||
if(speedometerIcon.isEmpty()) throw new MissingPropertyException("background");
|
||||
|
||||
InputStream stream = speedometerIcon.get().open();
|
||||
this.speedometerIcon = ImageIO.read(stream);
|
||||
stream.close();
|
||||
|
||||
if(!config.has("start")) throw new MissingPropertyException("start");
|
||||
this.start = config.getInt("start");
|
||||
|
||||
if(!config.has("end")) throw new MissingPropertyException("end");
|
||||
this.end = config.getInt("end");
|
||||
|
||||
if(!config.has("scale")) throw new MissingPropertyException("scale");
|
||||
this.scale = config.getFloat("scale");
|
||||
|
||||
if(!config.has("pointer")) throw new MissingPropertyException("pointer");
|
||||
this.pointer = new Pointer(config.getJSONObject("pointer"), resourceManager, new Vector2i(this.speedometerIcon.getWidth(), this.speedometerIcon.getHeight()));
|
||||
|
||||
if(!config.has("maxSpeed")) throw new MissingPropertyException("maxSpeed");
|
||||
this.max = config.getInt("maxSpeed");
|
||||
|
||||
if(!config.has("overflow")) throw new MissingPropertyException("overflow");
|
||||
this.overflow = config.getBoolean("overflow");
|
||||
}
|
||||
|
||||
public BufferedImage getSpeedometerIcon(double speed)
|
||||
{
|
||||
BufferedImage img = ImageHandler.clone(speedometerIcon);
|
||||
Graphics2D graphics = img.createGraphics();
|
||||
pointer.draw(graphics, start, end, max, overflow, Math.pow(speed, scale));
|
||||
return img;
|
||||
}
|
||||
}
|
||||
|
||||
class Pointer
|
||||
{
|
||||
private BufferedImage image;
|
||||
private Color color;
|
||||
private Vector2i start;
|
||||
private int length;
|
||||
private boolean g = false;
|
||||
|
||||
public Pointer(JSONObject pointer, ResourceManager resourceManager, Vector2i size) throws MissingPropertyException, IOException, JSONException
|
||||
{
|
||||
if(!pointer.has("start")) throw new MissingPropertyException("pointer/start");
|
||||
if(pointer.get("start") instanceof JSONObject jsonObject)
|
||||
{
|
||||
if(!jsonObject.has("x")) throw new MissingPropertyException("pointer/start/x");
|
||||
if(!jsonObject.has("y")) throw new MissingPropertyException("pointer/start/y");
|
||||
start = new Vector2i(jsonObject.getInt("x"), jsonObject.getInt("y"));
|
||||
}
|
||||
else if(pointer.get("start") instanceof String str)
|
||||
{
|
||||
if(str.isEmpty()) throw new MissingPropertyException("pointer/start");
|
||||
|
||||
if(str.matches("^\\([0-9]+,( )?[0-9]+\\)+$"))
|
||||
{
|
||||
String[] split = str.split(",");
|
||||
start = new Vector2i(Integer.parseInt(split[0].substring(1)), Integer.parseInt(split[1].substring(0, split[1].length()-1)));
|
||||
}
|
||||
else if(str.equalsIgnoreCase("center"))
|
||||
{
|
||||
start = new Vector2i(size.x / 2, size.y / 2);
|
||||
}
|
||||
else throw new MissingPropertyException("pointer/start");
|
||||
|
||||
}
|
||||
|
||||
if(pointer.has("image"))
|
||||
{
|
||||
String imageResourceLocation = pointer.getString("image");
|
||||
|
||||
if(imageResourceLocation.contains(":"))
|
||||
{
|
||||
imageResourceLocation = imageResourceLocation.replaceFirst(":", ":textures/");
|
||||
}
|
||||
else
|
||||
{
|
||||
imageResourceLocation = "textures/"+imageResourceLocation;
|
||||
}
|
||||
|
||||
Optional<Resource> image = resourceManager.getResource(ResourceLocation.read(imageResourceLocation).getOrThrow(s -> new MissingPropertyException("pointer/image")));
|
||||
if(image.isEmpty()) throw new MissingPropertyException("pointer/image");
|
||||
|
||||
InputStream stream = image.get().open();
|
||||
this.image = ImageHandler.scale(ImageIO.read(stream), size.x, size.y);
|
||||
stream.close();
|
||||
}
|
||||
else if(pointer.has("length"))
|
||||
{
|
||||
if(pointer.get("length") instanceof String str)
|
||||
{
|
||||
length = switch (str.toLowerCase())
|
||||
{
|
||||
case "half" -> size.x / 2;
|
||||
case "full" -> size.x;
|
||||
default -> throw new MissingPropertyException("pointer/length");
|
||||
};
|
||||
}
|
||||
else if(pointer.get("length") instanceof Integer integer)
|
||||
{
|
||||
length = integer;
|
||||
}
|
||||
else throw new MissingPropertyException("pointer/length");
|
||||
|
||||
if(pointer.has("color"))
|
||||
{
|
||||
String c = pointer.getString("color");
|
||||
if(!c.matches("^#[0-9a-fA-F]{6}$")) throw new MissingPropertyException("pointer/color");
|
||||
color = new Color(Integer.parseInt(c.substring(1), 16));
|
||||
}
|
||||
else throw new MissingPropertyException("pointer/color");
|
||||
}
|
||||
else throw new MissingPropertyException("pointer/image or pointer/length");
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g2d, int start, int end, int max, boolean overflow, double speed)
|
||||
{
|
||||
Color c = color;
|
||||
if(Config.isOverrideColor())
|
||||
{
|
||||
c = Config.getColor();
|
||||
}
|
||||
double angle = ((speed/max) * end)+start;
|
||||
if(angle > end && !overflow) angle = end;
|
||||
Debugger.angle = angle;
|
||||
|
||||
if(Objects.nonNull(image))
|
||||
{
|
||||
int centerX = this.start.x;
|
||||
int centerY = this.start.y;
|
||||
BufferedImage image = ImageHandler.rotateImage(this.image, angle, centerX, centerY);
|
||||
g2d.drawImage(image, 0, 0, null);
|
||||
}
|
||||
else if(c != null && length > 0)
|
||||
{
|
||||
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);
|
||||
Debugger.x = endX;
|
||||
Debugger.y = endY;
|
||||
|
||||
g2d.setColor(c);
|
||||
g2d.setStroke(new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
|
||||
g2d.drawLine(this.start.x, this.start.y, endX, endY);
|
||||
}
|
||||
else
|
||||
{
|
||||
Config.setDisableVisualSpeedometer(true);
|
||||
throw new NullPointerException("image and line pointer both are undefined");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
"speedometer.config.imageSize": "Image Size",
|
||||
"speedometer.config.showVisualSpeedType": "\u00A74⨻\u00A7rShow Visual Speed Type",
|
||||
"speedometer.config.showSpeedType": "Show Visual Speed Type",
|
||||
"speedometer.config.override_color": "Override color",
|
||||
|
||||
"speedometer.key.configKey": "Config Key",
|
||||
"speedometer.key.debugKey": "Debug Key",
|
||||
@@ -29,7 +30,7 @@
|
||||
|
||||
"speedometer.meter.large": "Large",
|
||||
"speedometer.meter.small": "Small",
|
||||
"speedometer.meter.medium": "Small",
|
||||
"speedometer.meter.medium": "Medium",
|
||||
|
||||
"speedometer.visualSpeedometer.true": "Visual",
|
||||
"speedometer.visualSpeedometer.false": "Text",
|
||||
@@ -60,5 +61,14 @@
|
||||
|
||||
"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"
|
||||
"speedometer.config.tooltip.override_color.line1": "Override the color of a line pointer",
|
||||
"speedometer.config.tooltip.override_color.line2": "OPS doesn't work if the pointer is an image!",
|
||||
|
||||
"speedometer.invalid": "Invalid String",
|
||||
|
||||
"speedometer.config.error.size_outofbounds": "The size is out of bounds 10<=size<=300",
|
||||
|
||||
"speedometer.error.missing_cloth": "Missing Cloth Config API for Config Screen",
|
||||
|
||||
"resourcepack.speedometer.quarter_circle_speedometer": "Quarter circle Speedometer"
|
||||
}
|
||||
74
common/src/main/resources/assets/speedometer/lang/sv_se.json
Normal file
@@ -0,0 +1,74 @@
|
||||
{
|
||||
"speedometer.config.name": "Speedometer Config",
|
||||
"speedometer.config.category.name": "Speedometer Konfigurationskatigori",
|
||||
"speedometer.config.speed": "Fart Typ",
|
||||
"speedometer.config.color": "Färg",
|
||||
"speedometer.config.knot": "Använd Knot i Båtar",
|
||||
"speedometer.config.visualSpeedometer": "Visuel Fartmätare",
|
||||
"speedometer.config.xPosition.visual": "X Positionen för Visuel Mätare",
|
||||
"speedometer.config.yPosition.visual": "Y Positionen för Visuel Mätare",
|
||||
"speedometer.config.xPosition.text": "X Positionen för Text Mätare",
|
||||
"speedometer.config.yPosition.text": "Y Positionen för Text Mätare",
|
||||
"speedometer.config.xPosition": "X Positionen för Mätare",
|
||||
"speedometer.config.yPosition": "Y Positionen för Mätare",
|
||||
"speedometer.config.debug": "Debug",
|
||||
"speedometer.config.imageSize": "Bildstorlek",
|
||||
"speedometer.config.showVisualSpeedType": "\u00A74⨻\u00A7rVisa Visuell Farttyp",
|
||||
"speedometer.config.showSpeedType": "Visa Visuell Farttyp",
|
||||
"speedometer.config.override_color": "Överskrid färgen",
|
||||
|
||||
"speedometer.key.configKey": "Konfigurations Knapp",
|
||||
"speedometer.key.debugKey": "Debug Knapp",
|
||||
"speedometer.key.category": "Speedometer",
|
||||
|
||||
"speedometer.speed.mph": "MPH",
|
||||
"speedometer.speed.mps": "Meter/s",
|
||||
"speedometer.speed.kmph": "Km/h",
|
||||
"speedometer.speed.bps": "Blocks/s",
|
||||
"speedometer.speed.knot": "Knot",
|
||||
"speedometer.speed.error": "Okänd Fart Typ",
|
||||
|
||||
"speedometer.meter.large": "Stor",
|
||||
"speedometer.meter.small": "Liten",
|
||||
"speedometer.meter.medium": "Mellan",
|
||||
|
||||
"speedometer.visualSpeedometer.true": "Visuel",
|
||||
"speedometer.visualSpeedometer.false": "Text",
|
||||
|
||||
"speedometer.useKnot.true": "Ja",
|
||||
"speedometer.useKnot.false": "Nej",
|
||||
|
||||
"speedometer.debug.true": "\u00A74Ja",
|
||||
"speedometer.debug.false": "\u00A74Nej",
|
||||
|
||||
"speedometer.show": "Visa",
|
||||
"speedometer.hide": "Göm",
|
||||
|
||||
"speedometer.config.tooltip.xPosition.line1": "W = fönstrets bred",
|
||||
"speedometer.config.tooltip.xPosition.line2": "w = halva fönstrets bred",
|
||||
"speedometer.config.tooltip.xPosition.line3": "s = breden på texten eller bilden",
|
||||
|
||||
"speedometer.config.tooltip.yPosition.line1": "H = fönstrets höjd",
|
||||
"speedometer.config.tooltip.yPosition.line2": "h = halva fönstrets höjd",
|
||||
"speedometer.config.tooltip.yPosition.line3": "s = höjden av texten eller bilden",
|
||||
|
||||
"speedometer.config.tooltip.debug": "Debug Information",
|
||||
|
||||
"speedometer.config.tooltip.imageSize": "Storleken på bilden. Detta bestämmer både bredden och höjden av bilden",
|
||||
|
||||
"speedometer.config.tooltip.showVisualSpeedType.line1": "Denna instälningen funkar inte helt och hållet",
|
||||
"speedometer.config.tooltip.showVisualSpeedType.line2": "Jag (utvecklaren) avråder användandet av denna inställning då den inte fungerar vid mindre storlekar och förstör FPS vid större storlekar",
|
||||
|
||||
"speedometer.config.tooltip.showSpeedType.line1": "Denna inställning visar farttypen ovanför den visuella mätaren, vilket är bättre än inuti mätaren",
|
||||
|
||||
"speedometer.config.tooltip.override_color.line1": "Överskrider förgen av linjen pekaren",
|
||||
"speedometer.config.tooltip.override_color.line2": "OBS funkar inte om pekaren är en bild!",
|
||||
|
||||
"speedometer.invalid": "Inte korrekt Sträng",
|
||||
|
||||
"speedometer.config.error.size_outofbounds": "Stolekten är felakting 10<=stolek<=300",
|
||||
|
||||
"speedometer.error.missing_cloth": "Saknar Cloth Config API för konfigurationsskärmen",
|
||||
|
||||
"resourcepack.speedometer.quarter_circle_speedometer": "Quarter circle Speedometer"
|
||||
}
|
||||
|
Before Width: | Height: | Size: 316 B |
|
Before Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"background": "speedometer:meter/speedometer.png",
|
||||
"start": -45,
|
||||
"end": 225,
|
||||
"maxSpeed": 120,
|
||||
"overflow": true,
|
||||
"pointer": {
|
||||
"color": "#b00219",
|
||||
"length": 50,
|
||||
"start": "center"
|
||||
},
|
||||
"scale": 1,
|
||||
"name": "Full cycle style"
|
||||
}
|
||||
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
@@ -18,16 +18,18 @@ configurations {
|
||||
repositories {
|
||||
maven { url "https://maven.shedaniel.me/" }
|
||||
maven { url "https://maven.terraformersmc.com/releases/" }
|
||||
maven { url "https://maven.nucleoid.xyz/" }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
|
||||
modApi "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}"
|
||||
modApi "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}+${rootProject.minecraft_version}"
|
||||
// Remove the next line if you don't want to depend on the API
|
||||
modApi "dev.architectury:architectury-fabric:${rootProject.architectury_version}"
|
||||
|
||||
modApi "me.shedaniel.cloth:cloth-config-fabric:11.1.106"
|
||||
modApi "com.terraformersmc:modmenu:7.1.0"
|
||||
modApi "me.shedaniel.cloth:cloth-config-fabric:${rootProject.cloth_config_version}"
|
||||
modApi "com.terraformersmc:modmenu:${rootProject.modmenu_version}"
|
||||
modApi "eu.pb4:placeholder-api:2.4.0-pre.2+1.21"
|
||||
|
||||
common(project(path: ":common", configuration: "namedElements")) { transitive false }
|
||||
shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false }
|
||||
|
||||
@@ -2,10 +2,35 @@ package me.zacharias.speedometer.fabric;
|
||||
|
||||
import me.zacharias.speedometer.Speedometer;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
|
||||
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
|
||||
public class SpeedometerFabric implements ModInitializer {
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
Speedometer.init();
|
||||
|
||||
//Minecraft.getInstance().getResourcePackRepository().addPack()
|
||||
|
||||
ResourceManagerHelper.get(PackType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
|
||||
/**
|
||||
* Register the reload listener for the speedometers
|
||||
* This is required since i haven't found how to put this in the Architecture Abstraction layer(Common module)
|
||||
* TODO: Find a way to put this in the Abstraction layer
|
||||
* @param resourceManager The event that is fired when the client reloads resources
|
||||
*/
|
||||
@Override
|
||||
public void onResourceManagerReload(ResourceManager resourceManager) {
|
||||
Speedometer.loadSpeedometers(resourceManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getFabricId() {
|
||||
return ResourceLocation.fromNamespaceAndPath("speedometer", "visual_speedometer_reload_listener");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,9 @@
|
||||
"id": "speedometer",
|
||||
"version": "${version}",
|
||||
|
||||
"name": "speedometer",
|
||||
"name": "Speedometer",
|
||||
"description": "just displaying your speed",
|
||||
"authors": ["Allen"],
|
||||
"authors": ["Zacharias"],
|
||||
"contact": {
|
||||
"sources": "https://github.com/zaze06/Speedometer",
|
||||
"issues": "https://github.com/zaze06/Speedometer/issues"
|
||||
@@ -19,9 +19,11 @@
|
||||
"main": ["me.zacharias.speedometer.fabric.SpeedometerFabric"]
|
||||
},
|
||||
"depends": {
|
||||
"fabricloader": ">=0.14.21",
|
||||
"minecraft": ">=1.20",
|
||||
"cloth-config": ">=11.1.106",
|
||||
"architectury": ">=9.1.10"
|
||||
"fabricloader": ">=0.15.11",
|
||||
"minecraft": ">=1.21",
|
||||
"architectury": ">=13.0.5"
|
||||
},
|
||||
"suggests": {
|
||||
"cloth-config1": ">=15.0.140"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"pack": {
|
||||
"pack_format": 15,
|
||||
"pack_format": 34,
|
||||
"description": "speedometer resources"
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
loom.platform=forge
|
||||
@@ -1,15 +0,0 @@
|
||||
package me.zacharias.speedometer.forge;
|
||||
|
||||
import dev.architectury.platform.forge.EventBuses;
|
||||
import me.zacharias.speedometer.Speedometer;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
|
||||
@Mod(Speedometer.MOD_ID)
|
||||
public class SpeedometerForge {
|
||||
public SpeedometerForge() {
|
||||
// Submit our event bus to let architectury register our content on the right time
|
||||
EventBuses.registerModEventBus(Speedometer.MOD_ID, FMLJavaModLoadingContext.get().getModEventBus());
|
||||
Speedometer.init();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"pack": {
|
||||
"pack_format": 15,
|
||||
"description": "speedometer resources",
|
||||
"forge:server_data_pack_format": 12
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,65 @@
|
||||
{
|
||||
"homepage": "https://modrinth.com/mod/speedometer/versions",
|
||||
"1.20.6": {
|
||||
"1.0": "First version",
|
||||
"2.0": "Made the speedometer text movable, added debug data display, added visual speedometer",
|
||||
"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",
|
||||
"5.0": "Visual speed display has been added",
|
||||
"5.1": "Added second speed display",
|
||||
"5.2": "Fixed issue #1",
|
||||
"5.2.1": "Fixed issue #3"
|
||||
},
|
||||
"1.20.5": {
|
||||
"1.0": "First version",
|
||||
"2.0": "Made the speedometer text movable, added debug data display, added visual speedometer",
|
||||
"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",
|
||||
"5.0": "Visual speed display has been added",
|
||||
"5.1": "Added second speed display",
|
||||
"5.2": "Fixed issue #1",
|
||||
"5.2.1": "Fixed issue #3"
|
||||
},
|
||||
"1.20.4": {
|
||||
"1.0": "First version",
|
||||
"2.0": "Made the speedometer text movable, added debug data display, added visual speedometer",
|
||||
"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",
|
||||
"5.0": "Visual speed display has been added",
|
||||
"5.1": "Added second speed display",
|
||||
"5.2": "Fixed issue #1",
|
||||
"5.2.1": "Fixed issue #3"
|
||||
},
|
||||
"1.20.3": {
|
||||
"1.0": "First version",
|
||||
"2.0": "Made the speedometer text movable, added debug data display, added visual speedometer",
|
||||
"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",
|
||||
"5.0": "Visual speed display has been added",
|
||||
"5.1": "Added second speed display",
|
||||
"5.2": "Fixed issue #1",
|
||||
"5.2.1": "Fixed issue #3"
|
||||
},
|
||||
"1.20.2": {
|
||||
"1.0": "First version",
|
||||
"2.0": "Made the speedometer text movable, added debug data display, added visual speedometer",
|
||||
"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",
|
||||
"5.0": "Visual speed display has been added",
|
||||
"5.1": "Added second speed display",
|
||||
"5.2": "Fixed issue #1",
|
||||
"5.2.1": "Fixed issue #3"
|
||||
},
|
||||
"1.20.1": {
|
||||
"1.0": "First version",
|
||||
"2.0": "Made the speedometer text movable, added debug data display, added visual speedometer",
|
||||
@@ -8,7 +68,9 @@
|
||||
"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",
|
||||
"5.0": "Visual speed display has been added",
|
||||
"5.1": "Added second speed display"
|
||||
"5.1": "Added second speed display",
|
||||
"5.2": "Fixed issue #1",
|
||||
"5.2.1": "Fixed issue #3"
|
||||
},
|
||||
"1.20": {
|
||||
"1.0": "First version",
|
||||
@@ -18,13 +80,30 @@
|
||||
"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",
|
||||
"5.0": "Visual speed display has been added",
|
||||
"5.1": "Added second speed display"
|
||||
"5.1": "Added second speed display",
|
||||
"5.2": "Fixed issue #1",
|
||||
"5.2.1": "Fixed issue #3"
|
||||
},
|
||||
"promos": {
|
||||
"1.20.1-latest": "5.1",
|
||||
"1.20.1-recommended": "5.1",
|
||||
|
||||
"1.20-latest": "5.1",
|
||||
"1.20-recommended": "5.1"
|
||||
"1.20.6-latest": "5.2",
|
||||
"1.20.6-recommended": "5.2",
|
||||
|
||||
"1.20.5-latest": "5.2",
|
||||
"1.20.5-recommended": "5.2",
|
||||
|
||||
"1.20.4-latest": "5.2",
|
||||
"1.20.4-recommended": "5.2",
|
||||
|
||||
"1.20.3-latest": "5.2",
|
||||
"1.20.3-recommended": "5.2",
|
||||
|
||||
"1.20.2-latest": "5.2",
|
||||
"1.20.2-recommended": "5.2",
|
||||
|
||||
"1.20.1-latest": "5.2",
|
||||
"1.20.1-recommended": "5.2",
|
||||
|
||||
"1.20-latest": "5.2",
|
||||
"1.20-recommended": "5.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,29 @@
|
||||
org.gradle.jvmargs=-Xmx8G
|
||||
|
||||
minecraft_version=1.20.1
|
||||
minecraft_version=1.21.4
|
||||
|
||||
archives_base_name=speedometer
|
||||
mod_version=5.1
|
||||
mod_version=6.2.2
|
||||
maven_group=me.zacharias
|
||||
|
||||
architectury_version=9.1.10
|
||||
# https://modrinth.com/mod/architectury-api/versions
|
||||
architectury_version=15.0.1
|
||||
|
||||
fabric_loader_version=0.14.21
|
||||
fabric_api_version=0.84.0+1.20.1
|
||||
# https://modrinth.com/mod/cloth-config/versions
|
||||
cloth_config_version = 17.0.144
|
||||
|
||||
forge_version=1.20.1-47.0.19
|
||||
# NeoForged Only
|
||||
# https://neoforged.net/
|
||||
neoforge_version = 21.4.30-beta
|
||||
|
||||
# Fabric Only
|
||||
# https://fabricmc.net/develop/
|
||||
fabric_loader_version=0.16.9
|
||||
fabric_api_version=0.112.1
|
||||
|
||||
# Fabric Only
|
||||
# https://modrinth.com/mod/modmenu/versions
|
||||
modmenu_version = 13.0.0-beta.1
|
||||
|
||||
# Version of the org.json json library
|
||||
json_version = 20240303
|
||||
4
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
||||
#Fri Jun 21 10:45:53 CEST 2024
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
|
||||
networkTimeout=10000
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
plugins {
|
||||
id "com.github.johnrengelman.shadow" version "7.1.2"
|
||||
id "com.github.johnrengelman.shadow" version "8.1.1"
|
||||
}
|
||||
architectury {
|
||||
platformSetupLoomIde()
|
||||
forge()
|
||||
neoForge()
|
||||
}
|
||||
|
||||
repositories{
|
||||
maven {
|
||||
name = 'NeoForged'
|
||||
url = 'https://maven.neoforged.net/releases'
|
||||
}
|
||||
maven { url "https://maven.shedaniel.me/" }
|
||||
}
|
||||
|
||||
@@ -15,24 +19,24 @@ configurations {
|
||||
shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this.
|
||||
compileClasspath.extendsFrom common
|
||||
runtimeClasspath.extendsFrom common
|
||||
developmentForge.extendsFrom common
|
||||
developmentNeoForge.extendsFrom common
|
||||
}
|
||||
|
||||
dependencies {
|
||||
forge "net.minecraftforge:forge:${rootProject.forge_version}"
|
||||
neoForge "net.neoforged:neoforge:$rootProject.neoforge_version"
|
||||
// Remove the next line if you don't want to depend on the API
|
||||
modApi "dev.architectury:architectury-forge:${rootProject.architectury_version}"
|
||||
modImplementation "dev.architectury:architectury-neoforge:$rootProject.architectury_version"
|
||||
|
||||
modApi "me.shedaniel.cloth:cloth-config-forge:11.1.106"
|
||||
modImplementation "me.shedaniel.cloth:cloth-config-neoforge:$rootProject.cloth_config_version"
|
||||
|
||||
common(project(path: ":common", configuration: "namedElements")) { transitive false }
|
||||
shadowCommon(project(path: ":common", configuration: "transformProductionForge")) { transitive = false }
|
||||
shadowCommon(project(path: ":common", configuration: "transformProductionNeoForge")) { transitive = false }
|
||||
}
|
||||
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
|
||||
filesMatching("META-INF/mods.toml") {
|
||||
filesMatching("META-INF/neoforge.mods.toml") {
|
||||
expand "version": project.version
|
||||
}
|
||||
}
|
||||
1
neoforge/gradle.properties
Normal file
@@ -0,0 +1 @@
|
||||
loom.platform=neoforge
|
||||
@@ -0,0 +1,55 @@
|
||||
package me.zacharias.speedometer.forge;
|
||||
|
||||
import com.mojang.datafixers.util.Unit;
|
||||
import me.zacharias.speedometer.Speedometer;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.server.packs.resources.SimplePreparableReloadListener;
|
||||
import net.minecraft.util.profiling.ProfilerFiller;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.neoforged.neoforge.client.event.RegisterClientReloadListenersEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@Mod(Speedometer.MOD_ID)
|
||||
public class SpeedometerNeoForge {
|
||||
public SpeedometerNeoForge(IEventBus eventBus) {
|
||||
// Submit our event bus to let architectury register our content on the right time
|
||||
Speedometer.init();
|
||||
|
||||
//ResourcePackLoader.buildPackFinder()
|
||||
}
|
||||
}
|
||||
|
||||
@EventBusSubscriber(modid = Speedometer.MOD_ID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
|
||||
class EventHandler
|
||||
{
|
||||
/**
|
||||
* Register the reload listener for the speedometers
|
||||
* This is required since i haven't found how to put this in the Architecture Abstraction layer(Common module)
|
||||
* TODO: Find a way to put this in the Abstraction layer
|
||||
* @param event The event that is fired when the client reloads resources
|
||||
*/
|
||||
@SubscribeEvent
|
||||
private static void onResourceReload(RegisterClientReloadListenersEvent event) {
|
||||
event.registerReloadListener(new SimplePreparableReloadListener<Unit>() {
|
||||
@Override
|
||||
protected @NotNull Unit prepare(@NotNull ResourceManager arg, @NotNull ProfilerFiller arg2) {
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void apply(@NotNull Unit object, @NotNull ResourceManager resourceManager, @NotNull ProfilerFiller arg2) {
|
||||
Speedometer.loadSpeedometers(resourceManager);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
private static void clientStart(FMLClientSetupEvent event) {
|
||||
//Minecraft.getInstance().getResourcePackRepository().addPackFinder(consumer -> consumer.accept());
|
||||
}
|
||||
}
|
||||
@@ -1,37 +1,50 @@
|
||||
# This is an example mods.toml file. It contains the data relating to the loading mods.
|
||||
# This is an example neoforge.mods.toml file. It contains the data relating to the loading mods.
|
||||
# There are several mandatory fields (#mandatory), and many more that are optional (#optional).
|
||||
# The overall format is standard TOML format, v0.5.0.
|
||||
# Note that there are a couple of TOML lists in this file.
|
||||
# Find more information on toml format here: https://github.com/toml-lang/toml
|
||||
|
||||
# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml
|
||||
modLoader="javafml" #mandatory
|
||||
|
||||
# A version range to match for said mod loader - for regular FML @Mod it will be the forge version
|
||||
loaderVersion="[46,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions.
|
||||
loaderVersion="[2,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions.
|
||||
|
||||
# The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties.
|
||||
# Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here.
|
||||
license="All Rights Reserved"
|
||||
|
||||
# A URL to refer people to when problems occur with this mod
|
||||
issueTrackerURL="https://github.com/zaze06/speedometer/issues"
|
||||
issueTrackerURL="https://github.com/zaze06/Speedometer/issues"
|
||||
|
||||
# A list of mods - how many allowed here is determined by the individual mod loader
|
||||
[[mods]] #mandatory
|
||||
|
||||
# The modid of the mod
|
||||
modId="speedometer" #mandatory
|
||||
|
||||
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
|
||||
# ${version} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata
|
||||
# see the associated build.gradle script for how to populate this completely automatically during a build
|
||||
version="${version}" #mandatory
|
||||
|
||||
# A display name for the mod
|
||||
displayName="speedometer" #mandatory
|
||||
displayName="Speedometer" #mandatory
|
||||
|
||||
# A URL to query for updates for this mod. See the JSON update specification <here>
|
||||
updateJSONURL="https://raw.githubusercontent.com/zaze06/Speedometer/master/forge/src/main/resources/updateChecker.json" #optional
|
||||
updateJSONURL="https://raw.githubusercontent.com/zaze06/Speedometer/master/neoforge/src/main/resources/updateChecker.json" #optional
|
||||
|
||||
# A URL for the "homepage" for this mod, displayed in the mod UI
|
||||
displayURL="https://modrinth.com/mod/speedometer" #optional
|
||||
|
||||
# A file name (in the root of the mod JAR) containing a logo for display
|
||||
logoFile="icon.png" #optional
|
||||
|
||||
# A text field displayed in the mod UI
|
||||
#credits="Thanks for this example mod goes to Java" #optional
|
||||
# A text field displayed in the mod UI
|
||||
authors="Allen" #optional
|
||||
authors="Zacharias" #optional
|
||||
|
||||
# Display Test controls the display for your mod in the server connection screen
|
||||
# MATCH_VERSION means that your mod will cause a red X if the versions on client and server differ. This is the default behaviour and should be what you choose if you have server and client elements to your mod.
|
||||
# IGNORE_SERVER_VERSION means that your mod will not cause a red X if it's present on the server but not on the client. This is what you should use if you're a server only mod.
|
||||
@@ -42,37 +55,39 @@ displayTest="IGNORE_ALL_VERSION" # MATCH_VERSION is the default if nothing is sp
|
||||
|
||||
# The description text for the mod (multi line!) (#mandatory)
|
||||
description='''
|
||||
just displaying your speed
|
||||
Just displaying your speed
|
||||
'''
|
||||
|
||||
[[resource_packs]]
|
||||
secondary = "resourcepacks/quarter_circle_speedometer"
|
||||
|
||||
# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional.
|
||||
[[dependencies.speedometer]] #optional
|
||||
# the modid of the dependency
|
||||
modId="forge" #mandatory
|
||||
modId="neoforge" #mandatory
|
||||
# Does this dependency have to exist - if not, ordering below must be specified
|
||||
mandatory=true #mandatory
|
||||
# The version range of the dependency
|
||||
versionRange="[46,)" #mandatory
|
||||
versionRange="[21.0.78-beta,)" #mandatory
|
||||
# An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory
|
||||
ordering="NONE"
|
||||
# Side this dependency is applied on - BOTH, CLIENT or SERVER
|
||||
side="BOTH"
|
||||
# Here's another dependency
|
||||
side="CLIENT"
|
||||
[[dependencies.speedometer]]
|
||||
modId="minecraft"
|
||||
mandatory=true
|
||||
# This version range declares a minimum of the current minecraft version up to but not including the next major version
|
||||
versionRange="[1.20,1.21)"
|
||||
versionRange="[1.21,1.22)"
|
||||
ordering="NONE"
|
||||
side="BOTH"
|
||||
[[dependencies.speedometer]]
|
||||
modId="architectury"
|
||||
mandatory=true
|
||||
versionRange="[9.1.10,)"
|
||||
ordering="NONE"
|
||||
versionRange="[13.0.5,)"
|
||||
ordering="BEFORE"
|
||||
side="CLIENT"
|
||||
[[dependencies.speedometer]]
|
||||
modId="cloth_config"
|
||||
mandatory=true
|
||||
versionRange="[11.1.106,)"
|
||||
ordering="NONE"
|
||||
type="optional"
|
||||
versionRange="[15.0.140,)"
|
||||
ordering="BEFORE"
|
||||
side="CLIENT"
|
||||
|
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
6
neoforge/src/main/resources/pack.mcmeta
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"pack": {
|
||||
"pack_format": 34,
|
||||
"description": "speedometer resources"
|
||||
}
|
||||
}
|
||||
14
neoforge/src/main/resources/updateChecker.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"homepage": "https://modrinth.com/mod/speedometer/versions",
|
||||
"1.21": {
|
||||
"6.0": "Lost support for Forge and gain NeoForge support",
|
||||
"6.0.1": "Small bug fix in Parser",
|
||||
"6.1": "Small bug fix in Parser",
|
||||
"6.2": "Making speedometer and pointer resource pack based",
|
||||
"6.2.1": "Fixed issue #3"
|
||||
},
|
||||
"promos": {
|
||||
"1.21-latest": "6.2.1",
|
||||
"1.21-recommended": "6.2.1"
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
# Speedometer
|
||||
This is a simple mod for forge and fabric that displays your current speed
|
||||
This is a simple mod for Forge, Fabric, and NeoForged that displays your current speed
|
||||
|
||||
## Credits to
|
||||
[org.json](https://www.json.org/json-en.html) *Included due to problems whit ForgeGradle*
|
||||
[org.json](https://www.json.org/json-en.html) *Included due to problems whit Gradle and building*
|
||||
|
||||
## Compile your own version?
|
||||
1. Download source code
|
||||
@@ -13,7 +13,10 @@ This is a simple mod for forge and fabric that displays your current speed
|
||||
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`
|
||||
* Forge: `neoforged/build/libs`
|
||||
|
||||
## Forge Support Transition
|
||||
As of version 1.21 I chose to no longer support Forge in fevour of NeoForged
|
||||
|
||||
|
||||
# This mod is a newer version of [speedometer-forge](https://github.com/zaze06/speedometer-forge)
|
||||
|
||||
94
resourcepack.md
Normal file
@@ -0,0 +1,94 @@
|
||||
# Speedometer resourcepack setup
|
||||
This guide explains how to set up a speedometer resource pack for Minecraft, including file structure and configuration options.
|
||||
|
||||
## Supported versions
|
||||
This feature is supported in
|
||||
- Speedometer 6.2 and forwards
|
||||
- Minecraft 1.21.x and forward
|
||||
|
||||
## `pack.mcmeta`
|
||||
The mcmeta file has no differences just make sure it's a valid pack_format for the version
|
||||
- 1.21.x: `"pack_format": 34`
|
||||
- I recommend adding this, so that you don't need to update the format since the only real requirement is using version 6.2 or newer of this mod
|
||||
```jsonc
|
||||
"supported_formats": {
|
||||
"min_inclusive": 34,
|
||||
"max_inclusive": 57 // This needs to be the leatest pack_format
|
||||
}
|
||||
```
|
||||
|
||||
## File Locations
|
||||
So the speedometer is built upon 2 main things
|
||||
- speedometer.json
|
||||
- speedometer.png *this is a placeholder name*
|
||||
|
||||
There is also the optional of
|
||||
- pointer.png *this is a placeholder name*
|
||||
|
||||
resource pack tree
|
||||
```
|
||||
base
|
||||
├── assets
|
||||
│ └── speedometer # Referred to as a "module" in this documentation
|
||||
│ ├── models
|
||||
│ │ └── speedometer.json
|
||||
│ ├── textures
|
||||
│ │ ├── speedometer.png
|
||||
│ │ └── pointer.png
|
||||
├── pack.mcmeta
|
||||
└── pack.png
|
||||
```
|
||||
|
||||
## `speedometer.json` example *Standard speedometer.json file*
|
||||
```json
|
||||
{
|
||||
"background": "speedometer:meter/speedometer.png",
|
||||
"start": -45,
|
||||
"end": 225,
|
||||
"maxSpeed": 120,
|
||||
"overflow": true,
|
||||
"pointer": {
|
||||
"color": "#b00219",
|
||||
"length": 50,
|
||||
"start": "center"
|
||||
},
|
||||
"scale": 1,
|
||||
"name": "Full cycle style"
|
||||
}
|
||||
```
|
||||
|
||||
### Explanation of values
|
||||
- background
|
||||
The file speedometer.png is located in the meter subdirectory of the textures folder, inside the speedometer module of your resource pack.<br>
|
||||
This can also have the value `minecraft:meter/speedometer.png` and it would instead point to the same location inside the `minecraft` module.
|
||||
- start
|
||||
The angle in degrees where the pointer is pointing at when the speed is 0. *This value has the 0 value of ether the `pointer/image` or to the right of `pointer/start`*
|
||||
- end
|
||||
The angle in degrees where the pointer is pointing when `maxSpeed` is reached. *Same base value as `start`*
|
||||
- maxSpeed
|
||||
This value defines the maximum speed the speedometer will display. You can interpret this as blocks per second (b/s), kilometers per hour (km/h), or miles per hour (mph), depending on how you're measuring the in-game speed.
|
||||
- overflow
|
||||
This boolean is false if the pointer locks at the `end` angle when the speed exceeds `maxSpeed`.
|
||||
- pointer
|
||||
This defines properties of the pointer.
|
||||
- color *not required, but if not present then `image` most be*
|
||||
The color value should be a hexadecimal RGB code, e.g., #b00219, where # is followed by six characters representing red, green, and blue values (00-FF for each component).
|
||||
- length *not required if `image` is not defined*
|
||||
The length in picture based on the original size of the background.
|
||||
- start
|
||||
The start parameter defines where the pointer begins. You can use predefined strings (center, left, right) or specify a custom position using the format (x, y), where x and y are the coordinates. Alternatively, you can define an object with x and y keys to set exact positions.<br>
|
||||
If you use this with an image, it's the point of where the pointer image is rotates around
|
||||
- image
|
||||
This defines the scaling factor for speed. The actual speed is calculated as baseSpeed^scale, where the base speed is raised to the power of the scale. <br>
|
||||
OPS this picture should be the same size as the background to not cause issues
|
||||
- scale
|
||||
The scale of how to modify the speed as a power, this is the speed that `maxSpeed` is based of. the way the speed passed to `maxSpeed` is calculated is `baseSpeed^scale`.
|
||||
- name
|
||||
A string that is the name of this speedometer. *This is just used to send a log message about the speedometer*
|
||||
|
||||
## JSON formating help
|
||||
I have created a JSON schema for this that is available at [speedometer_config_schema.json](https://github.com/zaze06/Speedometer/blob/master/schemas/speedometer_config_schema.json), please refer to your Advanced Text Editor on how to add a schema, if your editor supports the `$schema` feature then add
|
||||
```json
|
||||
"$schema": "https://raw.githubusercontent.com/zaze06/Speedometer/refs/heads/master/schemas/speedometer_config_schema.json",
|
||||
```
|
||||
in the root object, and the schema should apply, else if your editor supports it you can add the schema to all `speedometer.json` files
|
||||
110
schemas/speedometer_config_schema.json
Normal file
@@ -0,0 +1,110 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "A name for your speedometer"
|
||||
},
|
||||
"background": {
|
||||
"type": "string",
|
||||
"description": "Path to the background texture file (e.g., 'meter/speedometer.png')"
|
||||
},
|
||||
"start": {
|
||||
"type": "integer",
|
||||
"description": "Start value for the speedometer scale in degrees"
|
||||
},
|
||||
"end": {
|
||||
"type": "integer",
|
||||
"description": "End value for the speedometer scale in degrees"
|
||||
},
|
||||
"maxSpeed": {
|
||||
"type": "number",
|
||||
"description": "The max speed, as in the end point angle in Blocks/s"
|
||||
},
|
||||
"overflow": {
|
||||
"type": "boolean",
|
||||
"description": "Dose the pointer overflow after maxSpeed"
|
||||
},
|
||||
"pointer": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"color": {
|
||||
"type": "string",
|
||||
"pattern": "^#[0-9a-fA-F]{6}$",
|
||||
"description": "Color code for the pointer (e.g., '#8a0000')"
|
||||
},
|
||||
"start": {
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "string",
|
||||
"enum": ["center", "left", "right"],
|
||||
"description": "Starting position of the pointer"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"pattern": "^\\([0-9]+,( )?[0-9]+\\)+$",
|
||||
"description": "Starting position of the pointer"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"x": {
|
||||
"type": "number",
|
||||
"description": "X position"
|
||||
},
|
||||
"y": {
|
||||
"type": "number",
|
||||
"description": "Y position"
|
||||
}
|
||||
},
|
||||
"required": ["x", "y"],
|
||||
"description": "Starting position of the pointer",
|
||||
"additionalProperties": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"length": {
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "string",
|
||||
"enum": ["half", "full"],
|
||||
"description": "Length of the pointer relative to the scale"
|
||||
},
|
||||
{
|
||||
"type": "number",
|
||||
"description": "Length of the pointer relative to the scale"
|
||||
}
|
||||
]
|
||||
},
|
||||
"image":{
|
||||
"type": "string",
|
||||
"description": "Image location for a pointer"
|
||||
}
|
||||
},
|
||||
"required": ["start"],
|
||||
"anyOf": [
|
||||
{
|
||||
"required": [
|
||||
"image"
|
||||
]
|
||||
},
|
||||
{
|
||||
"required": [
|
||||
"color",
|
||||
"length"
|
||||
]
|
||||
}
|
||||
],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"scale": {
|
||||
"type": "number",
|
||||
"minimum": 0.1,
|
||||
"maximum": 2.0,
|
||||
"description": "Scale factor for the speedometer"
|
||||
}
|
||||
},
|
||||
"required": ["background", "start", "end", "pointer", "scale", "maxSpeed", "overflow"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
@@ -9,4 +9,4 @@ pluginManagement {
|
||||
|
||||
include("common")
|
||||
include("fabric")
|
||||
include("forge")
|
||||
include("neoforge")
|
||||