diff --git a/build.gradle b/build.gradle index ce9275b..3fec5ff 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '0.2.5-SNAPSHOT' + id 'fabric-loom' version '0.2.6-SNAPSHOT' id 'maven-publish' } @@ -14,7 +14,7 @@ minecraft { dependencies { minecraft "com.mojang:minecraft:${project.minecraftVersion}" - mappings "net.fabricmc:yarn:${project.yarnMappings}" + mappings "net.fabricmc:yarn:${project.yarnMappings}:v2" modCompile "net.fabricmc:fabric-loader:${project.loaderVersion}" } diff --git a/gradle.properties b/gradle.properties index ad3c891..ed5764e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,10 +2,10 @@ org.gradle.jvmargs=-Xmx4G # Fabric Properties # check these on https://fabricmc.net/use -minecraftVersion=19w38b -yarnMappings=19w38b+build.4 -loaderVersion=0.6.2+build.166 +minecraftVersion=19w46b +yarnMappings=19w46b+build.1 +loaderVersion=0.6.4+build.169 # Mod Properties -modVersion=0.2.0 +modVersion=0.3.0 mavenGroup=com.github.liachmodded archivesBaseName=pathsuggestion diff --git a/src/main/java/com/github/liachmodded/pathsuggestion/PathSuggestion.java b/src/main/java/com/github/liachmodded/pathsuggestion/PathSuggestion.java index 42f1825..eb6256a 100644 --- a/src/main/java/com/github/liachmodded/pathsuggestion/PathSuggestion.java +++ b/src/main/java/com/github/liachmodded/pathsuggestion/PathSuggestion.java @@ -4,7 +4,7 @@ import com.mojang.brigadier.suggestion.Suggestion; import com.mojang.brigadier.suggestion.Suggestions; import java.util.ArrayList; -import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.ListIterator; import net.minecraft.text.Text; @@ -16,16 +16,21 @@ public final class PathSuggestion { private static final char[] SEPARATORS = new char[]{'.', ':', '/'}; + private static final Comparator SUGGESTION_COMPARATOR = (a, b) -> { + boolean l = a instanceof ShrinkedSuggestion; + boolean r = b instanceof ShrinkedSuggestion; + return l == r ? a.compareTo(b) : l ? -1 : 1; + }; private PathSuggestion() {} public static void shrinkSuggestions(Suggestions suggestions) { final List entries = suggestions.getList(); - Collections.sort(entries); + entries.sort(null); final int sharedPrefix = getCommonPrefix(entries.get(0).getText(), entries.get(entries.size() - 1).getText(), 0); - final List updated = new ArrayList<>(); + final List updated = new ArrayList<>(entries.size()); final ListIterator iterator = entries.listIterator(); while (iterator.hasNext()) { final Suggestion current = iterator.next(); @@ -71,6 +76,8 @@ public static void shrinkSuggestions(Suggestions suggestions) { } } + updated.sort(SUGGESTION_COMPARATOR); + entries.clear(); entries.addAll(updated); } diff --git a/src/main/java/com/github/liachmodded/pathsuggestion/RefreshableCommandSuggestor.java b/src/main/java/com/github/liachmodded/pathsuggestion/RefreshableCommandSuggestor.java new file mode 100644 index 0000000..1bf812b --- /dev/null +++ b/src/main/java/com/github/liachmodded/pathsuggestion/RefreshableCommandSuggestor.java @@ -0,0 +1,7 @@ +package com.github.liachmodded.pathsuggestion; + +public interface RefreshableCommandSuggestor { + + void refresh(); + +} diff --git a/src/main/java/com/github/liachmodded/pathsuggestion/mixin/ChatScreenAccessor.java b/src/main/java/com/github/liachmodded/pathsuggestion/mixin/ChatScreenAccessor.java deleted file mode 100644 index a9f508c..0000000 --- a/src/main/java/com/github/liachmodded/pathsuggestion/mixin/ChatScreenAccessor.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.github.liachmodded.pathsuggestion.mixin; - -import net.minecraft.client.gui.screen.ChatScreen; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Invoker; - -@Mixin(ChatScreen.class) -public interface ChatScreenAccessor { - - @Invoker - void callUpdateCommand(); -} diff --git a/src/main/java/com/github/liachmodded/pathsuggestion/mixin/ChatScreenMixin.java b/src/main/java/com/github/liachmodded/pathsuggestion/mixin/ChatScreenMixin.java deleted file mode 100644 index bba85f9..0000000 --- a/src/main/java/com/github/liachmodded/pathsuggestion/mixin/ChatScreenMixin.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.github.liachmodded.pathsuggestion.mixin; - -import com.github.liachmodded.pathsuggestion.PathSuggestion; -import com.mojang.brigadier.suggestion.Suggestions; -import net.minecraft.client.gui.screen.ChatScreen; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -@Mixin(ChatScreen.class) -public abstract class ChatScreenMixin { - - @Inject(method = "showSuggestions()V", at = @At(value = "INVOKE", target = "Lcom/mojang/brigadier/suggestion/Suggestions;getList()Ljava/util/List;", remap = false, ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD) - public void onCreatingSuggestionsWindow(CallbackInfo ci, int maxWidth, Suggestions suggestions) { - if (!suggestions.isEmpty()) { - PathSuggestion.shrinkSuggestions(suggestions); - } - } -} diff --git a/src/main/java/com/github/liachmodded/pathsuggestion/mixin/ChatScreenSuggestionWindowMixin.java b/src/main/java/com/github/liachmodded/pathsuggestion/mixin/ChatScreenSuggestionWindowMixin.java deleted file mode 100644 index 22dcb10..0000000 --- a/src/main/java/com/github/liachmodded/pathsuggestion/mixin/ChatScreenSuggestionWindowMixin.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.github.liachmodded.pathsuggestion.mixin; - -import com.github.liachmodded.pathsuggestion.ShrinkedSuggestion; -import com.mojang.brigadier.suggestion.Suggestion; -import net.minecraft.client.gui.screen.ChatScreen; -import org.spongepowered.asm.mixin.Final; -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.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -@Mixin(targets = "net/minecraft/client/gui/screen/ChatScreen$SuggestionWindow") -public abstract class ChatScreenSuggestionWindowMixin { - - @Shadow(aliases = {"field_2397", "this$0"}) // javap the class to check out the field name! - @Final - private ChatScreen field_2397; - - @Shadow - public abstract void close(); - - @Inject(method = "complete()V", - at = @At("RETURN"), - locals = LocalCapture.CAPTURE_FAILHARD) - public void onComplete(CallbackInfo ci, Suggestion suggestion, int cursor) { - if (suggestion instanceof ShrinkedSuggestion) { - close(); - ((ChatScreenAccessor) field_2397).callUpdateCommand(); - } - } -} diff --git a/src/main/java/com/github/liachmodded/pathsuggestion/mixin/CommandScreenAccessor.java b/src/main/java/com/github/liachmodded/pathsuggestion/mixin/CommandScreenAccessor.java deleted file mode 100644 index 114a8a5..0000000 --- a/src/main/java/com/github/liachmodded/pathsuggestion/mixin/CommandScreenAccessor.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.github.liachmodded.pathsuggestion.mixin; - -import net.minecraft.client.gui.screen.ingame.AbstractCommandBlockScreen; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Invoker; - -@Mixin(AbstractCommandBlockScreen.class) -public interface CommandScreenAccessor { - - @Invoker - void callUpdateCommand(); -} diff --git a/src/main/java/com/github/liachmodded/pathsuggestion/mixin/CommandScreenMixin.java b/src/main/java/com/github/liachmodded/pathsuggestion/mixin/CommandScreenMixin.java deleted file mode 100644 index 22c8b5a..0000000 --- a/src/main/java/com/github/liachmodded/pathsuggestion/mixin/CommandScreenMixin.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.github.liachmodded.pathsuggestion.mixin; - -import com.github.liachmodded.pathsuggestion.PathSuggestion; -import com.mojang.brigadier.suggestion.Suggestions; -import net.minecraft.client.gui.screen.ingame.AbstractCommandBlockScreen; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -@Mixin(AbstractCommandBlockScreen.class) -public abstract class CommandScreenMixin { - - @Inject(method = "showSuggestions()V", at = @At(value = "INVOKE", target = "Lcom/mojang/brigadier/suggestion/Suggestions;isEmpty()Z", remap = false), locals = LocalCapture.CAPTURE_FAILHARD) - public void onCreatingSuggestionWindow(CallbackInfo ci, Suggestions suggestions) { - if (!suggestions.isEmpty()) { - PathSuggestion.shrinkSuggestions(suggestions); - } - } -} diff --git a/src/main/java/com/github/liachmodded/pathsuggestion/mixin/CommandSuggestorMixin.java b/src/main/java/com/github/liachmodded/pathsuggestion/mixin/CommandSuggestorMixin.java new file mode 100644 index 0000000..35cb4cd --- /dev/null +++ b/src/main/java/com/github/liachmodded/pathsuggestion/mixin/CommandSuggestorMixin.java @@ -0,0 +1,35 @@ +package com.github.liachmodded.pathsuggestion.mixin; + +import com.github.liachmodded.pathsuggestion.PathSuggestion; +import com.github.liachmodded.pathsuggestion.RefreshableCommandSuggestor; +import com.mojang.brigadier.suggestion.Suggestions; +import net.minecraft.client.gui.screen.CommandSuggestor; +import org.spongepowered.asm.mixin.Implements; +import org.spongepowered.asm.mixin.Interface; +import org.spongepowered.asm.mixin.Intrinsic; +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.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +@Mixin(CommandSuggestor.class) +@Implements(@Interface(iface = RefreshableCommandSuggestor.class, prefix = "refreshable$")) +public abstract class CommandSuggestorMixin { + + @Shadow + public abstract void refresh(); + + @Inject(method = "showSuggestions(Z)V", at = @At(value = "INVOKE", target = "Lcom/mojang/brigadier/suggestion/Suggestions;isEmpty()Z", remap = false), locals = LocalCapture.CAPTURE_FAILHARD) + public void onCreatingSuggestionWindow(boolean showFirstSuggestion, CallbackInfo ci, Suggestions suggestions) { + if (!suggestions.isEmpty()) { + PathSuggestion.shrinkSuggestions(suggestions); + } + } + + @Intrinsic + public void refreshable$refresh() { + this.refresh(); + } +} diff --git a/src/main/java/com/github/liachmodded/pathsuggestion/mixin/CommandScreenSuggestionWindowMixin.java b/src/main/java/com/github/liachmodded/pathsuggestion/mixin/CommandSuggestorWindowMixin.java similarity index 65% rename from src/main/java/com/github/liachmodded/pathsuggestion/mixin/CommandScreenSuggestionWindowMixin.java rename to src/main/java/com/github/liachmodded/pathsuggestion/mixin/CommandSuggestorWindowMixin.java index ac7a155..73b8e07 100644 --- a/src/main/java/com/github/liachmodded/pathsuggestion/mixin/CommandScreenSuggestionWindowMixin.java +++ b/src/main/java/com/github/liachmodded/pathsuggestion/mixin/CommandSuggestorWindowMixin.java @@ -1,8 +1,9 @@ package com.github.liachmodded.pathsuggestion.mixin; +import com.github.liachmodded.pathsuggestion.RefreshableCommandSuggestor; import com.github.liachmodded.pathsuggestion.ShrinkedSuggestion; import com.mojang.brigadier.suggestion.Suggestion; -import net.minecraft.client.gui.screen.ingame.AbstractCommandBlockScreen; +import net.minecraft.client.gui.screen.CommandSuggestor; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -11,23 +12,23 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -@Mixin(targets = "net/minecraft/client/gui/screen/ingame/AbstractCommandBlockScreen$SuggestionWindow") -public abstract class CommandScreenSuggestionWindowMixin { +@Mixin(CommandSuggestor.SuggestionWindow.class) +public abstract class CommandSuggestorWindowMixin { - @Shadow(aliases = {"field_2770", "this$0"}) // see chat screen one + @Shadow(aliases = {"field_21615", "this$0"}) @Final - private AbstractCommandBlockScreen field_2770; + private CommandSuggestor field_21615; @Shadow public abstract void discard(); @Inject(method = "complete()V", - at = @At("RETURN"), + at = @At("TAIL"), locals = LocalCapture.CAPTURE_FAILHARD) public void onComplete(CallbackInfo ci, Suggestion suggestion, int cursor) { if (suggestion instanceof ShrinkedSuggestion) { discard(); - ((CommandScreenAccessor) field_2770).callUpdateCommand(); + ((RefreshableCommandSuggestor) field_21615).refresh(); } } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 04251f6..c17ebf2 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -19,6 +19,7 @@ "pathsuggestion.mixins.json" ], "depends": { - "fabricloader": ">=0.4.0" + "fabricloader": ">=0.6.3", + "minecraft": ">=1.15-alpha.19.46.b" } } diff --git a/src/main/resources/pathsuggestion.mixins.json b/src/main/resources/pathsuggestion.mixins.json index 3587754..c76f4bd 100644 --- a/src/main/resources/pathsuggestion.mixins.json +++ b/src/main/resources/pathsuggestion.mixins.json @@ -3,12 +3,8 @@ "package": "com.github.liachmodded.pathsuggestion.mixin", "compatibilityLevel": "JAVA_8", "client": [ - "ChatScreenAccessor", - "ChatScreenMixin", - "ChatScreenSuggestionWindowMixin", - "CommandScreenAccessor", - "CommandScreenMixin", - "CommandScreenSuggestionWindowMixin" + "CommandSuggestorMixin", + "CommandSuggestorWindowMixin" ], "injectors": { "defaultRequire": 1