Skip to content

Commit f675c72

Browse files
Speedrun API / SeedQueue compatibility (#202)
* upgradle: loom 1.5 * feature: speedrunapi support * check if createWorld is called on clientthread for seedqueue compat * bump version to 15.0 * fix: always use english option compat with fabric resource loader * remove the mixin plugin as it is unnecessary --------- Co-authored-by: contaria <[email protected]>
1 parent a813153 commit f675c72

File tree

10 files changed

+54
-49
lines changed

10 files changed

+54
-49
lines changed

build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//file:noinspection GroovyUnusedAssignment
22
//file:noinspection GroovyAssignabilityCheck
33
plugins {
4-
id 'fabric-loom' version '1.4-SNAPSHOT'
4+
id 'fabric-loom' version '1.5-SNAPSHOT'
55
id 'maven-publish'
66
}
77

@@ -26,6 +26,8 @@ dependencies {
2626
minecraft "com.mojang:minecraft:${project.minecraft_version}"
2727
mappings "com.github.RedLime:yarn:${project.yarn_mappings}:v2"
2828
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
29+
// https://jitpack.io/#kingcontaria/speedrunapi
30+
modImplementation "com.github.KingContaria:SpeedrunAPI:3d7827a9c1"
2931

3032
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
3133
// You may need to force-disable transitiveness on them.

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ yarn_mappings=1.16.1.build.19
1010
loader_version=0.14.25
1111

1212
# Mod Properties
13-
mod_version=14.2
13+
mod_version=15.0
1414
maven_group=com.redlimerl.speedrunigt
1515
archives_base_name=SpeedRunIGT

src/main/java/com/redlimerl/speedrunigt/SpeedRunIGTMixinPlugin.java

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.redlimerl.speedrunigt.gui.screen;
2+
3+
import net.minecraft.client.gui.screen.Screen;
4+
import org.jetbrains.annotations.NotNull;
5+
import org.mcsr.speedrunapi.config.api.SpeedrunConfigScreenProvider;
6+
7+
@SuppressWarnings("unused")
8+
public class SpeedRunOptionScreenProvider implements SpeedrunConfigScreenProvider {
9+
@Override
10+
public @NotNull Screen createConfigScreen(Screen parent) {
11+
return new SpeedRunOptionScreen(parent);
12+
}
13+
}

src/main/java/com/redlimerl/speedrunigt/mixins/MinecraftClientMixin.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ public abstract class MinecraftClientMixin {
7474

7575
@Inject(at = @At("HEAD"), method = "createWorld")
7676
public void onCreate(String worldName, LevelInfo levelInfo, RegistryTracker.Modifiable registryTracker, GeneratorOptions generatorOptions, CallbackInfo ci) {
77+
// don't start timer when the world is being created on another thread
78+
// this is for compatibility with SeedQueue, where this is method is called to create background seeds
79+
if (!MinecraftClient.getInstance().isOnThread()) {
80+
return;
81+
}
82+
7783
RunCategory category = SpeedRunOption.getOption(SpeedRunOptions.TIMER_CATEGORY);
7884
if (category.isAutoStart()) InGameTimer.start(worldName, RunType.fromBoolean(InGameTimerUtils.IS_SET_SEED));
7985
InGameTimer.getInstance().setDefaultGameMode(levelInfo.getGameMode().getId());

src/main/java/com/redlimerl/speedrunigt/mixins/retime/SodiumOptionImplMixin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
package com.redlimerl.speedrunigt.mixins.retime;
22

33
import com.redlimerl.speedrunigt.timer.InGameTimerUtils;
4+
import org.spongepowered.asm.mixin.Dynamic;
45
import org.spongepowered.asm.mixin.Mixin;
56
import org.spongepowered.asm.mixin.Pseudo;
67
import org.spongepowered.asm.mixin.injection.At;
78
import org.spongepowered.asm.mixin.injection.Inject;
89
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
910

10-
@SuppressWarnings("UnresolvedMixinReference")
1111
@Pseudo
1212
@Mixin(targets = "me.jellysquid.mods.sodium.client.gui.options.OptionImpl", remap = false)
1313
public class SodiumOptionImplMixin {
1414

15+
@Dynamic
1516
@Inject(method = "setValue", remap = false, at = @At("HEAD"))
1617
public void onSetValue(CallbackInfo ci) {
1718
InGameTimerUtils.CHANGED_OPTIONS.add(this);

src/main/java/com/redlimerl/speedrunigt/mixins/screen/OptionsScreenMixin.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.mojang.blaze3d.systems.RenderSystem;
44
import com.redlimerl.speedrunigt.SpeedRunIGTUpdateChecker;
55
import com.redlimerl.speedrunigt.gui.screen.SpeedRunOptionScreen;
6+
import net.fabricmc.loader.api.FabricLoader;
67
import net.minecraft.client.gui.screen.Screen;
78
import net.minecraft.client.gui.screen.options.OptionsScreen;
89
import net.minecraft.client.gui.widget.ButtonWidget;
@@ -20,6 +21,7 @@ public class OptionsScreenMixin extends Screen {
2021
private static final Identifier ENDER_PEARL = new Identifier("textures/item/ender_pearl.png");
2122
private static final Identifier BLAZE_POWDER = new Identifier("textures/item/blaze_powder.png");
2223
private static final Identifier ENDER_EYE = new Identifier("textures/item/ender_eye.png");
24+
private static final boolean hasSpeedrunAPI = FabricLoader.getInstance().isModLoaded("speedrunapi");
2325

2426
private ButtonWidget timerButton;
2527

@@ -29,6 +31,7 @@ protected OptionsScreenMixin(Text title) {
2931

3032
@Inject(method = "init", at = @At("TAIL"))
3133
private void onInit(CallbackInfo ci) {
34+
if (hasSpeedrunAPI) return;
3235
this.timerButton = new ButtonWidget(this.width / 2 - 180, this.height / 6 - 12, 20, 20, new LiteralText(""), (buttonWidget) -> {
3336
if (this.client != null) {
3437
this.client.openScreen(new SpeedRunOptionScreen(this));
@@ -40,6 +43,7 @@ private void onInit(CallbackInfo ci) {
4043
@SuppressWarnings("deprecation")
4144
@Inject(method = "render", at = @At("TAIL"))
4245
private void renderEnderPearl(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo ci) {
46+
if (hasSpeedrunAPI) return;
4347
if (this.client != null) {
4448
RenderSystem.pushMatrix();
4549
RenderSystem.translatef(-.5f, -.5f, 0);

src/main/java/com/redlimerl/speedrunigt/mixins/translate/TranslationStorageMixin.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import org.spongepowered.asm.mixin.injection.At;
1111
import org.spongepowered.asm.mixin.injection.Inject;
1212
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
13+
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
1314

15+
import java.util.Iterator;
1416
import java.util.List;
1517
import java.util.Map;
1618
import java.util.Optional;
@@ -28,4 +30,11 @@ private static void onLoad(List<Resource> resources, Map<String, String> transla
2830
.ifPresent(langStream -> Language.load(langStream, translationMap::put));
2931
});
3032
}
33+
34+
@Inject(method = "load(Ljava/util/List;Ljava/util/Map;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/resource/Resource;getInputStream()Ljava/io/InputStream;"), locals = LocalCapture.CAPTURE_FAILSOFT, cancellable = true)
35+
private static void cancelExternalLoadingOfTranslations(List<Resource> resources, Map<String, String> translationMap, CallbackInfo ci, Iterator<Resource> resourceIterator, Resource resource) {
36+
if (SpeedRunOption.getOption(SpeedRunOptions.ALWAYS_ENGLISH_TRANSLATIONS) && resource.getId().getNamespace().equals("speedrunigt") && !resource.getId().getPath().equalsIgnoreCase("lang/en_us.json")) {
37+
ci.cancel();
38+
}
39+
}
3140
}

src/main/resources/fabric.mod.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
"name": "SpeedRunIGT",
77
"description": "Displays the timer with RTA, IGT in Minecraft",
88
"authors": [
9-
"RedLime"
9+
{
10+
"name": "RedLime",
11+
"contact": {
12+
"homepage": "https://github.com/RedLime"
13+
}
14+
}
1015
],
1116
"contact": {
1217
"sources": "https://github.com/RedLime/SpeedRunIGT"
@@ -39,5 +44,15 @@
3944

4045
"breaks": {
4146
"ghostrunner": "<=3.0"
47+
},
48+
49+
"suggests": {
50+
"speedrunapi": "*"
51+
},
52+
53+
"custom": {
54+
"speedrunapi": {
55+
"screen": "com.redlimerl.speedrunigt.gui.screen.SpeedRunOptionScreenProvider"
56+
}
4257
}
4358
}

src/main/resources/speedrunigt.mixins.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"required": true,
33
"package": "com.redlimerl.speedrunigt.mixins",
4-
"plugin": "com.redlimerl.speedrunigt.SpeedRunIGTMixinPlugin",
54
"mixins": [
65
"access.ServerStatHandlerAccessor",
76

0 commit comments

Comments
 (0)