Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/main/java/me/duncanruns/fsgmod/mixin/TitleScreenMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,34 @@ public abstract class TitleScreenMixin extends Screen {
@Unique
private final int seedOffset = RANDOM.nextInt(2); // If you found this, yes, it's making the seed render one pixel off at random.

@Unique
private ButtonWidget fsgConfigButton;

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

@Inject(method = "init", at = @At("TAIL"))
private void init(CallbackInfo info) {
this.addButton(new ButtonWidget(this.width / 2 - 124, this.height / 4 + 48 + 24, 20, 20, new LiteralText(""), (b) -> {
// Save the button instance to the variable instead of just adding it
this.fsgConfigButton = this.addButton(new ButtonWidget(this.width / 2 - 124, this.height / 4 + 48 + 24, 20, 20, new LiteralText(""), (b) -> {
assert client != null;
client.openScreen(new ConfigScreen());
}));
}

@Inject(method = "render", at = @At("TAIL"))
private void wheatSeedsOverlay(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo ci) {
if (this.fsgConfigButton == null) return; // Safety check to prevent crashes

assert this.client != null;
this.client.getTextureManager().bindTexture(BUTTON_IMAGE);
drawTexture(matrices, this.width / 2 - 124 + 1 + (isMinceraft ? RANDOM.nextInt(2) : seedOffset), this.height / 4 + 48 + 2 + 24, 0.0F, 0.0F, 16, 16, 16, 16);

// Dynamically grab the button's X and Y coordinates so the texture tracks the box
int iconX = this.fsgConfigButton.x + 1 + (isMinceraft ? RANDOM.nextInt(2) : seedOffset);
int iconY = this.fsgConfigButton.y + 2;

drawTexture(matrices, iconX, iconY, 0.0F, 0.0F, 16, 16, 16, 16);
}

}
}