Compare commits
27 Commits
5.0-alpha
...
6.2.4-1.17
| Author | SHA1 | Date | |
|---|---|---|---|
|
b81dd019ea
|
|||
|
4b2a150a30
|
|||
|
bd205b5ae6
|
|||
|
192735d352
|
|||
|
216a498d72
|
|||
|
|
d7dbf65446 | ||
|
|
3e282612a3 | ||
| 1a59e3dc2a | |||
| 1fc71a34a9 | |||
|
|
d1e5ef63ee | ||
|
|
32b6198f71 | ||
|
|
5c95f394a8 | ||
| 38f96cb1e9 | |||
| 95222c1c95 | |||
| f48a4aaf6c | |||
| 1589226f81 | |||
| fefd82f71f | |||
| 3638718f16 | |||
| 9ed808d33d | |||
|
|
614af5b6d6 | ||
| c644671eaf | |||
| b09ffb4639 | |||
| 481993b2e2 | |||
|
|
965a3ea62d | ||
|
|
a36058459f | ||
|
|
962c2f5f2b | ||
| cda526d41d |
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.
|
||||
8
.gitignore
vendored
@@ -114,5 +114,13 @@ 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
|
||||
|
||||
# Gradle files
|
||||
gradlew
|
||||
gradlew.bat
|
||||
gradle/wrapper/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 |
12
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 /*"0.10.0.172"*/"0.10.0.243" apply false
|
||||
}
|
||||
|
||||
architectury {
|
||||
@@ -19,7 +19,8 @@ subprojects {
|
||||
// The following line declares the mojmap mappings, you may use other mappings as well
|
||||
mappings loom.officialMojangMappings()
|
||||
// The following line declares the yarn mappings you may select this one as well.
|
||||
// mappings "net.fabricmc:yarn:@YARN_MAPPINGS@:v2"
|
||||
//mappings "net.fabricmc:yarn:1.17.1+build.65: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 = 16
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
@@ -1,30 +1,27 @@
|
||||
package me.zacharias.speedometer;
|
||||
|
||||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
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.KeyMapping;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraft.network.chat.TextColor;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
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 javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
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(
|
||||
@@ -40,25 +37,45 @@ public class Client {
|
||||
"speedometer.key.category"
|
||||
);
|
||||
|
||||
public static final KeyMapping SPEED_KEY = new KeyMapping(
|
||||
"speedometer.key.speedKey",
|
||||
InputConstants.Type.KEYSYM,
|
||||
InputConstants.KEY_UP,
|
||||
"speedometer.key.category"
|
||||
);
|
||||
|
||||
private static final ArrayList<Double> speeds = new ArrayList<>();
|
||||
private static boolean speedometerVisualDisplayFailed = false;
|
||||
public static BufferedImage img = null;
|
||||
|
||||
|
||||
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") || Platform.isModLoaded("cloth-config2");
|
||||
|
||||
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(
|
||||
new TranslatableComponent("speedometer.error.missing_cloth")
|
||||
.withStyle(style -> style.withColor(ChatFormatting.RED))
|
||||
.append(
|
||||
new TranslatableComponent("speedometer.error.missing_cloth.open_config")
|
||||
.withStyle(style -> style
|
||||
.withColor(ChatFormatting.DARK_RED)
|
||||
.withUnderlined(true)
|
||||
.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, Config.getConfigPath()))))
|
||||
, false);
|
||||
LOGGER.warn(new TranslatableComponent("speedometer.error.missing_cloth").getString());
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER.warn(new TranslatableComponent("speedometer.error.missing_cloth").getString());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -69,49 +86,30 @@ public class Client {
|
||||
}
|
||||
});
|
||||
|
||||
//KeyMappingRegistry.register(SPEED_KEY);
|
||||
ClientTickEvent.CLIENT_POST.register(minecraft -> {
|
||||
if(SPEED_KEY.consumeClick()){
|
||||
if(minecraft.player != null) {
|
||||
minecraft.player.addDeltaMovement(new Vec3(1, 0, 0));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Config.initialize();
|
||||
Config.save();
|
||||
|
||||
ClientGuiEvent.RENDER_HUD.register(Client::render);
|
||||
|
||||
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(PoseStack poseStack, float delta) {
|
||||
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;
|
||||
|
||||
@@ -139,84 +137,50 @@ 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 = getPosImp(poseStack, width, Config.getYPosition(), false);
|
||||
int xPos = getPosImp(poseStack, width, Config.getXPosition(), true);
|
||||
|
||||
if(Config.getVisualSpeedometer() && !speedometerVisualDisplayFailed){
|
||||
int lineHeight = Minecraft.getInstance().font.lineHeight;
|
||||
|
||||
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));
|
||||
g2d.drawString(SpeedTypes.getName(speedType).getString(), img.getWidth()/2-27,img.getHeight()/2+25);
|
||||
|
||||
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);
|
||||
|
||||
int xPos = getPos(graphics, Config.getXPosition(), 0);
|
||||
int yPos = getPos(graphics, Config.getYPosition(), 1);
|
||||
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);
|
||||
Gui.fill(poseStack, 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);
|
||||
int lineHeight = Minecraft.getInstance().font.lineHeight;
|
||||
graphics.drawString(
|
||||
Minecraft.getInstance().font,
|
||||
speedString,
|
||||
getPos(graphics, Config.getXPosition(), 0) - width,
|
||||
getPos(graphics, Config.getYPosition(), 1) - lineHeight,
|
||||
Config.getColor().getColor()
|
||||
);
|
||||
drawString(
|
||||
poseStack,
|
||||
xPos - width,
|
||||
yPos - lineHeight,
|
||||
speedString,
|
||||
Config.getColor().getRGB()
|
||||
);
|
||||
}
|
||||
|
||||
if(Config.isDebug()){
|
||||
@@ -236,22 +200,26 @@ 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") + "\n" +
|
||||
"Pos: ("+xPos+", "+yPos+") \n" +
|
||||
"Width: "+Minecraft.getInstance().getWindow().getGuiScaledWidth() + "\n" +
|
||||
"Height: "+Minecraft.getInstance().getWindow().getGuiScaledHeight();
|
||||
|
||||
Color color = new Color(255, 255, 255);
|
||||
|
||||
int y = 0;
|
||||
for(String s : debugData.split("\n")){
|
||||
drawString(graphics,0, y, s, color.getRGB());
|
||||
drawString(poseStack,0, y, s, color.getRGB());
|
||||
y+=Minecraft.getInstance().font.lineHeight+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void drawString(GuiGraphics graphics, int x, int y, String text, int colorRGB){
|
||||
graphics.drawString(
|
||||
private static void drawString(PoseStack poseStack, int x, int y, String text, int colorRGB){
|
||||
Gui.drawString(
|
||||
poseStack,
|
||||
Minecraft.getInstance().font,
|
||||
text,
|
||||
x,
|
||||
@@ -260,49 +228,81 @@ public class Client {
|
||||
);
|
||||
}
|
||||
|
||||
private static int getPos(GuiGraphics event, String input, int type) {
|
||||
private static int getPosImp(PoseStack poseStack, int width, String input, boolean isXPosition){
|
||||
int width1 = Minecraft.getInstance().getWindow().getGuiScaledWidth();
|
||||
int height1 = Minecraft.getInstance().getWindow().getGuiScaledHeight();
|
||||
|
||||
input = input.trim();
|
||||
input = input
|
||||
.replaceAll("(W+)|(H+)", String.valueOf(isXPosition? width1 : height1))
|
||||
.replaceAll("(w+)|(h+)", String.valueOf(isXPosition? width1/2 : height1/2))
|
||||
.replaceAll("(S+)|(s+)", String.valueOf(width));
|
||||
if((Config.isDebug()) && Config.getCounter() < 2) {
|
||||
//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(DEBUG): {}\n{}\n\n\n", isXPosition, input);
|
||||
Config.addCounter();
|
||||
}
|
||||
return getPos(poseStack, width, input, isXPosition);
|
||||
}
|
||||
|
||||
private static int getPos(PoseStack event, int width, String input, boolean isXPosition) {
|
||||
|
||||
int width1 = Minecraft.getInstance().getWindow().getGuiScaledWidth();
|
||||
int height1 = Minecraft.getInstance().getWindow().getGuiScaledHeight();
|
||||
|
||||
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(width1));
|
||||
else passerPose.add(String.valueOf(height1));
|
||||
}
|
||||
else if(c == 'h' || c == 'w'){
|
||||
if(isXPosition) passerPose.add(String.valueOf(width1 / 2));
|
||||
else passerPose.add(String.valueOf(height1 / 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(passerPose.size()-1).matches("^[0-9]+$")) {
|
||||
passerPose.add(passerPose.remove(passerPose.size()-1) + 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.get(0));
|
||||
}catch (NumberFormatException e){
|
||||
defaultValues(event, type, passerPose);
|
||||
xPos = Integer.parseInt(passerPose.get(0));
|
||||
passerPose.clear();
|
||||
defaultValues(event, isXPosition, passerPose);
|
||||
position = Integer.parseInt(passerPose.get(0));
|
||||
}
|
||||
|
||||
for(int i = 1; i < passerPose.size(); i++){
|
||||
@@ -316,32 +316,35 @@ 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){
|
||||
passerPose.add(String.valueOf(event.guiWidth()));
|
||||
private static void defaultValues(PoseStack event, boolean isXPosition, ArrayList<String> passerPose) {
|
||||
if(isXPosition)
|
||||
{
|
||||
passerPose.add(String.valueOf(Minecraft.getInstance().getWindow().getGuiScaledWidth()));
|
||||
passerPose.add("-");
|
||||
passerPose.add("3");
|
||||
}else if(type == 1){
|
||||
passerPose.add(String.valueOf(event.guiHeight()));
|
||||
}
|
||||
else
|
||||
{
|
||||
passerPose.add(String.valueOf(Minecraft.getInstance().getWindow().getGuiScaledHeight()));
|
||||
passerPose.add("-");
|
||||
passerPose.add("3");
|
||||
}
|
||||
|
||||
@@ -1,57 +1,90 @@
|
||||
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;
|
||||
private static JSONObject config;
|
||||
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 config = new File(Platform.getConfigFolder().toString()+"/"+MOD_ID+"/config.json");
|
||||
if(!config.exists()){
|
||||
if(config != null) throw new RuntimeException("Already Initialized");
|
||||
configPath = Platform.getConfigFolder().toString()+"/"+MOD_ID+"/config.json";
|
||||
File configFile = new File(configPath);
|
||||
if(!configFile.exists()){
|
||||
try {
|
||||
config.getParentFile().mkdir();
|
||||
config.createNewFile();
|
||||
configFile.getParentFile().mkdir();
|
||||
configFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Config = new JSONObject();
|
||||
config = new JSONObject();
|
||||
|
||||
defualt();
|
||||
defaultValues();
|
||||
}else {
|
||||
try {
|
||||
BufferedReader in = new BufferedReader(new FileReader(config));
|
||||
BufferedReader in = new BufferedReader(new FileReader(configFile));
|
||||
String tmp;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
while((tmp = in.readLine()) != null){
|
||||
builder.append(tmp);
|
||||
}
|
||||
Config = new JSONObject(builder.toString());
|
||||
if(Config.has("version")){
|
||||
if(Config.getFloat("version")!=configVersion){
|
||||
if(Config.getFloat("version") > configVersion){
|
||||
defualt();
|
||||
|
||||
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){
|
||||
LOGGER.warn("Config version is too new, resting");
|
||||
defaultValues();
|
||||
|
||||
save();
|
||||
}else if(Config.getFloat("version") < configVersion){
|
||||
Config = new JSONObject();
|
||||
}else if(config.getFloat("version") < configVersion){
|
||||
config = new JSONObject();
|
||||
LOGGER.warn("Config version is outdated, resting");
|
||||
|
||||
defualt();
|
||||
defaultValues();
|
||||
save();
|
||||
}
|
||||
}
|
||||
}else{
|
||||
Config = new JSONObject();
|
||||
defualt();
|
||||
config = new JSONObject();
|
||||
defaultValues();
|
||||
save();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@@ -60,59 +93,58 @@ public class Config {
|
||||
}
|
||||
}
|
||||
|
||||
private static void defualt() {
|
||||
if(!Config.has("speed")) {
|
||||
Config.put("speed", SpeedTypes.BlockPS);
|
||||
private static void defaultValues() {
|
||||
if(!config.has("speed")) {
|
||||
config.put("speed", SpeedTypes.BlockPS);
|
||||
}
|
||||
if(!Config.has("useKnot")) {
|
||||
Config.put("useKnot", false);
|
||||
if(!config.has("useKnot")) {
|
||||
config.put("useKnot", false);
|
||||
}
|
||||
if(!Config.has("color")) {
|
||||
Config.put("color", new JSONObject()
|
||||
if(!config.has("color")) {
|
||||
config.put("color", new JSONObject()
|
||||
.put("r", 16)
|
||||
.put("g", 146)
|
||||
.put("b", 158)
|
||||
);
|
||||
}
|
||||
if(!Config.has("visualSpeedometer")) {
|
||||
Config.put("visualSpeedometer", false);
|
||||
if(!config.has("visualSpeedometer")) {
|
||||
config.put("visualSpeedometer", false);
|
||||
}
|
||||
|
||||
/*if(!Config.has("xPositionVisual")) {
|
||||
Config.put("xPositionVisual", "W-3");
|
||||
if(!config.has("xPosition")) {
|
||||
config.put("xPosition", "W-3");
|
||||
}
|
||||
if(!Config.has("yPositionVisual")) {
|
||||
Config.put("yPositionVisual", "H-3");
|
||||
}
|
||||
if(!Config.has("xPositionText")) {
|
||||
Config.put("xPositionText", "W-3");
|
||||
}
|
||||
if(!Config.has("yPositionText")) {
|
||||
Config.put("yPositionText", "H-3");
|
||||
}*/
|
||||
|
||||
if(!Config.has("xPosition")) {
|
||||
Config.put("xPosition", "W-3");
|
||||
}
|
||||
if(!Config.has("yPosition")) {
|
||||
Config.put("yPosition", "H-3");
|
||||
if(!config.has("yPosition")) {
|
||||
config.put("yPosition", "H-3");
|
||||
}
|
||||
|
||||
if(!Config.has("debug")) {
|
||||
Config.put("debug", false);
|
||||
if(!config.has("debug")) {
|
||||
config.put("debug", false);
|
||||
}
|
||||
|
||||
if(!Config.has("imagSize")) {
|
||||
Config.put("imageSize", 19);
|
||||
if(!config.has("imagSize")) {
|
||||
config.put("imageSize", 19);
|
||||
}
|
||||
|
||||
if(!Config.has("version")) {
|
||||
Config.put("version", configVersion);
|
||||
if(!config.has("version")) {
|
||||
config.put("version", configVersion);
|
||||
}
|
||||
|
||||
if(!config.has("showVisualSpeedType")){
|
||||
config.put("showVisualSpeedType", false);
|
||||
}
|
||||
|
||||
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();
|
||||
@@ -123,7 +155,7 @@ public class Config {
|
||||
}
|
||||
try {
|
||||
BufferedWriter out = new BufferedWriter(new FileWriter(config));
|
||||
out.write(Config.toString(4));
|
||||
out.write(Config.config.toString(4));
|
||||
out.flush();
|
||||
out.close();
|
||||
}catch (Exception e){
|
||||
@@ -131,48 +163,56 @@ public class Config {
|
||||
}
|
||||
counter=0;
|
||||
}
|
||||
|
||||
|
||||
//region Config Getters
|
||||
public static SpeedTypes getSpeedType(){
|
||||
if(Config.has("speed")){
|
||||
return Config.getEnum(SpeedTypes.class, "speed");
|
||||
if(config.has("speed")){
|
||||
return config.getEnum(SpeedTypes.class, "speed");
|
||||
}else{
|
||||
return SpeedTypes.BlockPS;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean getUseKnot() {
|
||||
if(Config.has("useKnot")){
|
||||
return Config.getBoolean("useKnot");
|
||||
if(config.has("useKnot")){
|
||||
return config.getBoolean("useKnot");
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static Color getColor(){
|
||||
if(Config.has("color")){
|
||||
JSONObject color = Config.getJSONObject("color");
|
||||
return Color.ofRGB(
|
||||
if(config.has("color")){
|
||||
JSONObject color = config.getJSONObject("color");
|
||||
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");
|
||||
if(config.has("debug")){
|
||||
return config.getBoolean("debug");
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean getVisualSpeedometer(){
|
||||
if(Config.has("visualSpeedometer")){
|
||||
return Config.getBoolean("visualSpeedometer");
|
||||
}else {
|
||||
if(config.has("visualSpeedometer")){
|
||||
return config.getBoolean("visualSpeedometer");
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -184,111 +224,114 @@ public class Config {
|
||||
counter++;
|
||||
}
|
||||
|
||||
/*public static String getXPositionVisual(){
|
||||
if(Config.has("xPositionVisual")) {
|
||||
return Config.getString("xPositionVisual");
|
||||
}else{
|
||||
return "W-23";
|
||||
}
|
||||
}
|
||||
|
||||
public static String getYPositionVisual() {
|
||||
if (Config.has("yPositionVisual")) {
|
||||
return Config.getString("yPositionVisual");
|
||||
} else {
|
||||
return "H-23";
|
||||
}
|
||||
}
|
||||
public static String getXPositionText(){
|
||||
if(Config.has("xPositionText")) {
|
||||
return Config.getString("xPositionText");
|
||||
}else{
|
||||
return "W-70";
|
||||
}
|
||||
}
|
||||
|
||||
public static String getYPositionText(){
|
||||
if(Config.has("yPositionText")) {
|
||||
return Config.getString("yPositionText");
|
||||
}else{
|
||||
return "H-15";
|
||||
}
|
||||
}*/
|
||||
|
||||
public static String getYPosition(){
|
||||
if(Config.has("yPosition")) {
|
||||
return Config.getString("yPosition");
|
||||
if(config.has("yPosition")) {
|
||||
return config.getString("yPosition");
|
||||
}else{
|
||||
return "H-3";
|
||||
}
|
||||
}
|
||||
|
||||
public static String getXPosition(){
|
||||
if(Config.has("xPosition")) {
|
||||
return Config.getString("xPosition");
|
||||
if(config.has("xPosition")) {
|
||||
return config.getString("xPosition");
|
||||
}else{
|
||||
return "W-3";
|
||||
}
|
||||
}
|
||||
|
||||
public static int getImageSize(){
|
||||
if(Config.has("imageSize")){
|
||||
return Config.getInt("imageSize");
|
||||
if(config.has("imageSize")){
|
||||
return config.getInt("imageSize");
|
||||
}else {
|
||||
return 19;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setColor(Color color){
|
||||
Config.put("color", new JSONObject()
|
||||
.put("r", color.getRed())
|
||||
.put("g", color.getGreen())
|
||||
.put("b", color.getBlue())
|
||||
public static boolean getShowSpeedType(){
|
||||
if(config.has("getShowSpeedType")){
|
||||
return config.getBoolean("showSpeedType");
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getConfigPath()
|
||||
{
|
||||
return configPath;
|
||||
}
|
||||
|
||||
public static BufferedImage getSpeedometer() {
|
||||
return speedometer;
|
||||
}
|
||||
|
||||
public static boolean isDisableVisualSpeedometer() {
|
||||
return disableVisualSpeedometer;
|
||||
}
|
||||
|
||||
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", r)
|
||||
.put("g", g)
|
||||
.put("b", b)
|
||||
);
|
||||
}
|
||||
|
||||
public static void setUseKnot(boolean useKnot){
|
||||
Config.put("useKnot", useKnot);
|
||||
config.put("useKnot", useKnot);
|
||||
}
|
||||
|
||||
public static void setSpeedType(SpeedTypes speedType) {
|
||||
Config.put("speed", speedType);
|
||||
config.put("speed", speedType);
|
||||
}
|
||||
|
||||
public static void setVisualSpeedometer(boolean visualSpeedometer){
|
||||
Config.put("visualSpeedometer", visualSpeedometer);
|
||||
config.put("visualSpeedometer", visualSpeedometer);
|
||||
}
|
||||
|
||||
/*
|
||||
public static void setXPositionVisual(String xPositionVisual){
|
||||
Config.put("xPositionVisual", xPositionVisual);
|
||||
}
|
||||
|
||||
public static void setYPositionVisual(String yPositionVisual){
|
||||
Config.put("yPositionVisual", yPositionVisual);
|
||||
}
|
||||
|
||||
public static void setXPositionText(String xPositionText){
|
||||
Config.put("xPositionText", xPositionText);
|
||||
}
|
||||
|
||||
public static void setYPositionText(String yPositionText){
|
||||
Config.put("yPositionText", yPositionText);
|
||||
}*/
|
||||
|
||||
public static void setXPosition(String xPosition){
|
||||
Config.put("xPosition", xPosition);
|
||||
config.put("xPosition", xPosition);
|
||||
}
|
||||
|
||||
public static void setYPosition(String yPosition){
|
||||
Config.put("yPosition", yPosition);
|
||||
config.put("yPosition", yPosition);
|
||||
}
|
||||
|
||||
public static void setDebug(boolean debug){
|
||||
Config.put("debug", debug);
|
||||
config.put("debug", debug);
|
||||
}
|
||||
|
||||
public static void setImageSize(int imageSize){
|
||||
Config.put("imageSize", imageSize);
|
||||
config.put("imageSize", imageSize);
|
||||
}
|
||||
|
||||
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,10 +1,8 @@
|
||||
package me.zacharias.speedometer;
|
||||
|
||||
import me.shedaniel.clothconfig2.api.ConfigBuilder;
|
||||
import me.shedaniel.clothconfig2.api.ConfigCategory;
|
||||
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
|
||||
import me.shedaniel.clothconfig2.api.*;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -12,32 +10,34 @@ public class ConfigMenu {
|
||||
public static ConfigBuilder getConfig(Screen parent) {
|
||||
ConfigBuilder builder = ConfigBuilder.create()
|
||||
.setParentScreen(parent)
|
||||
.setTitle(Component.translatable("speedometer.config.name"));
|
||||
.setTitle(new TranslatableComponent("speedometer.config.name"));
|
||||
|
||||
ConfigCategory category = builder.getOrCreateCategory(Component.translatable("speedometer.config.category.name"));
|
||||
ConfigCategory category = builder.getOrCreateCategory(new TranslatableComponent("speedometer.config.category.name"));
|
||||
|
||||
ConfigEntryBuilder entryBuilder = builder.entryBuilder();
|
||||
|
||||
category.addEntry(entryBuilder.startEnumSelector(Component.translatable("speedometer.config.speed"), SpeedTypes.class, me.zacharias.speedometer.Config.getSpeedType())
|
||||
category.addEntry(entryBuilder.startEnumSelector(new TranslatableComponent("speedometer.config.speed"), SpeedTypes.class, me.zacharias.speedometer.Config.getSpeedType())
|
||||
.setEnumNameProvider(SpeedTypes::getName)
|
||||
.setSaveConsumer(me.zacharias.speedometer.Config::setSpeedType)
|
||||
//.setDefaultValue(SpeedTypes.BlockPS)
|
||||
.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(new TranslatableComponent("speedometer.config.color"), me.zacharias.speedometer.Config.getColorRGB())
|
||||
.setSaveConsumer2(color -> Config.setColor(color.getRed(), color.getGreen(), color.getBlue()))
|
||||
.build()
|
||||
);
|
||||
|
||||
category.addEntry(entryBuilder.startBooleanToggle(Component.translatable("speedometer.config.knot"), me.zacharias.speedometer.Config.getUseKnot())
|
||||
category.addEntry(entryBuilder.startBooleanToggle(new TranslatableComponent("speedometer.config.knot"), me.zacharias.speedometer.Config.getUseKnot())
|
||||
.setSaveConsumer(me.zacharias.speedometer.Config::setUseKnot)
|
||||
.setYesNoTextSupplier(useKnot -> Component.translatable("speedometer.useKnot."+useKnot))
|
||||
.setYesNoTextSupplier(useKnot -> new TranslatableComponent("speedometer.useKnot."+useKnot))
|
||||
.build()
|
||||
);
|
||||
|
||||
category.addEntry(entryBuilder.startBooleanToggle(Component.translatable("speedometer.config.visualSpeedometer"), me.zacharias.speedometer.Config.getVisualSpeedometer())
|
||||
category.addEntry(entryBuilder.startBooleanToggle(new TranslatableComponent("speedometer.config.visualSpeedometer"), me.zacharias.speedometer.Config.getVisualSpeedometer())
|
||||
.setSaveConsumer(me.zacharias.speedometer.Config::setVisualSpeedometer)
|
||||
.setYesNoTextSupplier((visualSpeedometer -> Component.translatable("speedometer.visualSpeedometer."+visualSpeedometer)))
|
||||
.setYesNoTextSupplier((visualSpeedometer -> new TranslatableComponent("speedometer.visualSpeedometer."+visualSpeedometer)))
|
||||
//.setRequirement(Requirement.isFalse(Config::isDisableVisualSpeedometer))
|
||||
.build()
|
||||
);
|
||||
|
||||
@@ -46,124 +46,80 @@ public class ConfigMenu {
|
||||
String xRegex = "W*w*S*s*\\+*-*\\**/*[0-9]*";
|
||||
String yRegex = "H*h*S*s*\\+*-*\\**/*[0-9]*";
|
||||
|
||||
// Text Placement
|
||||
/*
|
||||
category.addEntry(entryBuilder.startStringDropdownMenu(Component.translatable("speedometer.config.xPosition.text"), Config.getXPositionText())
|
||||
.setSaveConsumer(Config::setXPositionText)
|
||||
.setErrorSupplier(xPosition -> {
|
||||
if(xPosition.matches(xRegex)){
|
||||
return Optional.empty();
|
||||
}else{
|
||||
return Optional.of(Component.translatable("speedometer.invalid"));
|
||||
}
|
||||
})
|
||||
.setTooltip(
|
||||
Component.translatable("speedometer.config.tooltip.xPosition.line1"),
|
||||
Component.translatable("speedometer.config.tooltip.xPosition.line2"),
|
||||
Component.translatable("speedometer.config.tooltip.xPosition.line3")
|
||||
)
|
||||
.build()
|
||||
);
|
||||
|
||||
category.addEntry(entryBuilder.startStringDropdownMenu(Component.translatable("speedometer.config.yPosition.text"), Config.getYPositionText())
|
||||
.setSaveConsumer(Config::setYPositionText)
|
||||
.setErrorSupplier(yPosition -> {
|
||||
if(yPosition.matches(yRegex)){
|
||||
return Optional.empty();
|
||||
}else{
|
||||
return Optional.of(Component.translatable("speedometer.invalid"));
|
||||
}
|
||||
})
|
||||
.setTooltip(
|
||||
Component.translatable("speedometer.config.tooltip.yPosition.line1"),
|
||||
Component.translatable("speedometer.config.tooltip.yPosition.line2"),
|
||||
Component.translatable("speedometer.config.tooltip.yPosition.line3")
|
||||
)
|
||||
.build()
|
||||
);
|
||||
|
||||
// Visual location
|
||||
|
||||
category.addEntry(entryBuilder.startStringDropdownMenu(Component.translatable("speedometer.config.xPosition.visual"), Config.getXPositionVisual())
|
||||
.setSaveConsumer(Config::setXPositionVisual)
|
||||
.setErrorSupplier(xPosition -> {
|
||||
if(xPosition.matches(xRegex)){
|
||||
return Optional.empty();
|
||||
}else{
|
||||
return Optional.of(Component.translatable("speedometer.invalid"));
|
||||
}
|
||||
})
|
||||
.setTooltip(
|
||||
Component.translatable("speedometer.config.tooltip.xPosition.line1"),
|
||||
Component.translatable("speedometer.config.tooltip.xPosition.line2"),
|
||||
Component.translatable("speedometer.config.tooltip.xPosition.line3")
|
||||
)
|
||||
.build()
|
||||
);
|
||||
|
||||
|
||||
category.addEntry(entryBuilder.startStringDropdownMenu(Component.translatable("speedometer.config.yPosition.visual"), Config.getYPositionVisual())
|
||||
.setSaveConsumer(Config::setYPositionVisual)
|
||||
.setErrorSupplier(yPosition -> {
|
||||
if(yPosition.matches(yRegex)){
|
||||
return Optional.empty();
|
||||
}else{
|
||||
return Optional.of(Component.translatable("speedometer.invalid"));
|
||||
}
|
||||
})
|
||||
.setTooltip(
|
||||
Component.translatable("speedometer.config.tooltip.yPosition.line1"),
|
||||
Component.translatable("speedometer.config.tooltip.yPosition.line2"),
|
||||
Component.translatable("speedometer.config.tooltip.yPosition.line3")
|
||||
)
|
||||
.build()
|
||||
);*/
|
||||
|
||||
category.addEntry(entryBuilder.startStringDropdownMenu(Component.translatable("speedometer.config.xPosition"), Config.getXPosition())
|
||||
category.addEntry(entryBuilder.startStringDropdownMenu(new TranslatableComponent("speedometer.config.xPosition"), Config.getXPosition())
|
||||
.setSaveConsumer(Config::setXPosition)
|
||||
.setErrorSupplier(xPosition -> {
|
||||
if(xPosition.matches(xRegex)){
|
||||
return Optional.empty();
|
||||
}else{
|
||||
return Optional.of(Component.translatable("speedometer.invalid"));
|
||||
return Optional.of(new TranslatableComponent("speedometer.invalid"));
|
||||
}
|
||||
})
|
||||
.setTooltip(
|
||||
Component.translatable("speedometer.config.tooltip.xPosition.line1"),
|
||||
Component.translatable("speedometer.config.tooltip.xPosition.line2")
|
||||
new TranslatableComponent("speedometer.config.tooltip.xPosition.line1"),
|
||||
new TranslatableComponent("speedometer.config.tooltip.xPosition.line2"),
|
||||
new TranslatableComponent("speedometer.config.tooltip.xPosition.line3")
|
||||
)
|
||||
.build()
|
||||
);
|
||||
|
||||
|
||||
category.addEntry(entryBuilder.startStringDropdownMenu(Component.translatable("speedometer.config.yPosition"), Config.getYPosition())
|
||||
category.addEntry(entryBuilder.startStringDropdownMenu(new TranslatableComponent("speedometer.config.yPosition"), Config.getYPosition())
|
||||
.setSaveConsumer(Config::setYPosition)
|
||||
.setErrorSupplier(yPosition -> {
|
||||
if(yPosition.matches(yRegex)){
|
||||
return Optional.empty();
|
||||
}else{
|
||||
return Optional.of(Component.translatable("speedometer.invalid"));
|
||||
return Optional.of(new TranslatableComponent("speedometer.invalid"));
|
||||
}
|
||||
})
|
||||
.setTooltip(
|
||||
Component.translatable("speedometer.config.tooltip.yPosition.line1"),
|
||||
Component.translatable("speedometer.config.tooltip.yPosition.line2")
|
||||
new TranslatableComponent("speedometer.config.tooltip.yPosition.line1"),
|
||||
new TranslatableComponent("speedometer.config.tooltip.yPosition.line2"),
|
||||
new TranslatableComponent("speedometer.config.tooltip.yPosition.line3")
|
||||
)
|
||||
.build()
|
||||
);
|
||||
|
||||
// Size of visual image
|
||||
|
||||
category.addEntry(entryBuilder.startIntField(Component.translatable("speedometer.config.imageSize"), Config.getImageSize())
|
||||
category.addEntry(entryBuilder.startIntField(new TranslatableComponent("speedometer.config.imageSize"), Config.getImageSize())
|
||||
.setSaveConsumer(Config::setImageSize)
|
||||
.setTooltip(Component.translatable("speedometer.config.tooltip.imageSize"))
|
||||
.setTooltip(new TranslatableComponent("speedometer.config.tooltip.imageSize"))
|
||||
.setErrorSupplier(size -> {
|
||||
if(size > 300 || size < 10)
|
||||
{
|
||||
return Optional.of(new TranslatableComponent("speedometer.config.error.size_outofbounds"));
|
||||
}
|
||||
else {
|
||||
return Optional.empty();
|
||||
}
|
||||
})
|
||||
.build()
|
||||
);
|
||||
|
||||
category.addEntry(entryBuilder.startBooleanToggle(Component.translatable("speedometer.config.debug"),Config.isDebug())
|
||||
// Show visual speed type
|
||||
|
||||
category.addEntry(entryBuilder.startBooleanToggle(new TranslatableComponent("speedometer.config.showSpeedType"), Config.getShowSpeedType())
|
||||
.setSaveConsumer(Config::setShowSpeedType)
|
||||
.setYesNoTextSupplier(showSpeedType -> new TranslatableComponent("speedometer."+(showSpeedType?"show":"hide")))
|
||||
.setTooltip(new TranslatableComponent("speedometer.config.tooltip.showSpeedType.line1"))
|
||||
.build()
|
||||
);
|
||||
|
||||
category.addEntry(entryBuilder.startBooleanToggle(new TranslatableComponent("speedometer.config.override_color"), Config.isOverrideColor())
|
||||
.setSaveConsumer(Config::setOverrideColor)
|
||||
.setTooltip(
|
||||
new TranslatableComponent("speedometer.config.tooltip.override_color.line1"),
|
||||
new TranslatableComponent("speedometer.config.tooltip.override_color.line2")
|
||||
)
|
||||
.build()
|
||||
);
|
||||
|
||||
category.addEntry(entryBuilder.startBooleanToggle(new TranslatableComponent("speedometer.config.debug"),Config.isDebug())
|
||||
.setSaveConsumer(Config::setDebug)
|
||||
.setYesNoTextSupplier(isDebug -> Component.translatable("speedometer.debug."+isDebug))
|
||||
.setTooltip(Component.translatable("speedometer.config.tooltip.debug"))
|
||||
.setYesNoTextSupplier(isDebug -> new TranslatableComponent("speedometer.debug."+isDebug))
|
||||
.setTooltip(new TranslatableComponent("speedometer.config.tooltip.debug"))
|
||||
.build()
|
||||
);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,18 @@
|
||||
package me.zacharias.speedometer;
|
||||
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
|
||||
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) {
|
||||
return Component.translatable("speedometer.speed." + switch (speedType) {
|
||||
return new TranslatableComponent("speedometer.speed." + switch (speedType) {
|
||||
case MPH -> "mph";
|
||||
case MPS -> "mps";
|
||||
case KMPH -> "kmph";
|
||||
@@ -25,11 +20,7 @@ public enum SpeedTypes {
|
||||
case KNOT -> "knot";
|
||||
});
|
||||
}else {
|
||||
return Component.translatable("speedometer.speed.error");
|
||||
return new TranslatableComponent("speedometer.speed.error");
|
||||
}
|
||||
}
|
||||
|
||||
public int gatMaxVisual() {
|
||||
return maxVisual;
|
||||
}
|
||||
}
|
||||
@@ -3,43 +3,97 @@ 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.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
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");
|
||||
|
||||
|
||||
if(Platform.getEnvironment() != Env.CLIENT) {
|
||||
LOGGER.error("You're running speedometer on somthing other then a client, this is not supported");
|
||||
LOGGER.error("You're running speedometer on something other then a client, this is not supported");
|
||||
try {
|
||||
for (File f : Objects.requireNonNull(Platform.getModsFolder().toFile().listFiles())) {
|
||||
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) throws IOException {
|
||||
//List< Resource > resource = Minecraft.getInstance().getResourceManager().getResourceStack(ResourceLocation.fromNamespaceAndPath(MOD_ID, "models/speedometer.json"));
|
||||
Optional<Resource> resource = Optional.of(resourceManager.getResource(new ResourceLocation(MOD_ID, "models/speedometer.json")));
|
||||
|
||||
if(resource.isEmpty())
|
||||
{
|
||||
Config.setDisableVisualSpeedometer(true);
|
||||
LOGGER.error("Failed to load speedometer config");
|
||||
return;
|
||||
}
|
||||
|
||||
try(BufferedReader stream = new BufferedReader(new InputStreamReader(resource.get().getInputStream()))/*.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().getSourceName(), 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().getSourceName());
|
||||
}
|
||||
|
||||
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 com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
//import org.joml.Vector2i;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.Resource;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
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, CommandSyntaxException {
|
||||
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 = Optional.of(resourceManager.getResource(ResourceLocation.read(new StringReader(background))));//.getOrThrow(s -> new MissingPropertyException("background")));
|
||||
if(speedometerIcon.isEmpty()) throw new MissingPropertyException("background");
|
||||
|
||||
InputStream stream = speedometerIcon.get().getInputStream();
|
||||
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, CommandSyntaxException {
|
||||
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 = Optional.of(resourceManager.getResource(ResourceLocation.read(new StringReader(imageResourceLocation))));//.getOrThrow(s -> new MissingPropertyException("pointer/image")));
|
||||
if(image.isEmpty()) throw new MissingPropertyException("pointer/image");
|
||||
|
||||
InputStream stream = image.get().getInputStream();//.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");
|
||||
}
|
||||
}
|
||||
}
|
||||
17
common/src/main/java/me/zacharias/speedometer/Vector2i.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package me.zacharias.speedometer;
|
||||
|
||||
public class Vector2i {
|
||||
int x, y;
|
||||
public Vector2i(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,9 @@
|
||||
"speedometer.config.yPosition": "Y Position for Meters",
|
||||
"speedometer.config.debug": "Debug",
|
||||
"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",
|
||||
@@ -27,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",
|
||||
@@ -38,6 +41,9 @@
|
||||
"speedometer.debug.true": "\u00A74Yes",
|
||||
"speedometer.debug.false": "\u00A74No",
|
||||
|
||||
"speedometer.show": "Show",
|
||||
"speedometer.hide": "Hide",
|
||||
|
||||
"speedometer.config.tooltip.xPosition.line1": "W = the width of the screen",
|
||||
"speedometer.config.tooltip.xPosition.line2": "w = half the width of the screen",
|
||||
"speedometer.config.tooltip.xPosition.line3": "s = the width of the text or image",
|
||||
@@ -50,5 +56,20 @@
|
||||
|
||||
"speedometer.config.tooltip.imageSize": "Size of the image. This sets both the height and width",
|
||||
|
||||
"speedometer.invalid": "Invalid String"
|
||||
"speedometer.config.tooltip.showVisualSpeedType.line1": "This setting doesn't work fully.",
|
||||
"speedometer.config.tooltip.showVisualSpeedType.line2": "I(the developer) discourages the use of this setting since it doesn't work on smaller sises and the fps breaks at larger",
|
||||
|
||||
"speedometer.config.tooltip.showSpeedType.line1": "This setting shows the speed type above the visual meter which is better then within the visual meter",
|
||||
|
||||
"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, ",
|
||||
"speedometer.error.missing_cloth.open_config": "Open Config",
|
||||
|
||||
"resourcepack.speedometer.quarter_circle_speedometer": "Quarter circle Speedometer"
|
||||
}
|
||||
75
common/src/main/resources/assets/speedometer/lang/sv_se.json
Normal file
@@ -0,0 +1,75 @@
|
||||
{
|
||||
"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, ",
|
||||
"speedometer.error.missing_cloth.open_config": "Öppna Config",
|
||||
|
||||
"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}+1.17"
|
||||
// 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 }
|
||||
@@ -47,7 +49,7 @@ shadowJar {
|
||||
}
|
||||
|
||||
remapJar {
|
||||
inputFile.set shadowJar.archiveFile
|
||||
input/*File*/.set shadowJar.archiveFile
|
||||
dependsOn shadowJar
|
||||
archiveClassifier.set(null)
|
||||
}
|
||||
|
||||
@@ -2,10 +2,41 @@ 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;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
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) {
|
||||
try {
|
||||
Speedometer.loadSpeedometers(resourceManager);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getFabricId() {
|
||||
return new ResourceLocation("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.12.12",
|
||||
"minecraft": ">=1.17 <1.19",
|
||||
"architectury": ">=2.10.10"
|
||||
},
|
||||
"suggests": {
|
||||
"cloth-config1": ">=5.3.63"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"pack": {
|
||||
"pack_format": 15,
|
||||
"pack_format": 34,
|
||||
"description": "speedometer resources"
|
||||
}
|
||||
}
|
||||
@@ -11,22 +11,40 @@ repositories{
|
||||
}
|
||||
|
||||
configurations {
|
||||
common
|
||||
/*common
|
||||
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*/
|
||||
common {
|
||||
canBeResolved = true
|
||||
canBeConsumed = false
|
||||
}
|
||||
compileClasspath.extendsFrom common
|
||||
runtimeClasspath.extendsFrom common
|
||||
developmentForge.extendsFrom common
|
||||
|
||||
// Files in this configuration will be bundled into your mod using the Shadow plugin.
|
||||
// Don't use the `shadow` configuration from the plugin itself as it's meant for excluding files.
|
||||
shadowBundle {
|
||||
canBeResolved = true
|
||||
canBeConsumed = false
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
forge "net.minecraftforge:forge:${rootProject.forge_version}"
|
||||
forge "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
|
||||
// Remove the next line if you don't want to depend on the API
|
||||
modApi "dev.architectury:architectury-forge:${rootProject.architectury_version}"
|
||||
modApi "dev.architectury:architectury-forge:${architectury_version}"
|
||||
|
||||
modApi "me.shedaniel.cloth:cloth-config-forge:11.1.106"
|
||||
modApi "me.shedaniel.cloth:cloth-config-forge:${cloth_config_version}"
|
||||
|
||||
common(project(path: ":common", configuration: "namedElements")) { transitive false }
|
||||
shadowCommon(project(path: ":common", configuration: "transformProductionForge")) { transitive = false }
|
||||
common(project(path: ':common', configuration: 'namedElements')) { transitive false }
|
||||
shadowBundle project(path: ':common', configuration: 'transformProductionNeoForge')
|
||||
|
||||
//implementation 'org.json:json:20230227'
|
||||
//include 'org.json:json:20230227'
|
||||
//forgeRuntimeLibrary 'org.json:json:20230227'
|
||||
}
|
||||
|
||||
processResources {
|
||||
@@ -41,12 +59,12 @@ shadowJar {
|
||||
exclude "fabric.mod.json"
|
||||
|
||||
|
||||
configurations = [project.configurations.shadowCommon]
|
||||
archiveClassifier.set("dev-shadow")
|
||||
configurations = [project.configurations.shadowBundle]
|
||||
archiveClassifier = 'dev-shadow'
|
||||
}
|
||||
|
||||
remapJar {
|
||||
inputFile.set shadowJar.archiveFile
|
||||
input.set shadowJar.archiveFile
|
||||
dependsOn shadowJar
|
||||
archiveClassifier.set(null)
|
||||
}
|
||||
|
||||
@@ -1,15 +1,51 @@
|
||||
package me.zacharias.speedometer.forge;
|
||||
|
||||
import com.mojang.datafixers.util.Unit;
|
||||
import dev.architectury.platform.forge.EventBuses;
|
||||
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.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.RegisterClientReloadListenersEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@Mod(Speedometer.MOD_ID)
|
||||
import java.io.IOException;
|
||||
|
||||
import static me.zacharias.speedometer.Speedometer.MOD_ID;
|
||||
|
||||
@Mod(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();
|
||||
}
|
||||
public SpeedometerForge() {
|
||||
// Submit our event bus to let architectury register our content on the right time
|
||||
EventBuses.registerModEventBus(MOD_ID, FMLJavaModLoadingContext.get().getModEventBus());
|
||||
Speedometer.init();
|
||||
}
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber(modid = MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
|
||||
class EventHandler
|
||||
{
|
||||
@SubscribeEvent
|
||||
public 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) {
|
||||
try {
|
||||
Speedometer.loadSpeedometers(resourceManager);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
# 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="[37,)" #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"
|
||||
@@ -23,22 +23,22 @@ version="${version}" #mandatory
|
||||
# A display name for the mod
|
||||
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="http://myurl.me/" #optional
|
||||
# A URL for the "homepage" for this mod, displayed in the mod UI
|
||||
displayURL="https://modrinth.com/mod/speedometer" #optional
|
||||
#displayURL="http://example.com/" #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.
|
||||
# IGNORE_ALL_VERSION means that your mod will not cause a red X if it's present on the client or the server. This is a special case and should only be used if your mod has no server component.
|
||||
# NONE means that no display test is set on your mod. You need to do this yourself, see IExtensionPoint.DisplayTest for more information. You can define any scheme you wish with this value.
|
||||
# IMPORTANT NOTE: this is NOT an instruction as to which environments (CLIENT or DEDICATED SERVER) your mod loads on. Your mod should load (and maybe do nothing!) whereever it finds itself.
|
||||
displayTest="IGNORE_ALL_VERSION" # MATCH_VERSION is the default if nothing is specified (#optional)
|
||||
#displayTest="MATCH_VERSION" # MATCH_VERSION is the default if nothing is specified (#optional)
|
||||
|
||||
# The description text for the mod (multi line!) (#mandatory)
|
||||
description='''
|
||||
@@ -46,33 +46,34 @@ just displaying your speed
|
||||
'''
|
||||
# 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
|
||||
# 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
|
||||
# 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"
|
||||
# the modid of the dependency
|
||||
modId="forge" #mandatory
|
||||
# Does this dependency have to exist - if not, ordering below must be specified
|
||||
mandatory=true #mandatory
|
||||
# The version range of the dependency
|
||||
versionRange="[37,)" #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
|
||||
[[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)"
|
||||
ordering="NONE"
|
||||
side="BOTH"
|
||||
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.17,1.19)"
|
||||
ordering="NONE"
|
||||
side="BOTH"
|
||||
[[dependencies.speedometer]]
|
||||
modId="architectury"
|
||||
mandatory=true
|
||||
versionRange="[9.1.10,)"
|
||||
ordering="NONE"
|
||||
side="CLIENT"
|
||||
modId="architectury"
|
||||
mandatory=true
|
||||
versionRange="[2.10.10,)"
|
||||
ordering="BEFORE"
|
||||
side="CLIENT"
|
||||
[[dependencies.speedometer]]
|
||||
modId="cloth_config"
|
||||
mandatory=true
|
||||
versionRange="[11.1.106,)"
|
||||
ordering="NONE"
|
||||
side="CLIENT"
|
||||
modId="cloth_config"
|
||||
mandatory=false
|
||||
type="optional"
|
||||
versionRange="[5.3.63,)"
|
||||
ordering="BEFORE"
|
||||
side="CLIENT"
|
||||
@@ -1,7 +1,6 @@
|
||||
{
|
||||
"pack": {
|
||||
"pack_format": 15,
|
||||
"description": "speedometer resources",
|
||||
"forge:server_data_pack_format": 12
|
||||
"pack_format": 7
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,76 @@
|
||||
{
|
||||
"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",
|
||||
"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"
|
||||
"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.0": "First version",
|
||||
@@ -14,13 +78,32 @@
|
||||
"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"
|
||||
"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"
|
||||
},
|
||||
"promos": {
|
||||
"1.20.1-latest": "4.0",
|
||||
"1.20.1-recommended": "4.0",
|
||||
|
||||
"1.20-latest": "4.0",
|
||||
"1.20-recommended": "4.0"
|
||||
"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,31 @@
|
||||
org.gradle.jvmargs=-Xmx8G
|
||||
|
||||
minecraft_version=1.20.1
|
||||
minecraft_version=1.17.1
|
||||
|
||||
archives_base_name=speedometer
|
||||
mod_version=5-alpha
|
||||
mod_version=6.2.4-1.17.1
|
||||
maven_group=me.zacharias
|
||||
|
||||
architectury_version=9.1.10
|
||||
# https://modrinth.com/mod/architectury-api/versions
|
||||
architectury_version = 2.10.12
|
||||
|
||||
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 = 5.3.63
|
||||
|
||||
forge_version=1.20.1-47.0.19
|
||||
# NeoForged Only
|
||||
# https://neoforged.net/
|
||||
neoforge_version = 21.5.14-beta
|
||||
|
||||
# Fabric Only
|
||||
# https://fabricmc.net/develop/
|
||||
fabric_loader_version = 0.13.2
|
||||
fabric_api_version = 0.45.0
|
||||
# https://modrinth.com/mod/modmenu/versions
|
||||
modmenu_version = 2.0.17
|
||||
|
||||
# Forge Only
|
||||
|
||||
forge_version = 37.1.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-7.0-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
86
neoforge/build.gradle
Normal file
@@ -0,0 +1,86 @@
|
||||
plugins {
|
||||
id "com.github.johnrengelman.shadow" version "8.1.1"
|
||||
}
|
||||
architectury {
|
||||
platformSetupLoomIde()
|
||||
neoForge()
|
||||
}
|
||||
|
||||
repositories{
|
||||
maven {
|
||||
name = 'NeoForged'
|
||||
url = 'https://maven.neoforged.net/releases'
|
||||
}
|
||||
maven { url "https://maven.shedaniel.me/" }
|
||||
}
|
||||
|
||||
configurations {
|
||||
common
|
||||
shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this.
|
||||
compileClasspath.extendsFrom common
|
||||
runtimeClasspath.extendsFrom common
|
||||
developmentNeoForge.extendsFrom common
|
||||
}
|
||||
|
||||
dependencies {
|
||||
neoForge "net.neoforged:neoforge:$rootProject.neoforge_version"
|
||||
// Remove the next line if you don't want to depend on the API
|
||||
modImplementation "dev.architectury:architectury-neoforge:$rootProject.architectury_version"
|
||||
|
||||
modImplementation "me.shedaniel.cloth:cloth-config-neoforge:$rootProject.cloth_config_version"
|
||||
|
||||
common(project(path: ":common", configuration: "namedElements")) { transitive false }
|
||||
shadowCommon(project(path: ":common", configuration: "transformProductionNeoForge")) { transitive = false }
|
||||
}
|
||||
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
|
||||
filesMatching("META-INF/neoforge.mods.toml") {
|
||||
expand "version": project.version
|
||||
}
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
exclude "fabric.mod.json"
|
||||
|
||||
|
||||
configurations = [project.configurations.shadowCommon]
|
||||
archiveClassifier.set("dev-shadow")
|
||||
}
|
||||
|
||||
remapJar {
|
||||
inputFile.set shadowJar.archiveFile
|
||||
dependsOn shadowJar
|
||||
archiveClassifier.set(null)
|
||||
}
|
||||
|
||||
jar {
|
||||
archiveClassifier.set("dev")
|
||||
}
|
||||
|
||||
sourcesJar {
|
||||
def commonSources = project(":common").sourcesJar
|
||||
dependsOn commonSources
|
||||
from commonSources.archiveFile.map { zipTree(it) }
|
||||
}
|
||||
|
||||
components.java {
|
||||
withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) {
|
||||
skip()
|
||||
}
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
mavenForge(MavenPublication) {
|
||||
artifactId = rootProject.archives_base_name + "-" + project.name
|
||||
from components.java
|
||||
}
|
||||
}
|
||||
|
||||
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
|
||||
repositories {
|
||||
// Add repositories to publish to here.
|
||||
}
|
||||
}
|
||||
1
neoforge/gradle.properties
Normal file
@@ -0,0 +1 @@
|
||||
loom.platform=neoforge
|
||||
@@ -0,0 +1,58 @@
|
||||
package me.zacharias.speedometer.forge;
|
||||
|
||||
import com.mojang.datafixers.util.Unit;
|
||||
import me.zacharias.speedometer.Speedometer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
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.AddClientReloadListenersEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static me.zacharias.speedometer.Speedometer.MOD_ID;
|
||||
|
||||
@Mod(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 = 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(AddClientReloadListenersEvent event) {
|
||||
event.addListener(ResourceLocation.fromNamespaceAndPath(MOD_ID, "reload_listener"), 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());
|
||||
}
|
||||
}
|
||||
93
neoforge/src/main/resources/META-INF/neoforge.mods.toml
Normal file
@@ -0,0 +1,93 @@
|
||||
# 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="[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"
|
||||
|
||||
# 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
|
||||
|
||||
# A URL to query for updates for this mod. See the JSON update specification <here>
|
||||
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="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.
|
||||
# IGNORE_ALL_VERSION means that your mod will not cause a red X if it's present on the client or the server. This is a special case and should only be used if your mod has no server component.
|
||||
# NONE means that no display test is set on your mod. You need to do this yourself, see IExtensionPoint.DisplayTest for more information. You can define any scheme you wish with this value.
|
||||
# IMPORTANT NOTE: this is NOT an instruction as to which environments (CLIENT or DEDICATED SERVER) your mod loads on. Your mod should load (and maybe do nothing!) whereever it finds itself.
|
||||
displayTest="IGNORE_ALL_VERSION" # MATCH_VERSION is the default if nothing is specified (#optional)
|
||||
|
||||
# The description text for the mod (multi line!) (#mandatory)
|
||||
description='''
|
||||
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="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="[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="CLIENT"
|
||||
[[dependencies.speedometer]]
|
||||
modId="minecraft"
|
||||
mandatory=true
|
||||
versionRange="[1.21,1.22)"
|
||||
ordering="NONE"
|
||||
side="BOTH"
|
||||
[[dependencies.speedometer]]
|
||||
modId="architectury"
|
||||
mandatory=true
|
||||
versionRange="[13.0.5,)"
|
||||
ordering="BEFORE"
|
||||
side="CLIENT"
|
||||
[[dependencies.speedometer]]
|
||||
modId="cloth_config"
|
||||
type="optional"
|
||||
versionRange="[15.0.140,)"
|
||||
ordering="BEFORE"
|
||||
side="CLIENT"
|
||||
BIN
neoforge/src/main/resources/icon.png
Normal file
|
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"
|
||||
}
|
||||
}
|
||||
12
readme.md
@@ -1,16 +1,22 @@
|
||||
# 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 Gradle and building*
|
||||
|
||||
## Compile your own version?
|
||||
1. Download source code
|
||||
* Run `git clone https://github.com/zaze06/Speedometer`
|
||||
* Download the source code from github page [master.zip](https://github.com/zaze06/Speedometer/archive/refs/heads/master.zip)
|
||||
* Download the source code from GitHub page [master.zip](https://github.com/zaze06/Speedometer/archive/refs/heads/master.zip)
|
||||
* unzip the folder
|
||||
2. Open the folder
|
||||
3. Run `gradlew build`(Windows cmd) or `./gradlew build`(Linux, MacOS, Windows powershell)
|
||||
4. the compiled version will be in
|
||||
* Fabic: `fabric/build/libs`
|
||||
* Forge: `forge/build/libs`
|
||||
* 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,5 @@ pluginManagement {
|
||||
|
||||
include("common")
|
||||
include("fabric")
|
||||
include("forge")
|
||||
include("forge")
|
||||
//include("neoforge")
|
||||