Skip to content

Commit

Permalink
More tidying, cleaned up mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
JunePrimavera committed Apr 25, 2024
1 parent 02d8fd4 commit 2cb6dd0
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 28 deletions.
10 changes: 2 additions & 8 deletions src/main/java/xyz/sillyjune/notebook/Notebook.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ public void onInitialize() {
}
}
CONFIG = cfg; // Set the config

openBookKeybindRegister(); // Register keybind for opening the notebook, ";" by default

if (!new File(BOOK_FOLDER).exists() || !new File(STR."\{BOOK_FOLDER}/default.json").exists()) {
try {
Files.createDirectories(Paths.get(BOOK_FOLDER));
Expand All @@ -60,14 +58,10 @@ public void onInitialize() {
LOGGER.error(STR."failed to create \{BOOK_FOLDER}");
}
}

if (CONFIG.debug()) { LOGGER.error("June is very silly. Continue with extreme caution."); }
Date date = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int month = cal.get(Calendar.MONTH);
if (month != 5) { GAY = false; }

cal.setTime(new Date());
if (cal.get(Calendar.MONTH) != Calendar.JUNE) { GAY = false; } // Gay unless proven straight.
}

public static void openBookKeybindRegister() { // Register keybind
Expand Down
1 change: 0 additions & 1 deletion src/main/java/xyz/sillyjune/notebook/NotebookConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public boolean debug() { // Is debug mode enabled?
public int button_offset() { // Button offset config option for compatibility with mods with buttons in the same place (e.g. create)
return button_offset;
}

static String read_config() { // Read config from file
try {
File config = new File("config/notebook.json");
Expand Down
14 changes: 5 additions & 9 deletions src/main/java/xyz/sillyjune/notebook/NotebookScreen.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package xyz.sillyjune.notebook;

import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
Expand Down Expand Up @@ -29,7 +28,6 @@ public class NotebookScreen extends Screen {
private int pageIndex;
private int cursorIndex;
private List<OrderedText> cachedPage;
private Text pageIndexText;
private TextFieldWidget bookNameField;
private ButtonWidget newPageButton;
private ButtonWidget delPageButton;
Expand All @@ -44,7 +42,7 @@ public NotebookScreen() {
private NotebookScreen(boolean playPageTurnSound) {
super(NarratorManager.EMPTY);
this.cachedPage = Collections.emptyList();
this.pageIndexText = ScreenTexts.EMPTY;
//this.pageIndexText = ScreenTexts.EMPTY;
this.pageTurnSound = playPageTurnSound;

}
Expand Down Expand Up @@ -81,10 +79,8 @@ protected String readPage(int pagei) {
newPage();
}
String content = DATA.content[pagei];
if (content == null) {
return "";
}
return content;
// Prevents a crash if pages become corrupted somehow
return Objects.requireNonNullElse(content, "");
}

// Get index of book in folder
Expand Down Expand Up @@ -245,13 +241,13 @@ public void renderBackground(DrawContext context, int mouseX, int mouseY, float
if (cursorIndex == pageContent.length() && System.currentTimeMillis() % 2000 > 1000) {pageContent = STR."\{pageContent}_";}
// Render cursor and book content
this.cachedPage = this.textRenderer.wrapLines(StringVisitable.plain(pageContent), 114);
this.pageIndexText = Text.translatable("book.pageIndicator", this.pageIndex + 1, Math.max(DATA.content.length, 1));
}
// Render book background
context.drawTexture(BOOK_TEXTURE, (this.width - 192) / 2, 2, 0, 0, 192, 192);
for(int m = 0; m < Math.min(128 / 9, this.cachedPage.size()); ++m) {
context.drawText(this.textRenderer, this.cachedPage.get(m), ((this.width - 192) / 2) + 36, 32 + m * 9, 0, false);
}
context.drawText(this.textRenderer, this.pageIndexText, ((this.width - 192) / 2) - this.textRenderer.getWidth(this.pageIndexText) + 192 - 44, 18, 0, false);
// long
context.drawText(this.textRenderer, Text.translatable("book.pageIndicator", this.pageIndex + 1, Math.max(DATA.content.length, 1)), ((this.width - 192) / 2) - this.textRenderer.getWidth(Text.translatable("book.pageIndicator", this.pageIndex + 1, Math.max(DATA.content.length, 1))) + 192 - 44, 18, 0, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,11 @@

@Mixin(GameMenuScreen.class)
public abstract class GameMenuScreenButton extends Screen {
int l = this.height / 4 + 48;
protected GameMenuScreenButton(Text title) {
super(title);
}
@Inject(at = @At("RETURN"), method="initWidgets")
private void addCustomButton(CallbackInfo ci) {
this.addDrawableChild(new TexturedButtonWidget(this.width / 2 + 104, this.height / 4 + 96 + -16, 20, 20, MAIN_BUTTON_ICON, (button) -> {
//Code is run when the button is clicked
assert this.client != null;
this.client.setScreen(new NotebookScreen());
}));
this.addDrawableChild(new TexturedButtonWidget(this.width / 2 + 104, this.height / 4 + 96 + -16, 20, 20, MAIN_BUTTON_ICON, (_) -> this.client.setScreen(new NotebookScreen())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ protected TitleScreenButton(Text title) {
}
@Inject(at = @At("RETURN"), method="initWidgetsNormal")
private void addCustomButton(int y, int spacingY, CallbackInfo ci) {
this.addDrawableChild(new TexturedButtonWidget((this.width / 2 + 104), y + spacingY + CONFIG.button_offset(), 20, 20, MAIN_BUTTON_ICON, (button) -> {
assert this.client != null;
this.client.setScreen(new NotebookScreen());
}));
this.addDrawableChild(new TexturedButtonWidget((this.width / 2 + 104), y + spacingY + CONFIG.button_offset(), 20, 20, MAIN_BUTTON_ICON, (_) -> this.client.setScreen(new NotebookScreen())));
}
}

0 comments on commit 2cb6dd0

Please sign in to comment.