diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4636995..d9a6061 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,18 +11,32 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up JDK 21 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: 'corretto' java-version: '21' + - name: Cache Gradle dependencies + uses: actions/cache@v4 + with: + path: ~/.gradle/caches + key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + gradle-${{ runner.os }}- + - name: Cache Gradle wrapper + uses: actions/cache@v4 + with: + path: ~/.gradle/wrapper + key: gradle-wrapper-${{ runner.os }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }} + restore-keys: | + gradle-wrapper-${{ runner.os }}- - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build with Gradle run: ./gradlew build --full-stacktrace - name: Upload Artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: Artifacts path: build/libs/*-release.jar \ No newline at end of file diff --git a/core/src/main/java/com/rappytv/speedruntimer/sound/ITimerSound.java b/api/src/main/java/com/rappytv/speedruntimer/sound/TimerSound.java similarity index 72% rename from core/src/main/java/com/rappytv/speedruntimer/sound/ITimerSound.java rename to api/src/main/java/com/rappytv/speedruntimer/sound/TimerSound.java index 5ea028f..ffb8c4e 100644 --- a/core/src/main/java/com/rappytv/speedruntimer/sound/ITimerSound.java +++ b/api/src/main/java/com/rappytv/speedruntimer/sound/TimerSound.java @@ -2,9 +2,11 @@ import net.labymod.api.client.resources.ResourceLocation; import net.labymod.api.reference.annotation.Referenceable; +import org.jetbrains.annotations.Nullable; +@Nullable @Referenceable -public interface ITimerSound { +public interface TimerSound { ResourceLocation getNotificationSound(); } diff --git a/api/src/main/java/com/rappytv/speedruntimer/util/Timer.java b/api/src/main/java/com/rappytv/speedruntimer/util/Timer.java index 82e74f2..cf6d0bc 100644 --- a/api/src/main/java/com/rappytv/speedruntimer/util/Timer.java +++ b/api/src/main/java/com/rappytv/speedruntimer/util/Timer.java @@ -19,21 +19,21 @@ public Timer(Runnable onCountdownComplete) { } public void startCountUp() { - if(state != TimerState.OFF) return; + if(this.state != TimerState.OFF) return; this.direction = TimerDirection.COUNT_UP; this.seconds = 0; - start(); + this.start(); } public void startCountDown(long seconds) { - if(state != TimerState.OFF) return; + if(this.state != TimerState.OFF) return; this.direction = TimerDirection.COUNT_DOWN; this.seconds = seconds; - start(); + this.start(); } public void reset() { - if(state == TimerState.OFF) return; + if(this.state == TimerState.OFF) return; this.direction = TimerDirection.COUNT_UP; this.seconds = 0; this.state = TimerState.OFF; @@ -51,7 +51,7 @@ public Component getDisplay() { (String.valueOf(seconds).length() > 1 ? "" : "0") + seconds )); - if(state == TimerState.PAUSED) component.decorate(TextDecoration.ITALIC).color(NamedTextColor.RED); + if(this.state == TimerState.PAUSED) component.decorate(TextDecoration.ITALIC).color(NamedTextColor.RED); else component.color(NamedTextColor.GREEN); return component.decorate(TextDecoration.BOLD); } @@ -61,16 +61,16 @@ private void start() { timer.schedule(new TimerTask() { @Override public void run() { - if(state == TimerState.OFF) cancel(); - if(state == TimerState.PAUSED) return; - - if(direction == TimerDirection.COUNT_UP) seconds++; - else if(direction == TimerDirection.COUNT_DOWN) { - seconds--; - if(seconds < 0) { - seconds = 0; - state = TimerState.PAUSED; - onCountdownComplete.run(); + if(Timer.this.state == TimerState.OFF) this.cancel(); + if(Timer.this.state == TimerState.PAUSED) return; + + if(Timer.this.direction == TimerDirection.COUNT_UP) Timer.this.seconds++; + else if(Timer.this.direction == TimerDirection.COUNT_DOWN) { + Timer.this.seconds--; + if(Timer.this.seconds < 0) { + Timer.this.seconds = 0; + Timer.this.state = TimerState.PAUSED; + Timer.this.onCountdownComplete.run(); } } } @@ -99,7 +99,7 @@ public long resolveSeconds(String timeValue) { case "y" -> duration * 60 * 60 * 24 * 7 * 52; default -> { try { - yield resolveSeconds(Integer.parseInt(timeValue) + "s"); + yield this.resolveSeconds(Integer.parseInt(timeValue) + "s"); } catch (NumberFormatException e) { yield -1; } @@ -108,7 +108,7 @@ public long resolveSeconds(String timeValue) { } public TimerDirection getDirection() { - return direction; + return this.direction; } public void setDirection(TimerDirection direction) { @@ -116,7 +116,7 @@ public void setDirection(TimerDirection direction) { } public TimerState getState() { - return state; + return this.state; } public void setState(TimerState state) { @@ -124,7 +124,7 @@ public void setState(TimerState state) { } public long getSeconds() { - return seconds; + return this.seconds; } public void setSeconds(long seconds) { diff --git a/build.gradle.kts b/build.gradle.kts index aa55e44..8305070 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,10 +6,11 @@ plugins { val versions = providers.gradleProperty("net.labymod.minecraft-versions").get().split(";") group = "com.rappytv.speedruntimer" -version = providers.environmentVariable("VERSION").getOrElse("1.0.0") +version = providers.environmentVariable("VERSION").getOrElse("1.0.1") labyMod { defaultPackageName = "com.rappytv.speedruntimer" + addonInfo { namespace = "speedruntimer" displayName = "SpeedrunTimer" diff --git a/core/src/main/java/com/rappytv/speedruntimer/SpeedrunTimerAddon.java b/core/src/main/java/com/rappytv/speedruntimer/SpeedrunTimerAddon.java index 744b938..b2614d5 100644 --- a/core/src/main/java/com/rappytv/speedruntimer/SpeedrunTimerAddon.java +++ b/core/src/main/java/com/rappytv/speedruntimer/SpeedrunTimerAddon.java @@ -1,10 +1,10 @@ package com.rappytv.speedruntimer; +import com.rappytv.speedruntimer.api.generated.ReferenceStorage; import com.rappytv.speedruntimer.command.TimerCommand; -import com.rappytv.speedruntimer.core.generated.DefaultReferenceStorage; -import com.rappytv.speedruntimer.hudWidget.TimerHudWidget; +import com.rappytv.speedruntimer.hudwidget.TimerHudWidget; import com.rappytv.speedruntimer.sound.DefaultTimerSound; -import com.rappytv.speedruntimer.sound.ITimerSound; +import com.rappytv.speedruntimer.sound.TimerSound; import com.rappytv.speedruntimer.util.Timer; import net.labymod.api.Laby; import net.labymod.api.addon.LabyAddon; @@ -29,17 +29,17 @@ public class SpeedrunTimerAddon extends LabyAddon { @SuppressWarnings("ConstantConditions") @Override protected void enable() { - ITimerSound timerSound = ((DefaultReferenceStorage) this.referenceStorageAccessor()).iTimerSound(); + TimerSound timerSound = ((ReferenceStorage) this.referenceStorageAccessor()).getTimerSound(); if(timerSound == null) timerSound = new DefaultTimerSound(); ResourceLocation sound = timerSound.getNotificationSound(); - timer = new Timer(() -> { - if(configuration().countdownSound().get()) { + this.timer = new Timer(() -> { + if(this.configuration().countdownSound().get()) { Laby.references().minecraftSounds().playSound(sound, 1f, 1f); } }); - registerSettingCategory(); - registerCommand(new TimerCommand(this)); + this.registerSettingCategory(); + this.registerCommand(new TimerCommand(this)); Laby.labyAPI().hudWidgetRegistry().register(new TimerHudWidget(this)); } @@ -50,7 +50,7 @@ protected Class configurationClass() { @NotNull public Timer getTimer() { - return timer; + return this.timer; } public static Component prefix() { diff --git a/core/src/main/java/com/rappytv/speedruntimer/SpeedrunTimerConfig.java b/core/src/main/java/com/rappytv/speedruntimer/SpeedrunTimerConfig.java index dd642e7..f94234b 100644 --- a/core/src/main/java/com/rappytv/speedruntimer/SpeedrunTimerConfig.java +++ b/core/src/main/java/com/rappytv/speedruntimer/SpeedrunTimerConfig.java @@ -19,10 +19,10 @@ public class SpeedrunTimerConfig extends AddonConfig { @Override public ConfigProperty enabled() { - return enabled; + return this.enabled; } public ConfigProperty countdownSound() { - return countdownSound; + return this.countdownSound; } } diff --git a/core/src/main/java/com/rappytv/speedruntimer/command/TimerCommand.java b/core/src/main/java/com/rappytv/speedruntimer/command/TimerCommand.java index 964048f..8cd1c5a 100644 --- a/core/src/main/java/com/rappytv/speedruntimer/command/TimerCommand.java +++ b/core/src/main/java/com/rappytv/speedruntimer/command/TimerCommand.java @@ -1,6 +1,7 @@ package com.rappytv.speedruntimer.command; import com.rappytv.speedruntimer.SpeedrunTimerAddon; +import com.rappytv.speedruntimer.util.Timer; import com.rappytv.speedruntimer.util.Timer.TimerDirection; import com.rappytv.speedruntimer.util.Timer.TimerState; import net.labymod.api.Laby; @@ -13,18 +14,19 @@ public class TimerCommand extends Command { public TimerCommand(SpeedrunTimerAddon addon) { super("timer"); - - withSubCommand(new StartSubcommand(addon)); - withSubCommand(new CountdownSubcommand(addon)); - withSubCommand(new PauseSubcommand(addon)); - withSubCommand(new ResumeSubcommand(addon)); - withSubCommand(new TimeSubcommand(addon)); - withSubCommand(new ResetSubcommand(addon)); + Timer timer = addon.getTimer(); + + this.withSubCommand(new StartSubcommand(timer)); + this.withSubCommand(new CountdownSubcommand(timer)); + this.withSubCommand(new PauseSubcommand(timer)); + this.withSubCommand(new ResumeSubcommand(timer)); + this.withSubCommand(new TimeSubcommand(timer)); + this.withSubCommand(new ResetSubcommand(timer)); } @Override public boolean execute(String prefix, String[] arguments) { - displayMessage( + this.displayMessage( Component.empty() .append(SpeedrunTimerAddon.prefix()) .append(Component.translatable( @@ -41,17 +43,17 @@ public boolean execute(String prefix, String[] arguments) { private static class StartSubcommand extends SubCommand { - private final SpeedrunTimerAddon addon; + private final Timer timer; - protected StartSubcommand(SpeedrunTimerAddon addon) { + protected StartSubcommand(Timer timer) { super("start"); - this.addon = addon; + this.timer = timer; } @Override public boolean execute(String prefix, String[] arguments) { - if(addon.getTimer().getState() == TimerState.RUNNING) { - displayMessage( + if(this.timer.getState() == TimerState.RUNNING) { + this.displayMessage( Component.empty() .append(SpeedrunTimerAddon.prefix()) .append(Component.translatable( @@ -62,13 +64,13 @@ public boolean execute(String prefix, String[] arguments) { ); return true; } - if(addon.getTimer().getState() == TimerState.PAUSED) { + if(this.timer.getState() == TimerState.PAUSED) { Laby.references().chatExecutor().chat("/timer resume", false); return true; } - addon.getTimer().startCountUp(); + this.timer.startCountUp(); - displayMessage( + this.displayMessage( Component.empty() .append(SpeedrunTimerAddon.prefix()) .append(Component.translatable( @@ -82,17 +84,17 @@ public boolean execute(String prefix, String[] arguments) { private static class CountdownSubcommand extends SubCommand { - private final SpeedrunTimerAddon addon; + private final Timer timer; - protected CountdownSubcommand(SpeedrunTimerAddon addon) { + protected CountdownSubcommand(Timer timer) { super("countdown", "down"); - this.addon = addon; + this.timer = timer; } @Override public boolean execute(String prefix, String[] arguments) { - if(addon.getTimer().getState() == TimerState.RUNNING) { - displayMessage( + if(this.timer.getState() == TimerState.RUNNING) { + this.displayMessage( Component.empty() .append(SpeedrunTimerAddon.prefix()) .append(Component.translatable( @@ -103,13 +105,13 @@ public boolean execute(String prefix, String[] arguments) { ); return true; } - if(addon.getTimer().getState() == TimerState.PAUSED) { + if(this.timer.getState() == TimerState.PAUSED) { Laby.references().chatExecutor().chat("/timer resume", false); return true; } if(arguments.length < 1) { - displayMessage( + this.displayMessage( Component.empty() .append(SpeedrunTimerAddon.prefix()) .append(Component.translatable( @@ -119,9 +121,9 @@ public boolean execute(String prefix, String[] arguments) { ); return true; } - long seconds = addon.getTimer().resolveSeconds(arguments[0]); + long seconds = this.timer.resolveSeconds(arguments[0]); if(seconds < 0) { - displayMessage( + this.displayMessage( Component.empty() .append(SpeedrunTimerAddon.prefix()) .append(Component.translatable( @@ -132,8 +134,8 @@ public boolean execute(String prefix, String[] arguments) { return true; } - addon.getTimer().startCountDown(seconds); - displayMessage( + this.timer.startCountDown(seconds); + this.displayMessage( Component.empty() .append(SpeedrunTimerAddon.prefix()) .append(Component.translatable( @@ -147,17 +149,17 @@ public boolean execute(String prefix, String[] arguments) { private static class PauseSubcommand extends SubCommand { - private final SpeedrunTimerAddon addon; + private final Timer timer; - protected PauseSubcommand(SpeedrunTimerAddon addon) { + protected PauseSubcommand(Timer timer) { super("pause", "stop"); - this.addon = addon; + this.timer = timer; } @Override public boolean execute(String prefix, String[] arguments) { - if(addon.getTimer().getState() == TimerState.OFF) { - displayMessage( + if(this.timer.getState() == TimerState.OFF) { + this.displayMessage( Component.empty() .append(SpeedrunTimerAddon.prefix()) .append(Component.translatable( @@ -168,8 +170,8 @@ public boolean execute(String prefix, String[] arguments) { ); return true; } - if(addon.getTimer().getState() == TimerState.PAUSED) { - displayMessage( + if(this.timer.getState() == TimerState.PAUSED) { + this.displayMessage( Component.empty() .append(SpeedrunTimerAddon.prefix()) .append(Component.translatable( @@ -180,8 +182,8 @@ public boolean execute(String prefix, String[] arguments) { ); return true; } - addon.getTimer().setState(TimerState.PAUSED); - displayMessage( + this.timer.setState(TimerState.PAUSED); + this.displayMessage( Component.empty() .append(SpeedrunTimerAddon.prefix()) .append(Component.translatable( @@ -195,17 +197,17 @@ public boolean execute(String prefix, String[] arguments) { private static class ResumeSubcommand extends SubCommand { - private final SpeedrunTimerAddon addon; + private final Timer timer; - protected ResumeSubcommand(SpeedrunTimerAddon addon) { + protected ResumeSubcommand(Timer timer) { super("resume"); - this.addon = addon; + this.timer = timer; } @Override public boolean execute(String prefix, String[] arguments) { - if(addon.getTimer().getState() == TimerState.OFF) { - displayMessage( + if(this.timer.getState() == TimerState.OFF) { + this.displayMessage( Component.empty() .append(SpeedrunTimerAddon.prefix()) .append(Component.translatable( @@ -216,8 +218,8 @@ public boolean execute(String prefix, String[] arguments) { ); return true; } - if(addon.getTimer().getState() != TimerState.PAUSED) { - displayMessage( + if(this.timer.getState() != TimerState.PAUSED) { + this.displayMessage( Component.empty() .append(SpeedrunTimerAddon.prefix()) .append(Component.translatable( @@ -228,8 +230,8 @@ public boolean execute(String prefix, String[] arguments) { ); return true; } - if(addon.getTimer().getDirection() == TimerDirection.COUNT_DOWN && addon.getTimer().getSeconds() == 0) { - displayMessage( + if(this.timer.getDirection() == TimerDirection.COUNT_DOWN && this.timer.getSeconds() == 0) { + this.displayMessage( Component.empty() .append(SpeedrunTimerAddon.prefix()) .append(Component.translatable( @@ -240,8 +242,8 @@ public boolean execute(String prefix, String[] arguments) { ); return true; } - addon.getTimer().setState(TimerState.RUNNING); - displayMessage( + this.timer.setState(TimerState.RUNNING); + this.displayMessage( Component.empty() .append(SpeedrunTimerAddon.prefix()) .append(Component.translatable( @@ -255,17 +257,17 @@ public boolean execute(String prefix, String[] arguments) { private static class TimeSubcommand extends SubCommand { - private final SpeedrunTimerAddon addon; + private final Timer timer; - protected TimeSubcommand(SpeedrunTimerAddon addon) { + protected TimeSubcommand(Timer timer) { super("time"); - this.addon = addon; + this.timer = timer; } @Override public boolean execute(String prefix, String[] arguments) { - if(addon.getTimer().getState() == TimerState.OFF) { - displayMessage( + if(this.timer.getState() == TimerState.OFF) { + this.displayMessage( Component.empty() .append(SpeedrunTimerAddon.prefix()) .append(Component.translatable( @@ -277,7 +279,7 @@ public boolean execute(String prefix, String[] arguments) { return true; } if(arguments.length < 1) { - displayMessage( + this.displayMessage( Component.empty() .append(SpeedrunTimerAddon.prefix()) .append(Component.translatable( @@ -287,9 +289,9 @@ public boolean execute(String prefix, String[] arguments) { ); return true; } - long seconds = addon.getTimer().resolveSeconds(arguments[0]); + long seconds = this.timer.resolveSeconds(arguments[0]); if(seconds < 0) { - displayMessage( + this.displayMessage( Component.empty() .append(SpeedrunTimerAddon.prefix()) .append(Component.translatable( @@ -300,8 +302,8 @@ public boolean execute(String prefix, String[] arguments) { return true; } - addon.getTimer().setSeconds(seconds); - displayMessage( + this.timer.setSeconds(seconds); + this.displayMessage( Component.empty() .append(SpeedrunTimerAddon.prefix()) .append(Component.translatable( @@ -316,17 +318,17 @@ public boolean execute(String prefix, String[] arguments) { private static class ResetSubcommand extends SubCommand { - private final SpeedrunTimerAddon addon; + private final Timer timer; - protected ResetSubcommand(SpeedrunTimerAddon addon) { + protected ResetSubcommand(Timer timer) { super("reset"); - this.addon = addon; + this.timer = timer; } @Override public boolean execute(String prefix, String[] arguments) { - if(addon.getTimer().getState() == TimerState.OFF) { - displayMessage( + if(this.timer.getState() == TimerState.OFF) { + this.displayMessage( Component.empty() .append(SpeedrunTimerAddon.prefix()) .append(Component.translatable( @@ -337,8 +339,8 @@ public boolean execute(String prefix, String[] arguments) { ); return true; } - addon.getTimer().reset(); - displayMessage( + this.timer.reset(); + this.displayMessage( Component.empty() .append(SpeedrunTimerAddon.prefix()) .append(Component.translatable( diff --git a/core/src/main/java/com/rappytv/speedruntimer/hudWidget/TimerHudWidget.java b/core/src/main/java/com/rappytv/speedruntimer/hudWidget/TimerHudWidget.java deleted file mode 100644 index 0e14235..0000000 --- a/core/src/main/java/com/rappytv/speedruntimer/hudWidget/TimerHudWidget.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.rappytv.speedruntimer.hudWidget; - -import com.rappytv.speedruntimer.SpeedrunTimerAddon; -import com.rappytv.speedruntimer.util.Timer.TimerState; -import net.labymod.api.Laby; -import net.labymod.api.client.gui.hud.hudwidget.HudWidgetConfig; -import net.labymod.api.client.gui.hud.hudwidget.SimpleHudWidget; -import net.labymod.api.client.gui.hud.position.HudSize; -import net.labymod.api.client.gui.icon.Icon; -import net.labymod.api.client.gui.mouse.MutableMouse; -import net.labymod.api.client.render.font.ComponentRenderer; -import net.labymod.api.client.render.font.RenderableComponent; -import net.labymod.api.client.render.matrix.Stack; -import net.labymod.api.client.resources.ResourceLocation; -import net.labymod.api.util.bounds.area.RectangleAreaPosition; - -public class TimerHudWidget extends SimpleHudWidget { - - private final SpeedrunTimerAddon addon; - private final ComponentRenderer renderer; - - public TimerHudWidget(SpeedrunTimerAddon addon) { - super("speedruntimer_display", HudWidgetConfig.class); - this.addon = addon; - this.renderer = Laby.references().renderPipeline().componentRenderer(); - - setIcon(Icon.texture(ResourceLocation.create( - "speedruntimer", - "textures/timer.png" - ))); - } - - public void initializePreConfigured(HudWidgetConfig config) { - super.initializePreConfigured(config); - config.setEnabled(true); - config.setX(0.0f); - config.setY(-50.0f); - config.setAreaIdentifier(RectangleAreaPosition.BOTTOM_CENTER); - } - - @Override - public void render(Stack stack, MutableMouse mouse, float partialTicks, boolean isEditorContext, HudSize size) { - RenderableComponent statusComponent = RenderableComponent.of(addon.getTimer().getDisplay()); - if (stack != null) { - renderer.builder().text(statusComponent).pos(this.anchor.isLeft() ? 2 : (this.anchor.isCenter() ? statusComponent.getWidth() / 2.0f : 2.0f), 0).color(-1).shadow(true).centered(this.anchor.isCenter()).render(stack); - } - size.set(statusComponent.getWidth(), statusComponent.getHeight()); - } - - @Override - public boolean isVisibleInGame() { - return addon.getTimer().getState() != TimerState.OFF; - } -} diff --git a/core/src/main/java/com/rappytv/speedruntimer/hudwidget/TimerHudWidget.java b/core/src/main/java/com/rappytv/speedruntimer/hudwidget/TimerHudWidget.java new file mode 100644 index 0000000..5c332b7 --- /dev/null +++ b/core/src/main/java/com/rappytv/speedruntimer/hudwidget/TimerHudWidget.java @@ -0,0 +1,87 @@ +package com.rappytv.speedruntimer.hudwidget; + +import com.rappytv.speedruntimer.SpeedrunTimerAddon; +import com.rappytv.speedruntimer.util.Timer.TimerState; +import net.labymod.api.Laby; +import net.labymod.api.client.gui.hud.HudWidgetRendererAccessor; +import net.labymod.api.client.gui.hud.binding.dropzone.HudWidgetDropzone; +import net.labymod.api.client.gui.hud.binding.dropzone.NamedHudWidgetDropzones; +import net.labymod.api.client.gui.hud.hudwidget.HudWidgetConfig; +import net.labymod.api.client.gui.hud.hudwidget.SimpleHudWidget; +import net.labymod.api.client.gui.hud.position.HudSize; +import net.labymod.api.client.gui.hud.position.HudWidgetAnchor; +import net.labymod.api.client.gui.icon.Icon; +import net.labymod.api.client.gui.screen.ScreenContext; +import net.labymod.api.client.render.font.ComponentRenderer; +import net.labymod.api.client.render.font.RenderableComponent; +import net.labymod.api.client.render.matrix.Stack; +import net.labymod.api.client.resources.ResourceLocation; +import net.labymod.api.util.bounds.area.RectangleAreaPosition; + +public class TimerHudWidget extends SimpleHudWidget { + + private final SpeedrunTimerAddon addon; + private final ComponentRenderer renderer; + + public TimerHudWidget(SpeedrunTimerAddon addon) { + super("speedruntimer_display", HudWidgetConfig.class); + this.addon = addon; + this.renderer = Laby.references().renderPipeline().componentRenderer(); + + this.bindDropzones(new TimerHudWidgetDropzone()); + this.setIcon(Icon.texture(ResourceLocation.create( + "speedruntimer", + "textures/timer.png" + ))); + } + + public void initializePreConfigured(HudWidgetConfig config) { + super.initializePreConfigured(config); + config.setEnabled(true); + config.setX(0.0f); + config.setY(-50.0f); + config.setAreaIdentifier(RectangleAreaPosition.BOTTOM_CENTER); + } + + @Override + public void render(RenderPhase phase, ScreenContext context, boolean isEditorContext, HudSize size) { + Stack stack = context.stack(); + RenderableComponent statusComponent = RenderableComponent.of(this.addon.getTimer().getDisplay()); + if (stack != null) { + this.renderer.builder().text(statusComponent).pos(this.anchor.isLeft() ? 2 : (this.anchor.isCenter() ? statusComponent.getWidth() / 2.0f : 2.0f), 0).color(-1).shadow(true).centered(this.anchor.isCenter()).render(stack); + } + size.set(statusComponent.getWidth(), statusComponent.getHeight()); + } + + @Override + public boolean isVisibleInGame() { + return this.addon.getTimer().getState() != TimerState.OFF; + } + + public static class TimerHudWidgetDropzone extends HudWidgetDropzone { + + public TimerHudWidgetDropzone() { + super("timer_display"); + } + + @Override + public float getX(HudWidgetRendererAccessor renderer, HudSize hudWidgetSize) { + return NamedHudWidgetDropzones.ACTION_BAR.getX(renderer, hudWidgetSize); + } + + @Override + public float getY(HudWidgetRendererAccessor renderer, HudSize hudWidgetSize) { + return NamedHudWidgetDropzones.ACTION_BAR.getY(renderer, hudWidgetSize) - 15; + } + + @Override + public HudWidgetDropzone copy() { + return new TimerHudWidgetDropzone(); + } + + @Override + public HudWidgetAnchor getAnchor() { + return HudWidgetAnchor.CENTER_BOTTOM; + } + } +} diff --git a/core/src/main/java/com/rappytv/speedruntimer/sound/DefaultTimerSound.java b/core/src/main/java/com/rappytv/speedruntimer/sound/DefaultTimerSound.java index 4ce2f61..e42c060 100644 --- a/core/src/main/java/com/rappytv/speedruntimer/sound/DefaultTimerSound.java +++ b/core/src/main/java/com/rappytv/speedruntimer/sound/DefaultTimerSound.java @@ -2,12 +2,12 @@ import net.labymod.api.client.resources.ResourceLocation; -public class DefaultTimerSound implements ITimerSound { +public class DefaultTimerSound implements TimerSound { private final ResourceLocation sound = ResourceLocation.create("minecraft", "block.note_block.pling"); @Override public ResourceLocation getNotificationSound() { - return sound; + return this.sound; } } diff --git a/game-runner/src/v1_12_2/java/com/rappytv/speedruntimer/v1_12_2/TimerSoundImpl.java b/game-runner/src/v1_12_2/java/com/rappytv/speedruntimer/v1_12_2/VersionedTimerSound.java similarity index 60% rename from game-runner/src/v1_12_2/java/com/rappytv/speedruntimer/v1_12_2/TimerSoundImpl.java rename to game-runner/src/v1_12_2/java/com/rappytv/speedruntimer/v1_12_2/VersionedTimerSound.java index 0f61dbd..54a3fe5 100644 --- a/game-runner/src/v1_12_2/java/com/rappytv/speedruntimer/v1_12_2/TimerSoundImpl.java +++ b/game-runner/src/v1_12_2/java/com/rappytv/speedruntimer/v1_12_2/VersionedTimerSound.java @@ -1,16 +1,18 @@ package com.rappytv.speedruntimer.v1_12_2; -import com.rappytv.speedruntimer.sound.ITimerSound; +import com.rappytv.speedruntimer.sound.TimerSound; import net.labymod.api.client.resources.ResourceLocation; import net.labymod.api.models.Implements; +import javax.inject.Singleton; -@Implements(ITimerSound.class) -public class TimerSoundImpl implements ITimerSound { +@Singleton +@Implements(TimerSound.class) +public class VersionedTimerSound implements TimerSound { private final ResourceLocation sound = ResourceLocation.create("minecraft", "block.note.pling"); @Override public ResourceLocation getNotificationSound() { - return sound; + return this.sound; } } diff --git a/game-runner/src/v1_8_9/java/com/rappytv/speedruntimer/v1_8_9/TimerSoundImpl.java b/game-runner/src/v1_8_9/java/com/rappytv/speedruntimer/v1_8_9/VersionedTimerSound.java similarity index 60% rename from game-runner/src/v1_8_9/java/com/rappytv/speedruntimer/v1_8_9/TimerSoundImpl.java rename to game-runner/src/v1_8_9/java/com/rappytv/speedruntimer/v1_8_9/VersionedTimerSound.java index a66b8d3..38a7f5c 100644 --- a/game-runner/src/v1_8_9/java/com/rappytv/speedruntimer/v1_8_9/TimerSoundImpl.java +++ b/game-runner/src/v1_8_9/java/com/rappytv/speedruntimer/v1_8_9/VersionedTimerSound.java @@ -1,16 +1,18 @@ package com.rappytv.speedruntimer.v1_8_9; -import com.rappytv.speedruntimer.sound.ITimerSound; +import com.rappytv.speedruntimer.sound.TimerSound; import net.labymod.api.client.resources.ResourceLocation; import net.labymod.api.models.Implements; +import javax.inject.Singleton; -@Implements(ITimerSound.class) -public class TimerSoundImpl implements ITimerSound { +@Singleton +@Implements(TimerSound.class) +public class VersionedTimerSound implements TimerSound { private final ResourceLocation sound = ResourceLocation.create("minecraft", "note.pling"); @Override public ResourceLocation getNotificationSound() { - return sound; + return this.sound; } } diff --git a/gradle.properties b/gradle.properties index 8f550f5..44dc10b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ org.gradle.jvmargs=-Xmx4096m -net.labymod.minecraft-versions=1.8.9;1.12.2;1.16.5;1.17.1;1.18.2;1.19.2;1.19.3;1.19.4;1.20.1;1.20.2;1.20.4;1.20.5;1.20.6;1.21;1.21.1 \ No newline at end of file +net.labymod.minecraft-versions=1.8.9;1.12.2;1.16.5;1.17.1;1.18.2;1.19.2;1.19.3;1.19.4;1.20.1;1.20.2;1.20.4;1.20.5;1.20.6;1.21;1.21.1;1.21.3;1.21.4;1.21.5 \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index d50ac18..69203b6 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,7 +1,8 @@ rootProject.name = "speedruntimer" pluginManagement { - val labyGradlePluginVersion = "0.5.4" + val labyGradlePluginVersion = "0.5.9" + buildscript { repositories { maven("https://dist.labymod.net/api/v1/maven/release/")