-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from nutyworks/auto-complete-enhance
Auto complete enhance
- Loading branch information
Showing
7 changed files
with
134 additions
and
544 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/client/java/works/nuty/calcite/mixin/client/ChatInputSuggestorFields.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package works.nuty.calcite.mixin.client; | ||
|
||
import com.mojang.brigadier.ParseResults; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.gui.screen.ChatInputSuggestor; | ||
import net.minecraft.command.CommandSource; | ||
import net.minecraft.text.OrderedText; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
import java.util.List; | ||
|
||
@Environment(EnvType.CLIENT) | ||
@Mixin(ChatInputSuggestor.class) | ||
public interface ChatInputSuggestorFields { | ||
@Accessor | ||
ChatInputSuggestor.SuggestionWindow getWindow(); | ||
|
||
@Accessor | ||
int getMaxSuggestionSize(); | ||
|
||
@Accessor | ||
ParseResults<CommandSource> getParse(); | ||
|
||
@Accessor | ||
List<OrderedText> getMessages(); | ||
} |
21 changes: 21 additions & 0 deletions
21
src/client/java/works/nuty/calcite/mixin/client/SuggestionWindowFields.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package works.nuty.calcite.mixin.client; | ||
|
||
import com.mojang.brigadier.suggestion.Suggestion; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.gui.screen.ChatInputSuggestor; | ||
import net.minecraft.client.util.math.Rect2i; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
import java.util.List; | ||
|
||
@Environment(EnvType.CLIENT) | ||
@Mixin(ChatInputSuggestor.SuggestionWindow.class) | ||
public interface SuggestionWindowFields { | ||
@Accessor | ||
Rect2i getArea(); | ||
|
||
@Accessor | ||
List<Suggestion> getSuggestions(); | ||
} |
45 changes: 45 additions & 0 deletions
45
src/client/java/works/nuty/calcite/mixin/client/SuggestionWindowMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package works.nuty.calcite.mixin.client; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.gui.screen.ChatInputSuggestor; | ||
import org.lwjgl.glfw.GLFW; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Environment(EnvType.CLIENT) | ||
@Mixin(ChatInputSuggestor.SuggestionWindow.class) | ||
public abstract class SuggestionWindowMixin { | ||
@Shadow | ||
boolean completed; | ||
|
||
@Shadow | ||
public abstract void scroll(int offset); | ||
|
||
@Shadow | ||
public abstract void complete(); | ||
|
||
@Inject(at = @At("HEAD"), method = "keyPressed", cancellable = true) | ||
public void keyPressed(int keyCode, int scanCode, int modifiers, CallbackInfoReturnable<Boolean> cir) { | ||
if ((modifiers & GLFW.GLFW_MOD_CONTROL) > 0 && keyCode == GLFW.GLFW_KEY_N) { | ||
this.scroll(1); | ||
this.completed = false; | ||
cir.setReturnValue(true); | ||
cir.cancel(); | ||
} | ||
if ((modifiers & GLFW.GLFW_MOD_CONTROL) > 0 && keyCode == GLFW.GLFW_KEY_P) { | ||
this.scroll(-1); | ||
this.completed = false; | ||
cir.setReturnValue(true); | ||
cir.cancel(); | ||
} | ||
if (keyCode == GLFW.GLFW_KEY_ENTER || keyCode == GLFW.GLFW_KEY_KP_ENTER) { | ||
this.complete(); | ||
cir.setReturnValue(true); | ||
cir.cancel(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.