Skip to content

Commit

Permalink
Updated to 23w41a
Browse files Browse the repository at this point in the history
Signed-off-by: shedaniel <[email protected]>
  • Loading branch information
shedaniel committed Oct 17, 2023
1 parent 731a772 commit c0d6cb9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,34 @@
package dev.architectury.mixin.fabric;

import com.google.common.base.Throwables;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.ParseResults;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.architectury.event.events.common.CommandPerformEvent;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(Commands.class)
public class MixinCommands {
@Redirect(method = "performCommand",
at = @At(value = "INVOKE", target = "Lcom/mojang/brigadier/CommandDispatcher;execute(Lcom/mojang/brigadier/ParseResults;)I", remap = false))
private int performCommand(CommandDispatcher<CommandSourceStack> dispatcher, ParseResults<CommandSourceStack> results) throws CommandSyntaxException {
@ModifyVariable(method = "performCommand",
at = @At(value = "INVOKE", target = "Lnet/minecraft/commands/Commands;validateParseResults(Lcom/mojang/brigadier/ParseResults;)V", remap = false), argsOnly = true)
private ParseResults<CommandSourceStack> performCommand(ParseResults<CommandSourceStack> results) {
var event = new CommandPerformEvent(results, null);
if (CommandPerformEvent.EVENT.invoker().act(event).isPresent()) {
if (event.getThrowable() != null) {
Throwables.throwIfUnchecked(event.getThrowable());
}
return 1;
return null;
}
return dispatcher.execute(event.getResults());
return event.getResults();
}

@Inject(method = "performCommand",
at = @At(value = "INVOKE", target = "Lnet/minecraft/commands/Commands;validateParseResults(Lcom/mojang/brigadier/ParseResults;)V", remap = false), cancellable = true)
private void performCommand(ParseResults<CommandSourceStack> results, String command, CallbackInfo ci) {
if (results == null) ci.cancel();
}
}
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ org.gradle.daemon=false

platforms=fabric

minecraft_version=23w40a
supported_version=23w40a
minecraft_version=23w41a
supported_version=23w41a

artifact_type=beta

Expand All @@ -14,7 +14,7 @@ base_version=11.0
maven_group=dev.architectury

fabric_loader_version=0.14.23
fabric_api_version=0.89.4+1.20.3
fabric_api_version=0.90.1+1.20.3
mod_menu_version=7.0.0

forge_version=48.0.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public static void debugEvents() {
return EventResult.interruptTrue();
});
CommandPerformEvent.EVENT.register(event -> {
if (event.getResults().getReader().getString().startsWith("help")) {
TestMod.SINK.accept("Cancelling help command as a test!");
return EventResult.interruptFalse();
}

TestMod.SINK.accept("Server command performed: " + event.getResults().getReader().getString());
return EventResult.pass();
});
Expand Down

0 comments on commit c0d6cb9

Please sign in to comment.