Skip to content

SpeedRunIGT API Document

RedLime edited this page Nov 16, 2022 · 31 revisions

Implementation

repositories {
    maven { url 'https://jitpack.io' }
}

dependencies {
    //modImplementation "com.github.RedLime:SpeedRunIGT:${project.minecraft_version}-SNAPSHOT"
    modImplementation "com.github.RedLime:SpeedRunIGT:1.16.1-SNAPSHOT"
}

in fabric.mod.json

  "depends": {
    "minecraft": "...",
    "speedrunigt": ">=7.0"
  }

Timer

Get a timer

InGameTimer timer = InGameTimer.getInstance();

onComplete() (when a complete the category run)

InGameTimer.onComplete(igt -> {
    MinecraftClient.getInstance().player.sendMessage("Cool bro, " + InGameTime.timeToStringFormat(igt.getInGameTime()));
});

tryInsertNewTimeline() (insert your custom timeline)

# Example method
public void onPlayerDeath() {
    InGameTimer.getInstance().tryInsertNewTimeline("death");
}

SpeedRunIGTApi Examples for Extensions

Add entrypoint for SpeedRunIGTApi

in fabric.mod.json

  ...
  "entrypoints": {
    ...
    "speedrunigt": [
      "com.redlimerl.mcsr.breakbeehive.BreakBeehiveImpl"
    ]
  },

Add custom category

public class BreakBeehiveImpl implements SpeedRunIGTApi {
    public static final RunCategory BREAK_BEEHIVE_CATEGORY =
            new RunCategory("break_beehive", "mc_juice/full_game#Break_Beenest", "Break Beehive");
    @Override
    public RunCategory registerCategory() {
        return BREAK_BEEHIVE_CATEGORY;
    }
}

Result :

image

Note! In the development environment, the SpeedRunIGT strings are not displayed normally. but "In the development environment" only. (Fixed in 13.0)

Modify run's end timing of custom category

@Mixin(ClientWorld.class)
public class ClientWorldMixin {
    @Inject(method = "updateListeners", at = @At("TAIL"))
    public void onBlockUpdate(BlockPos pos, BlockState oldState, BlockState newState, int flags, CallbackInfo ci) {
        // Get a timer
        InGameTimer timer = InGameTimer.getInstance();

        // Check has player selected the your category and the timer is running
        if (timer.getCategory() == BreakBeehiveImpl.BREAK_BEEHIVE_CATEGORY && timer.isPlaying()) {
            if (flags == 11 && newState.getBlock() == Blocks.AIR && oldState.getBlock() instanceof BeehiveBlock) {
                // Stop the timer
                InGameTimer.complete();
            }
        }
    }
}

Add custom option button

public class BreakBeehiveImpl implements SpeedRunIGTApi {
    @Override
    public OptionButtonFactory createOptionButton() {
        return screen -> new OptionButtonFactory.Builder()
                .setToolTip(() -> "Test Option Button Tooltip!")
                .setCategory("My category")
                .setButtonWidget(new ButtonWidget(0, 0, 150, 20, new LiteralText("Test Button"), button -> {}));
    }    
}

Result :

image

Note! In the development environment, the SpeedRunIGT strings are not displayed normally. but "In the development environment" only. (Fixed in 13.0)

Example Extension Mod