Skip to content

Commit

Permalink
Extracted a boolean to its method
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro270707 committed Jan 16, 2024
1 parent 2196083 commit d91b8a8
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/main/java/net/pedroricardo/commander/mixin/GuiChatMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import net.pedroricardo.commander.content.CommanderCommandSource;
import net.pedroricardo.commander.gui.GuiChatSuggestions;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.Sys;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -41,13 +40,7 @@ private void drawSuggestionPreview(int x, int y, float renderPartialTicks, Callb
int mouseX = GuiHelper.getScaledMouseX(((GuiScreenAccessor)((GuiChat)(Object)this)).mc());
int mouseY = GuiHelper.getScaledMouseY(((GuiScreenAccessor)((GuiChat)(Object)this)).mc()) - 1;

if (this.commander$suggestionsGui != null && !this.commander$suggestionsGui.getSuggestions().isEmpty()
&& ((this.commander$suggestionsGui.getParseResults() != null
&& (this.commander$suggestionsGui.getCursor() == this.commander$suggestionsGui.getParseResults().getReader().getString().trim().length()
|| this.commander$suggestionsGui.getCursor() == this.commander$suggestionsGui.getParseResults().getReader().getString().length()))
||
Commander.serverSuggestions.has("reader") && this.commander$suggestionsGui.getCursor() == Commander.serverSuggestions.getAsJsonObject("reader").get("string").getAsString().trim().length()
|| this.commander$suggestionsGui.getCursor() == Commander.serverSuggestions.getAsJsonObject("reader").get("string").getAsString().length())) {
if (this.shouldDrawSuggestionPreview()) {
Suggestion suggestionToRender;
if (this.commander$suggestionsGui.isHoveringOverSuggestions(mouseX, mouseY)) {
suggestionToRender = this.commander$suggestionsGui.getSuggestions().get(this.commander$suggestionsGui.getIndexOfSuggestionBeingHoveredOver(mouseX, mouseY).get());
Expand All @@ -62,6 +55,13 @@ private void drawSuggestionPreview(int x, int y, float renderPartialTicks, Callb
}
}

@Unique
private boolean shouldDrawSuggestionPreview() {
boolean basedOnParseResults = this.commander$suggestionsGui.getParseResults() != null && (this.commander$suggestionsGui.getCursor() == this.commander$suggestionsGui.getParseResults().getReader().getString().trim().length() || this.commander$suggestionsGui.getCursor() == this.commander$suggestionsGui.getParseResults().getReader().getString().length());
boolean basedOnServer = Commander.serverSuggestions.has("reader") && (this.commander$suggestionsGui.getCursor() == Commander.serverSuggestions.getAsJsonObject("reader").get("string").getAsString().trim().length() || this.commander$suggestionsGui.getCursor() == Commander.serverSuggestions.getAsJsonObject("reader").get("string").getAsString().length());
return basedOnParseResults || basedOnServer;
}

@Inject(method = "drawScreen", at = @At("TAIL"))
private void drawSuggestionsGuiScreen(int x, int y, float renderPartialTicks, CallbackInfo ci) {
if (this.commander$suggestionsGui != null) this.commander$suggestionsGui.drawScreen();
Expand Down

0 comments on commit d91b8a8

Please sign in to comment.