Skip to content

Commit

Permalink
Update to 19w46b
Browse files Browse the repository at this point in the history
Also sort the shrinked directories to the top of the suggestion list (like in file viewers)

46b changed the exact code I am modifying so this one doesn't work on 46a

Signed-off-by: liach <[email protected]>
  • Loading branch information
liach committed Nov 15, 2019
1 parent 10c3fab commit e042515
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 122 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.2.5-SNAPSHOT'
id 'fabric-loom' version '0.2.6-SNAPSHOT'
id 'maven-publish'
}

Expand All @@ -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}"
}

Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,16 +16,21 @@
public final class PathSuggestion {

private static final char[] SEPARATORS = new char[]{'.', ':', '/'};
private static final Comparator<Suggestion> 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<Suggestion> 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<Suggestion> updated = new ArrayList<>();
final List<Suggestion> updated = new ArrayList<>(entries.size());
final ListIterator<Suggestion> iterator = entries.listIterator();
while (iterator.hasNext()) {
final Suggestion current = iterator.next();
Expand Down Expand Up @@ -71,6 +76,8 @@ public static void shrinkSuggestions(Suggestions suggestions) {
}
}

updated.sort(SUGGESTION_COMPARATOR);

entries.clear();
entries.addAll(updated);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.liachmodded.pathsuggestion;

public interface RefreshableCommandSuggestor {

void refresh();

}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
}
}
}
3 changes: 2 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"pathsuggestion.mixins.json"
],
"depends": {
"fabricloader": ">=0.4.0"
"fabricloader": ">=0.6.3",
"minecraft": ">=1.15-alpha.19.46.b"
}
}
8 changes: 2 additions & 6 deletions src/main/resources/pathsuggestion.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e042515

Please sign in to comment.