Skip to content

Commit

Permalink
Added a few custom config options.
Browse files Browse the repository at this point in the history
The first turns the title screen splash texts green.
The second cycles a new random splash text every 20 seconds.
The third adds a button to the main menu which connects you to 2b2t.
These are disabled by default, and can be changed in your Meteor config settings.
  • Loading branch information
0xTas committed Mar 12, 2024
1 parent 74a0dab commit 8c89891
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 10 deletions.
30 changes: 30 additions & 0 deletions src/main/java/dev/stardust/Stardust.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import dev.stardust.commands.*;
import com.mojang.logging.LogUtils;
import dev.stardust.util.StardustUtil;
import meteordevelopment.meteorclient.settings.Setting;
import meteordevelopment.meteorclient.addons.GithubRepo;
import meteordevelopment.meteorclient.commands.Commands;
import meteordevelopment.meteorclient.addons.MeteorAddon;
import meteordevelopment.meteorclient.settings.BoolSetting;
import meteordevelopment.meteorclient.systems.config.Config;
import meteordevelopment.meteorclient.systems.modules.Modules;
import meteordevelopment.meteorclient.systems.modules.Category;

Expand All @@ -18,6 +21,9 @@
public class Stardust extends MeteorAddon {
public static final Logger LOG = LogUtils.getLogger();
public static final Category CATEGORY = new Category("Stardust", StardustUtil.chooseMenuIcon());
public static Setting<Boolean> greenSplashTextSetting = new BoolSetting.Builder().build();
public static Setting<Boolean> rotateSplashTextSetting = new BoolSetting.Builder().build();
public static Setting<Boolean> directConnectButtonSetting = new BoolSetting.Builder().build();

@Override
public void onInitialize() {
Expand All @@ -40,6 +46,30 @@ public void onInitialize() {
Modules.get().add(new UpdateNotifier());
Modules.get().add(new AutoDrawDistance());

// See SplashTextRendererMixin.java
greenSplashTextSetting = Config.get().settings.getGroup("Visual").add(
new BoolSetting.Builder()
.name("Green Splash Text")
.description(">Makes the title splash texts green.")
.defaultValue(false)
.build()
);
// See TitleScreenMixin.java
rotateSplashTextSetting = Config.get().settings.getGroup("Visual").add(
new BoolSetting.Builder()
.name("Rotate Splash Text")
.description("Picks a new random splash text every 20 seconds.")
.defaultValue(false)
.build()
);
directConnectButtonSetting = Config.get().settings.getGroup("Visual").add(
new BoolSetting.Builder()
.name("Direct Connect Button")
.description("Adds a button to the main menu that directly connects you to 2b2t.org")
.defaultValue(false)
.build()
);

LOG.info("<✨> Stardust initialized.");
}

Expand Down
31 changes: 31 additions & 0 deletions src/main/java/dev/stardust/mixin/SplashTextRendererMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package dev.stardust.mixin;

import dev.stardust.Stardust;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.font.TextRenderer;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import net.minecraft.client.gui.screen.SplashTextRenderer;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;


/**
* @author Tas [0xTas] <[email protected]>
**/
@Mixin(SplashTextRenderer.class)
public class SplashTextRendererMixin {
@Unique private int trackAlpha = 0;

@Inject(method = "render", at = @At("HEAD"))
private void mixinRender(DrawContext context, int width, TextRenderer textRenderer, int alpha, CallbackInfo ci) {
this.trackAlpha = alpha;
}

@ModifyArg(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawCenteredTextWithShadow(Lnet/minecraft/client/font/TextRenderer;Ljava/lang/String;III)V"), index = 4)
private int modifyRenderArg(int color) {
return Stardust.greenSplashTextSetting.get() ? 0x54FB54 | this.trackAlpha : color;
}
}
74 changes: 74 additions & 0 deletions src/main/java/dev/stardust/mixin/TitleScreenMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package dev.stardust.mixin;

import dev.stardust.Stardust;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.network.ServerInfo;
import org.spongepowered.asm.mixin.injection.At;
import net.minecraft.client.network.ServerAddress;
import net.minecraft.client.gui.screen.TitleScreen;
import org.spongepowered.asm.mixin.injection.Inject;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.screen.ConnectScreen;
import net.minecraft.client.gui.screen.SplashTextRenderer;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;


/**
* @author Tas [0xTas] <[email protected]>
**/
@Mixin(TitleScreen.class)
public abstract class TitleScreenMixin extends Screen {
@Unique
private static final ServerInfo OLD_SERVER = new ServerInfo("2builders2tools", "2b2t.org", false);

@Shadow
private @Nullable SplashTextRenderer splashText;

protected TitleScreenMixin(Text title) {
super(title);
}

@Unique
private int timer = 0;
@Unique
private @Nullable MinecraftClient mc = null;

@Unique
private void onClick2b2tButton(ButtonWidget btn) {
if (mc == null) mc = MinecraftClient.getInstance();
ConnectScreen.connect(mc.currentScreen, mc,
ServerAddress.parse(OLD_SERVER.address), OLD_SERVER, true
);
}

@Inject(method = "init", at = @At("TAIL"))
private void mixinInit(CallbackInfo ci) {
if (Stardust.directConnectButtonSetting.get()) {
this.addDrawableChild(ButtonWidget.builder(
Text.of("§c§l2§a§lB"), this::onClick2b2tButton)
.dimensions(this.width / 2 + 104, (this.height / 4 + 48) + 72, 20, 20)
.build()
);
}
}

@Inject(method = "tick", at = @At("HEAD"))
private void mixinTick(CallbackInfo ci) {
if (mc == null) {
mc = MinecraftClient.getInstance();
return;
}

++timer;
if (timer >= 420 && Stardust.rotateSplashTextSetting.get()) {
timer = 0;
splashText = mc.getSplashTextLoader().get();
}
}
}
22 changes: 12 additions & 10 deletions src/main/resources/stardust.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@
"package": "dev.stardust.mixin",
"compatibilityLevel": "JAVA_17",
"client": [
"AbstractSignEditScreenAccessor",
"AbstractSignEditScreenMixin",
"BookScreenMixin",
"SoundSystemMixin",
"TitleScreenMixin",
"MusicTrackerMixin",
"AnvilScreenAccessor",
"BookEditScreenAccessor",
"BookEditScreenMixin",
"BookScreenMixin",
"ClientPlayerEntityMixin",
"ElytraSoundInstanceMixin",
"GameOptionsAccessor",
"MinecraftClientMixin",
"MusicTrackerAccessor",
"MusicTrackerMixin",
"NarratorManagerMixin",
"SoundSystemMixin",
"SourceManagerAccessor",
"WeightedSoundSetMixin",
"WrittenBookContentsAccessor"
"SourceManagerAccessor",
"BookEditScreenAccessor",
"SplashTextRendererMixin",
"ClientPlayerEntityMixin",
"ElytraSoundInstanceMixin",
"WrittenBookContentsAccessor",
"AbstractSignEditScreenMixin",
"AbstractSignEditScreenAccessor"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 8c89891

Please sign in to comment.