7 Commits

Author SHA1 Message Date
Zacharias
d7dbf65446 Update resourcepack.md
Fixed the spesification of a comented json object from JSON to JSONC
2025-03-26 11:08:20 +01:00
Zacharias
3e282612a3 Update resourcepack.md
Fixed an î to an i
2024-12-20 21:19:55 +01:00
1a59e3dc2a 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
2024-12-18 14:12:47 +01:00
1fc71a34a9 pack.mcmeta:
- Added `supported_formats` to make minecraft show it as compatible for newer versions

ReadMe.txt:
- A file added to optional resource pack root since interested people might check out the optional resource pack

resourcepack.md:
- Added lines to clarify the use of the schema
- Added lines to suggest the use of `supported_formats`
2024-12-11 20:38:10 +01:00
Zacharias
d1e5ef63ee Added a Feature request template 2024-12-11 20:02:23 +01:00
Zacharias
32b6198f71 Removed recomended and latest for forge since it's not planed to be supported 2024-11-05 16:41:52 +01:00
Zacharias
5c95f394a8 Update readme.md 2024-11-05 16:34:16 +01:00
19 changed files with 147 additions and 210 deletions

View 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.

View 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

View File

@@ -1,6 +1,10 @@
{
"pack": {
"pack_format": 34,
"description": "A different speedometer"
"description": "A different speedometer",
"supported_formats": {
"min_inclusive": 34,
"max_inclusive": 57
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -23,12 +23,12 @@ repositories {
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:${rootProject.cloth_config_version}"
modApi "com.terraformersmc:modmenu:11.0.0"
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 }

View File

@@ -3,23 +3,11 @@ 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.ResourcePackActivationType;
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.repository.RepositorySource;
import net.minecraft.server.packs.resources.ResourceManager;
import java.util.HashSet;
import java.util.Set;
import static me.zacharias.speedometer.Speedometer.LOGGER;
import static me.zacharias.speedometer.Speedometer.MOD_ID;
public class SpeedometerFabric implements ModInitializer {
@Override
public void onInitialize() {

View File

@@ -21,9 +21,9 @@
"depends": {
"fabricloader": ">=0.15.11",
"minecraft": ">=1.21",
"architectury": ">=13.0.1"
"architectury": ">=13.0.5"
},
"suggests": {
"cloth-config1": ">=15.0.127"
"cloth-config1": ">=15.0.140"
}
}

View File

@@ -85,25 +85,25 @@
"5.2.1": "Fixed issue #3"
},
"promos": {
"1.20.6-latest": "5.2.1",
"1.20.6-recommended": "5.2.1",
"1.20.6-latest": "5.2",
"1.20.6-recommended": "5.2",
"1.20.5-latest": "5.2.1",
"1.20.5-recommended": "5.2.1",
"1.20.5-latest": "5.2",
"1.20.5-recommended": "5.2",
"1.20.4-latest": "5.2.1",
"1.20.4-recommended": "5.2.1",
"1.20.4-latest": "5.2",
"1.20.4-recommended": "5.2",
"1.20.3-latest": "5.2.1",
"1.20.3-recommended": "5.2.1",
"1.20.3-latest": "5.2",
"1.20.3-recommended": "5.2",
"1.20.2-latest": "5.2.1",
"1.20.2-recommended": "5.2.1",
"1.20.2-latest": "5.2",
"1.20.2-recommended": "5.2",
"1.20.1-latest": "5.2.1",
"1.20.1-recommended": "5.2.1",
"1.20.1-latest": "5.2",
"1.20.1-recommended": "5.2",
"1.20-latest": "5.2.1",
"1.20-recommended": "5.2.1"
"1.20-latest": "5.2",
"1.20-recommended": "5.2"
}
}

View File

@@ -1,19 +1,29 @@
org.gradle.jvmargs=-Xmx8G
minecraft_version=1.21.1
minecraft_version=1.21.4
archives_base_name=speedometer
mod_version=6.2.1
mod_version=6.2.2
maven_group=me.zacharias
architectury_version=13.0.8
# https://modrinth.com/mod/architectury-api/versions
architectury_version=15.0.1
fabric_loader_version=0.16.5
fabric_api_version=0.105.0+1.21.1
# https://modrinth.com/mod/cloth-config/versions
cloth_config_version = 17.0.144
neoforge_version = 21.1.66
# NeoForged Only
# https://neoforged.net/
neoforge_version = 21.4.30-beta
cloth_config_version = 15.0.140
# 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

View File

@@ -2,18 +2,6 @@ package me.zacharias.speedometer.forge;
import com.mojang.datafixers.util.Unit;
import me.zacharias.speedometer.Speedometer;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.AbstractPackResources;
import net.minecraft.server.packs.PackLocationInfo;
import net.minecraft.server.packs.PackResources;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.repository.KnownPack;
import net.minecraft.server.packs.repository.Pack;
import net.minecraft.server.packs.repository.PackSource;
import net.minecraft.server.packs.resources.IoSupplier;
import net.minecraft.server.packs.resources.PreparableReloadListener;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.server.packs.resources.SimplePreparableReloadListener;
import net.minecraft.util.profiling.ProfilerFiller;
@@ -23,19 +11,8 @@ 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.ClientNeoForgeMod;
import net.neoforged.neoforge.client.event.RegisterClientReloadListenersEvent;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.resource.ResourcePackLoader;
import org.jetbrains.annotations.Nullable;
import java.io.InputStream;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import static me.zacharias.speedometer.Speedometer.*;
import org.jetbrains.annotations.NotNull;
@Mod(Speedometer.MOD_ID)
public class SpeedometerNeoForge {
@@ -52,7 +29,7 @@ class EventHandler
{
/**
* Register the reload listener for the speedometers
* This is required since i havent found how to put this in the Architecture Abstraction layer(Common module)
* 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
*/
@@ -60,12 +37,12 @@ class EventHandler
private static void onResourceReload(RegisterClientReloadListenersEvent event) {
event.registerReloadListener(new SimplePreparableReloadListener<Unit>() {
@Override
protected Unit prepare(ResourceManager arg, ProfilerFiller arg2) {
protected @NotNull Unit prepare(@NotNull ResourceManager arg, @NotNull ProfilerFiller arg2) {
return Unit.INSTANCE;
}
@Override
protected void apply(Unit object, ResourceManager resourceManager, ProfilerFiller arg2) {
protected void apply(@NotNull Unit object, @NotNull ResourceManager resourceManager, @NotNull ProfilerFiller arg2) {
Speedometer.loadSpeedometers(resourceManager);
}
});

View File

@@ -82,12 +82,12 @@ Just displaying your speed
[[dependencies.speedometer]]
modId="architectury"
mandatory=true
versionRange="[13.0.1,)"
ordering="NONE"
versionRange="[13.0.5,)"
ordering="BEFORE"
side="CLIENT"
[[dependencies.speedometer]]
modId="cloth_config"
mandatory=false
versionRange="[15.0.127,)"
ordering="NONE"
type="optional"
versionRange="[15.0.140,)"
ordering="BEFORE"
side="CLIENT"

View File

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

View File

@@ -9,6 +9,13 @@ This feature is supported in
## `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
@@ -33,7 +40,7 @@ base
```
## `speedometer.json` example *Standard speedometer.json file*
```
```json
{
"background": "speedometer:meter/speedometer.png",
"start": -45,
@@ -64,7 +71,7 @@ base
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 `ìmage` most be*
- 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.
@@ -78,3 +85,10 @@ base
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