-
Notifications
You must be signed in to change notification settings - Fork 0
Port Stats Ring from ChatTriggers module to 1.21.10 Fabric mod #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fa93abb
Initial plan
Copilot 0689b0b
Port Stats Ring from ChatTriggers to Fabric mod
Copilot 58090a5
Fix Cloth Config version to 20.0.148 for MC 1.21.10
Copilot 4e49b2b
Address code review feedback
Copilot bf31df0
Address all PR review feedback
Copilot ba317eb
Fix Mojang mappings: Identifier->ResourceLocation, blitSprite->blit
Copilot d8047d4
Fix Cloth Config
bubner aecbc49
Fix parsing and util
bubner 121820b
Extract magic numbers into named constants and add NOT_ENOUGH_MANA 2s…
Copilot 54e4864
UI tuning
bubner 703bdaf
Precompile pattern
bubner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| package me.bubner.statsring; | ||
|
|
||
| import me.shedaniel.clothconfig2.api.ConfigBuilder; | ||
| import me.shedaniel.clothconfig2.api.ConfigCategory; | ||
| import me.shedaniel.clothconfig2.api.ConfigEntryBuilder; | ||
| import net.minecraft.ChatFormatting; | ||
| import net.minecraft.client.gui.screens.Screen; | ||
| import net.minecraft.network.chat.Component; | ||
|
|
||
| /** | ||
| * Cloth Config screen for StatsRing settings. | ||
| * Replaces the original Vigilance config GUI from config.js. | ||
| * | ||
| * @author Lucas Bubner, 2023 (Original CT module) | ||
| */ | ||
| public class ConfigScreen { | ||
| private ConfigScreen() { | ||
| } | ||
|
|
||
| /** | ||
| * Create the Cloth Config settings screen. | ||
| * | ||
| * @param parent the parent screen to return to | ||
| * @param config the mod configuration instance | ||
| * @return the built config screen | ||
| */ | ||
| public static Screen create(Screen parent, ModConfig config) { | ||
| ConfigBuilder builder = ConfigBuilder.create() | ||
| .setParentScreen(parent) | ||
| .setTitle(Component.empty() | ||
| .append(Component.literal("Stats Ring: ").withStyle(ChatFormatting.BOLD)) | ||
| .append(Component.literal("Health ").withStyle(ChatFormatting.RED)) | ||
| .append(Component.literal("and ")) | ||
| .append(Component.literal("Mana ").withStyle(ChatFormatting.AQUA)) | ||
| .append(Component.literal("ring"))); | ||
|
|
||
| ConfigEntryBuilder entryBuilder = builder.entryBuilder(); | ||
|
|
||
| // Core category | ||
| ConfigCategory core = builder.getOrCreateCategory(Component.literal("Core")); | ||
| core.addEntry(entryBuilder.startBooleanToggle(Component.literal("Enable ring"), config.getActive()) | ||
| .setDefaultValue(true) | ||
| .setTooltip(Component.literal("Render the ring (on/off).")) | ||
| .setSaveConsumer(val -> config.properties.setProperty("active", String.valueOf(val))) | ||
| .build()); | ||
| core.addEntry(entryBuilder.startBooleanToggle(Component.literal("Show percentages"), config.getPercentage()) | ||
| .setDefaultValue(true) | ||
| .setTooltip(Component.literal("Render percentages of health/mana next to ring (on/off).")) | ||
| .setSaveConsumer(val -> config.properties.setProperty("percentage", String.valueOf(val))) | ||
| .build()); | ||
| core.addEntry(entryBuilder.startBooleanToggle(Component.literal("Show absorption"), config.getAbsorption()) | ||
| .setDefaultValue(true) | ||
| .setTooltip(Component.literal("Show over 100% health for absorption hearts (on/off).")) | ||
| .setSaveConsumer(val -> config.properties.setProperty("absorption", String.valueOf(val))) | ||
| .build()); | ||
|
|
||
| // Display category | ||
| ConfigCategory display = builder.getOrCreateCategory(Component.literal("Display")); | ||
| display.addEntry(entryBuilder.startBooleanToggle(Component.literal("Show backing image"), config.getBackingImage()) | ||
| .setDefaultValue(true) | ||
| .setTooltip(Component.literal("Show the background image for the ring that surrounds the bars (on/off).")) | ||
| .setSaveConsumer(val -> config.properties.setProperty("backingImage", String.valueOf(val))) | ||
| .build()); | ||
| display.addEntry(entryBuilder.startBooleanToggle(Component.literal("Interpolate colour"), config.getInterpolateColour()) | ||
| .setDefaultValue(true) | ||
| .setTooltip(Component.literal("Linear interpolates mana and health colour depending on percentage filled (on/off).")) | ||
| .setSaveConsumer(val -> config.properties.setProperty("interpolateColour", String.valueOf(val))) | ||
| .build()); | ||
| display.addEntry(entryBuilder.startBooleanToggle(Component.literal("Interpolate bars"), config.getInterpolateBars()) | ||
| .setDefaultValue(true) | ||
| .setTooltip(Component.literal("Linear interpolates the filled progress of the bars (on/off).")) | ||
| .setSaveConsumer(val -> config.properties.setProperty("interpolateBars", String.valueOf(val))) | ||
| .build()); | ||
|
|
||
| // Visual Warnings category | ||
| ConfigCategory warnings = builder.getOrCreateCategory(Component.literal("Visual Warnings")); | ||
| warnings.addEntry(entryBuilder.startIntField(Component.literal("Low HP percent alert threshold"), (int) config.getAlertLowHpPercent()) | ||
| .setDefaultValue(40) | ||
| .setMin(-1) | ||
| .setMax(100) | ||
| .setTooltip(Component.literal("Visually flashes HP when equal to or below this percentage (% from 0 to 100, -1 to disable)")) | ||
| .setSaveConsumer(val -> config.properties.setProperty("alertLowHpPercent", String.valueOf(val))) | ||
| .build()); | ||
| warnings.addEntry(entryBuilder.startIntField(Component.literal("Low Mana percent alert threshold"), (int) config.getAlertLowManaPercent()) | ||
| .setDefaultValue(20) | ||
| .setMin(-1) | ||
| .setMax(100) | ||
| .setTooltip(Component.literal("Visually flashes Mana when equal to or below this percentage (% from 0 to 100, -1 to disable)")) | ||
| .setSaveConsumer(val -> config.properties.setProperty("alertLowManaPercent", String.valueOf(val))) | ||
| .build()); | ||
|
|
||
| builder.setSavingRunnable(config::save); | ||
| return builder.build(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package me.bubner.statsring; | ||
|
|
||
| /** | ||
| * Represents the mana read status from the action bar. | ||
| * | ||
| * @author Lucas Bubner, 2023 (Original CT module) | ||
| */ | ||
| public enum ManaReadStatus { | ||
| OK, | ||
| FROZEN, | ||
| NOT_ENOUGH_MANA | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| package me.bubner.statsring; | ||
|
|
||
| import net.fabricmc.loader.api.FabricLoader; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.util.Properties; | ||
|
|
||
| /** | ||
| * Properties-based configuration for StatsRing. | ||
| * Serialises settings to a .properties file in the Fabric config directory. | ||
| * | ||
| * @author Lucas Bubner, 2023 (Original CT module) | ||
| */ | ||
| public class ModConfig { | ||
| private static final Path CONFIG_PATH = FabricLoader.getInstance().getConfigDir().resolve("statsring.properties"); | ||
| public final Properties properties = new Properties(); | ||
|
|
||
| public void load() { | ||
| if (Files.exists(CONFIG_PATH)) { | ||
| try (var reader = Files.newBufferedReader(CONFIG_PATH)) { | ||
| properties.load(reader); | ||
| } catch (IOException e) { | ||
| StatsRing.LOGGER.error("Failed to load config", e); | ||
| } | ||
| } else { | ||
| save(); | ||
| } | ||
| } | ||
bubner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public void save() { | ||
| try (var writer = Files.newBufferedWriter(CONFIG_PATH)) { | ||
| properties.store(writer, "StatsRing configuration"); | ||
| } catch (IOException e) { | ||
| StatsRing.LOGGER.error("Failed to save config", e); | ||
| } | ||
| } | ||
|
|
||
| public boolean getActive() { | ||
| return Boolean.parseBoolean(properties.getProperty("active", "true")); | ||
| } | ||
|
|
||
| public boolean getPercentage() { | ||
| return Boolean.parseBoolean(properties.getProperty("percentage", "true")); | ||
| } | ||
|
|
||
| public boolean getAbsorption() { | ||
| return Boolean.parseBoolean(properties.getProperty("absorption", "true")); | ||
| } | ||
|
|
||
| public boolean getBackingImage() { | ||
| return Boolean.parseBoolean(properties.getProperty("backingImage", "true")); | ||
| } | ||
|
|
||
| public boolean getInterpolateColour() { | ||
| return Boolean.parseBoolean(properties.getProperty("interpolateColour", "true")); | ||
| } | ||
|
|
||
| public boolean getInterpolateBars() { | ||
| return Boolean.parseBoolean(properties.getProperty("interpolateBars", "true")); | ||
| } | ||
|
|
||
| public float getAlertLowHpPercent() { | ||
| try { | ||
| return Float.parseFloat(properties.getProperty("alertLowHpPercent", "40")); | ||
| } catch (NumberFormatException e) { | ||
| return 40f; | ||
| } | ||
| } | ||
|
|
||
| public float getAlertLowManaPercent() { | ||
| try { | ||
| return Float.parseFloat(properties.getProperty("alertLowManaPercent", "20")); | ||
| } catch (NumberFormatException e) { | ||
| return 20f; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,42 @@ | ||
| package me.bubner.statsring; | ||
|
|
||
| import net.fabricmc.api.ClientModInitializer; | ||
|
|
||
| import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; | ||
| import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; | ||
| import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * StatsRing - Display Health and Mana in a ring around the crosshair on Hypixel SkyBlock. | ||
| * Ported from a 1.8.9 ChatTriggers module into a 1.21.10 Fabric mod. | ||
| * | ||
| * @author Lucas Bubner, 2023 (Original CT module) | ||
| */ | ||
| public class StatsRing implements ClientModInitializer { | ||
| public static final String MOD_ID = "statsring"; | ||
| public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); | ||
| public static final String MOD_ID = "statsring"; | ||
| public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); | ||
| private volatile boolean scheduleOpenConfigScreen = false; | ||
|
|
||
| @Override | ||
| public void onInitializeClient() { | ||
| final ModConfig config = new ModConfig(); | ||
| config.load(); | ||
|
|
||
| new StatsRingRenderer(config).register(); | ||
|
|
||
| @Override | ||
| public void onInitializeClient() { | ||
|
|
||
| } | ||
| // Register /ring command to open the settings GUI | ||
| ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> | ||
| dispatcher.register(ClientCommandManager.literal("ring").executes(context -> { | ||
| scheduleOpenConfigScreen = true; | ||
| return 1; | ||
| })) | ||
| ); | ||
| ClientTickEvents.END_CLIENT_TICK.register(client -> { | ||
| if (scheduleOpenConfigScreen) { | ||
| client.execute(() -> client.setScreen(ConfigScreen.create(client.screen, config))); | ||
| scheduleOpenConfigScreen = false; | ||
| } | ||
| }); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.