Skip to content

Commit 2c11e50

Browse files
authored
Merge pull request #4 from RappyLabyAddons/development
Release v1.0.2
2 parents 37f3e76 + f8abb39 commit 2c11e50

16 files changed

Lines changed: 81 additions & 113 deletions

File tree

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v4
15-
- name: Set up JDK 21
15+
- name: Set up JDK 25
1616
uses: actions/setup-java@v4
1717
with:
1818
distribution: 'corretto'
19-
java-version: '21'
19+
java-version: '25'
2020
- name: Cache Gradle dependencies
2121
uses: actions/cache@v4
2222
with:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ run/
7373
# LabyGradle | Addon Plugin
7474
build-data.txt
7575
.assetsroot
76+
resources_index.json
77+
access_widener_index.json
7678

7779
# Don't ignore libraries
7880
!libs/*.jar

api/src/main/java/com/rappytv/speedruntimer/util/Timer.java renamed to api/src/main/java/com/rappytv/speedruntimer/api/Timer.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
package com.rappytv.speedruntimer.util;
1+
package com.rappytv.speedruntimer.api;
22

3+
import com.rappytv.speedruntimer.api.event.CountdownCompleteEvent;
4+
import net.labymod.api.Laby;
35
import net.labymod.api.client.component.Component;
46
import net.labymod.api.client.component.format.NamedTextColor;
57
import net.labymod.api.client.component.format.TextDecoration;
@@ -9,23 +11,18 @@ public class Timer {
911

1012
private static final String displayFormat = "%s:%s:%s";
1113
private static final java.util.Timer timer = new java.util.Timer();
12-
private final Runnable onCountdownComplete;
1314
private TimerState state = TimerState.OFF;
1415
private TimerDirection direction = TimerDirection.COUNT_DOWN;
1516
private long seconds = 0;
1617

17-
public Timer(Runnable onCountdownComplete) {
18-
this.onCountdownComplete = onCountdownComplete;
19-
}
20-
2118
public void startCountUp() {
2219
if(this.state != TimerState.OFF) return;
2320
this.direction = TimerDirection.COUNT_UP;
2421
this.seconds = 0;
2522
this.start();
2623
}
2724

28-
public void startCountDown(long seconds) {
25+
public void startCountdown(long seconds) {
2926
if(this.state != TimerState.OFF) return;
3027
this.direction = TimerDirection.COUNT_DOWN;
3128
this.seconds = seconds;
@@ -70,7 +67,7 @@ else if(Timer.this.direction == TimerDirection.COUNT_DOWN) {
7067
if(Timer.this.seconds < 0) {
7168
Timer.this.seconds = 0;
7269
Timer.this.state = TimerState.PAUSED;
73-
Timer.this.onCountdownComplete.run();
70+
Laby.fireEvent(new CountdownCompleteEvent());
7471
}
7572
}
7673
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.rappytv.speedruntimer.api.event;
2+
3+
import net.labymod.api.event.Event;
4+
5+
public class CountdownCompleteEvent implements Event {
6+
7+
}

api/src/main/java/com/rappytv/speedruntimer/sound/TimerSound.java

Lines changed: 0 additions & 12 deletions
This file was deleted.

build.gradle.kts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
val versions = providers.gradleProperty("net.labymod.minecraft-versions").get().split(";")
77

88
group = "com.rappytv.speedruntimer"
9-
version = providers.environmentVariable("VERSION").getOrElse("1.0.1")
9+
version = providers.environmentVariable("VERSION").getOrElse("1.0.2")
1010

1111
labyMod {
1212
defaultPackageName = "com.rappytv.speedruntimer"
@@ -37,4 +37,9 @@ subprojects {
3737

3838
group = rootProject.group
3939
version = rootProject.version
40+
41+
extensions.findByType(JavaPluginExtension::class.java)?.apply {
42+
sourceCompatibility = JavaVersion.VERSION_21
43+
targetCompatibility = JavaVersion.VERSION_21
44+
}
4045
}

core/src/main/java/com/rappytv/speedruntimer/SpeedrunTimerAddon.java renamed to core/src/main/java/com/rappytv/speedruntimer/core/SpeedrunTimerAddon.java

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
package com.rappytv.speedruntimer;
2-
3-
import com.rappytv.speedruntimer.api.generated.ReferenceStorage;
4-
import com.rappytv.speedruntimer.command.TimerCommand;
5-
import com.rappytv.speedruntimer.hudwidget.TimerHudWidget;
6-
import com.rappytv.speedruntimer.sound.DefaultTimerSound;
7-
import com.rappytv.speedruntimer.sound.TimerSound;
8-
import com.rappytv.speedruntimer.util.Timer;
1+
package com.rappytv.speedruntimer.core;
2+
3+
import com.rappytv.speedruntimer.core.command.TimerCommand;
4+
import com.rappytv.speedruntimer.api.event.CountdownCompleteEvent;
5+
import com.rappytv.speedruntimer.core.hudwidget.TimerHudWidget;
6+
import com.rappytv.speedruntimer.api.Timer;
97
import net.labymod.api.Laby;
108
import net.labymod.api.addon.LabyAddon;
119
import net.labymod.api.client.component.Component;
1210
import net.labymod.api.client.component.format.NamedTextColor;
1311
import net.labymod.api.client.component.format.TextDecoration;
1412
import net.labymod.api.client.resources.ResourceLocation;
13+
import net.labymod.api.event.Subscribe;
14+
import net.labymod.api.loader.MinecraftVersions;
1515
import net.labymod.api.models.addon.annotation.AddonMain;
1616
import org.jetbrains.annotations.NotNull;
1717

@@ -25,24 +25,29 @@ public class SpeedrunTimerAddon extends LabyAddon<SpeedrunTimerConfig> {
2525
.append(Component.space());
2626

2727
private Timer timer;
28+
private ResourceLocation timerSound;
2829

29-
@SuppressWarnings("ConstantConditions")
3030
@Override
31-
protected void enable() {
32-
TimerSound timerSound = ((ReferenceStorage) this.referenceStorageAccessor()).getTimerSound();
33-
if(timerSound == null)
34-
timerSound = new DefaultTimerSound();
35-
ResourceLocation sound = timerSound.getNotificationSound();
36-
this.timer = new Timer(() -> {
37-
if(this.configuration().countdownSound().get()) {
38-
Laby.references().minecraftSounds().playSound(sound, 1f, 1f);
39-
}
40-
});
31+
public void enable() {
32+
this.timer = new Timer();
33+
this.initializeTimerSound();
4134
this.registerSettingCategory();
4235
this.registerCommand(new TimerCommand(this));
4336
Laby.labyAPI().hudWidgetRegistry().register(new TimerHudWidget(this));
4437
}
4538

39+
@Subscribe
40+
public void onCountDownComplete(CountdownCompleteEvent event) {
41+
if(!this.configuration().countdownSound().get() || this.timerSound == null) {
42+
return;
43+
}
44+
Laby.references().minecraftSounds().playSound(
45+
this.timerSound,
46+
1f,
47+
1f
48+
);
49+
}
50+
4651
@Override
4752
protected Class<? extends SpeedrunTimerConfig> configurationClass() {
4853
return SpeedrunTimerConfig.class;
@@ -56,4 +61,16 @@ public Timer getTimer() {
5661
public static Component prefix() {
5762
return prefix;
5863
}
64+
65+
private void initializeTimerSound() {
66+
String path;
67+
if(MinecraftVersions.current().equals(MinecraftVersions.V1_8_9)) {
68+
path = "note.pling";
69+
} else if(MinecraftVersions.current().equals(MinecraftVersions.V1_12_2)) {
70+
path = "block.note.pling";
71+
} else {
72+
path = "block.note_block.pling";
73+
}
74+
this.timerSound = ResourceLocation.create("minecraft", path);
75+
}
5976
}

core/src/main/java/com/rappytv/speedruntimer/SpeedrunTimerConfig.java renamed to core/src/main/java/com/rappytv/speedruntimer/core/SpeedrunTimerConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.rappytv.speedruntimer;
1+
package com.rappytv.speedruntimer.core;
22

33
import net.labymod.api.addon.AddonConfig;
44
import net.labymod.api.client.gui.screen.widget.widgets.input.SwitchWidget.SwitchSetting;

core/src/main/java/com/rappytv/speedruntimer/command/TimerCommand.java renamed to core/src/main/java/com/rappytv/speedruntimer/core/command/TimerCommand.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package com.rappytv.speedruntimer.command;
1+
package com.rappytv.speedruntimer.core.command;
22

3-
import com.rappytv.speedruntimer.SpeedrunTimerAddon;
4-
import com.rappytv.speedruntimer.util.Timer;
5-
import com.rappytv.speedruntimer.util.Timer.TimerDirection;
6-
import com.rappytv.speedruntimer.util.Timer.TimerState;
3+
import com.rappytv.speedruntimer.core.SpeedrunTimerAddon;
4+
import com.rappytv.speedruntimer.api.Timer;
5+
import com.rappytv.speedruntimer.api.Timer.TimerDirection;
6+
import com.rappytv.speedruntimer.api.Timer.TimerState;
77
import net.labymod.api.Laby;
88
import net.labymod.api.client.chat.command.Command;
99
import net.labymod.api.client.chat.command.SubCommand;
@@ -134,7 +134,7 @@ public boolean execute(String prefix, String[] arguments) {
134134
return true;
135135
}
136136

137-
this.timer.startCountDown(seconds);
137+
this.timer.startCountdown(seconds);
138138
this.displayMessage(
139139
Component.empty()
140140
.append(SpeedrunTimerAddon.prefix())

core/src/main/java/com/rappytv/speedruntimer/hudwidget/TimerHudWidget.java renamed to core/src/main/java/com/rappytv/speedruntimer/core/hudwidget/TimerHudWidget.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package com.rappytv.speedruntimer.hudwidget;
1+
package com.rappytv.speedruntimer.core.hudwidget;
22

3-
import com.rappytv.speedruntimer.SpeedrunTimerAddon;
4-
import com.rappytv.speedruntimer.util.Timer.TimerState;
5-
import net.labymod.api.Laby;
3+
import com.rappytv.speedruntimer.core.SpeedrunTimerAddon;
4+
import com.rappytv.speedruntimer.api.Timer.TimerState;
5+
import net.labymod.api.client.gfx.pipeline.renderer.text.TextRenderingOptions;
66
import net.labymod.api.client.gui.hud.HudWidgetRendererAccessor;
77
import net.labymod.api.client.gui.hud.binding.dropzone.HudWidgetDropzone;
88
import net.labymod.api.client.gui.hud.binding.dropzone.NamedHudWidgetDropzones;
@@ -12,21 +12,17 @@
1212
import net.labymod.api.client.gui.hud.position.HudWidgetAnchor;
1313
import net.labymod.api.client.gui.icon.Icon;
1414
import net.labymod.api.client.gui.screen.ScreenContext;
15-
import net.labymod.api.client.render.font.ComponentRenderer;
1615
import net.labymod.api.client.render.font.RenderableComponent;
17-
import net.labymod.api.client.render.matrix.Stack;
1816
import net.labymod.api.client.resources.ResourceLocation;
1917
import net.labymod.api.util.bounds.area.RectangleAreaPosition;
2018

2119
public class TimerHudWidget extends SimpleHudWidget<HudWidgetConfig> {
2220

2321
private final SpeedrunTimerAddon addon;
24-
private final ComponentRenderer renderer;
2522

2623
public TimerHudWidget(SpeedrunTimerAddon addon) {
2724
super("speedruntimer_display", HudWidgetConfig.class);
2825
this.addon = addon;
29-
this.renderer = Laby.references().renderPipeline().componentRenderer();
3026

3127
this.bindDropzones(new TimerHudWidgetDropzone());
3228
this.setIcon(Icon.texture(ResourceLocation.create(
@@ -45,11 +41,16 @@ public void initializePreConfigured(HudWidgetConfig config) {
4541

4642
@Override
4743
public void render(RenderPhase phase, ScreenContext context, boolean isEditorContext, HudSize size) {
48-
Stack stack = context.stack();
4944
RenderableComponent statusComponent = RenderableComponent.of(this.addon.getTimer().getDisplay());
50-
if (stack != null) {
51-
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);
52-
}
45+
context.canvas().submitRenderableComponent(
46+
statusComponent,
47+
this.anchor.isCenter() ? statusComponent.getWidth() / 2 : 0,
48+
0,
49+
-1,
50+
TextRenderingOptions.SHADOW | (this.anchor.isCenter()
51+
? TextRenderingOptions.CENTERED
52+
: TextRenderingOptions.NONE
53+
));
5354
size.set(statusComponent.getWidth(), statusComponent.getHeight());
5455
}
5556

0 commit comments

Comments
 (0)