Fix Mixins

This commit is contained in:
Brady
2020-01-10 18:59:57 -06:00
parent 27cb708d40
commit eb348120d9
3 changed files with 30 additions and 24 deletions
@@ -22,7 +22,7 @@ import baritone.api.event.events.TabCompleteEvent;
import com.mojang.brigadier.context.StringRange; import com.mojang.brigadier.context.StringRange;
import com.mojang.brigadier.suggestion.Suggestion; import com.mojang.brigadier.suggestion.Suggestion;
import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.Suggestions;
import net.minecraft.client.gui.screen.ChatScreen; import net.minecraft.client.gui.CommandSuggestionHelper;
import net.minecraft.client.gui.widget.TextFieldWidget; import net.minecraft.client.gui.widget.TextFieldWidget;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@@ -40,28 +40,28 @@ import java.util.stream.Stream;
* @author Brady * @author Brady
* @since 10/9/2019 * @since 10/9/2019
*/ */
@Mixin(ChatScreen.class) @Mixin(CommandSuggestionHelper.class)
public class MixinChatScreen { public class MixinCommandSuggestionHelper {
@Shadow
protected TextFieldWidget inputField;
//FIXME
/*
@Shadow @Shadow
@Final @Final
protected List<String> commandUsage; private TextFieldWidget field_228095_d_;
@Shadow @Shadow
private CompletableFuture<Suggestions> pendingSuggestions; @Final
private List<String> field_228103_l_;
@Shadow
private CompletableFuture<Suggestions> field_228107_p_;
@Inject( @Inject(
method = "updateSuggestion", method = "func_228111_a_",
at = @At("HEAD"), at = @At("HEAD"),
cancellable = true cancellable = true
) )
private void preUpdateSuggestion(CallbackInfo ci) { private void preUpdateSuggestion(CallbackInfo ci) {
// Anything that is present in the input text before the cursor position // Anything that is present in the input text before the cursor position
String prefix = this.inputField.getText().substring(0, Math.min(this.inputField.getText().length(), this.inputField.getCursorPosition())); String prefix = this.field_228095_d_.getText().substring(0, Math.min(this.field_228095_d_.getText().length(), this.field_228095_d_.getCursorPosition()));
TabCompleteEvent event = new TabCompleteEvent(prefix); TabCompleteEvent event = new TabCompleteEvent(prefix);
BaritoneAPI.getProvider().getPrimaryBaritone().getGameEventHandler().onPreTabComplete(event); BaritoneAPI.getProvider().getPrimaryBaritone().getGameEventHandler().onPreTabComplete(event);
@@ -75,14 +75,14 @@ public class MixinChatScreen {
ci.cancel(); ci.cancel();
// TODO: Support populating the command usage // TODO: Support populating the command usage
this.commandUsage.clear(); this.field_228103_l_.clear();
if (event.completions.length == 0) { if (event.completions.length == 0) {
this.pendingSuggestions = Suggestions.empty(); this.field_228107_p_ = Suggestions.empty();
} else { } else {
int offset = this.inputField.getText().endsWith(" ") int offset = this.field_228095_d_.getText().endsWith(" ")
? this.inputField.getCursorPosition() ? this.field_228095_d_.getCursorPosition()
: this.inputField.getText().lastIndexOf(" ") + 1; // If there is no space this is still 0 haha yes : this.field_228095_d_.getText().lastIndexOf(" ") + 1; // If there is no space this is still 0 haha yes
List<Suggestion> suggestionList = Stream.of(event.completions) List<Suggestion> suggestionList = Stream.of(event.completions)
.map(s -> new Suggestion(StringRange.between(offset, offset + s.length()), s)) .map(s -> new Suggestion(StringRange.between(offset, offset + s.length()), s))
@@ -92,9 +92,9 @@ public class MixinChatScreen {
StringRange.between(offset, offset + suggestionList.stream().mapToInt(s -> s.getText().length()).max().orElse(0)), StringRange.between(offset, offset + suggestionList.stream().mapToInt(s -> s.getText().length()).max().orElse(0)),
suggestionList); suggestionList);
this.pendingSuggestions = new CompletableFuture<>(); this.field_228107_p_ = new CompletableFuture<>();
this.pendingSuggestions.complete(suggestions); this.field_228107_p_.complete(suggestions);
} }
} }
}*/ }
} }
@@ -19,6 +19,7 @@ package baritone.launch.mixins;
import baritone.api.BaritoneAPI; import baritone.api.BaritoneAPI;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.event.events.BlockInteractEvent;
import baritone.api.event.events.TickEvent; import baritone.api.event.events.TickEvent;
import baritone.api.event.events.WorldEvent; import baritone.api.event.events.WorldEvent;
import baritone.api.event.events.type.EventState; import baritone.api.event.events.type.EventState;
@@ -27,6 +28,10 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.world.ClientWorld; import net.minecraft.client.world.ClientWorld;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockRayTraceResult;
import org.spongepowered.asm.lib.Opcodes; import org.spongepowered.asm.lib.Opcodes;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
@@ -34,6 +39,7 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import java.util.function.BiFunction; import java.util.function.BiFunction;
@@ -138,18 +144,18 @@ public class MixinMinecraft {
// allow user input is only the primary baritone // allow user input is only the primary baritone
return (BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().getCurrent() != null && player != null) || screen.passEvents; return (BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().getCurrent() != null && player != null) || screen.passEvents;
} }
//FIXME stupid LVT
/*
@Inject( @Inject(
method = "rightClickMouse", method = "rightClickMouse",
at = @At( at = @At(
value = "INVOKE", value = "INVOKE",
target = "net/minecraft/client/entity/player/ClientPlayerEntity.swingArm(Lnet/minecraft/util/Hand;)V" target = "net/minecraft/client/entity/player/ClientPlayerEntity.swingArm(Lnet/minecraft/util/Hand;)V",
ordinal = 1
), ),
locals = LocalCapture.CAPTURE_FAILHARD locals = LocalCapture.CAPTURE_FAILHARD
) )
private void onBlockUse(CallbackInfo ci, Hand var1[], int var2, int var3, Hand enumhand, ItemStack itemstack, BlockRayTraceResult raytrace, int i, ActionResultType enumactionresult) { private void onBlockUse(CallbackInfo ci, Hand var1[], int var2, int var3, Hand enumhand, ItemStack itemstack, BlockRayTraceResult raytrace, int i, ActionResultType enumactionresult) {
// rightClickMouse is only for the main player // rightClickMouse is only for the main player
BaritoneAPI.getProvider().getPrimaryBaritone().getGameEventHandler().onBlockInteract(new BlockInteractEvent(raytrace.getPos(), BlockInteractEvent.Type.USE)); BaritoneAPI.getProvider().getPrimaryBaritone().getGameEventHandler().onBlockInteract(new BlockInteractEvent(raytrace.getPos(), BlockInteractEvent.Type.USE));
}*/ }
} }
+1 -1
View File
@@ -9,7 +9,7 @@
}, },
"client": [ "client": [
"MixinBitArray", "MixinBitArray",
"MixinChatScreen", "MixinCommandSuggestionHelper",
"MixinChunkArray", "MixinChunkArray",
"MixinClientChunkProvider", "MixinClientChunkProvider",
"MixinClientPlayerEntity", "MixinClientPlayerEntity",