Skip to content

Commit

Permalink
Fix relaying commands in data packs
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisD3D committed Nov 13, 2023
1 parent 8621fbf commit e0b3c65
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package fr.denisd3d.mc2discord.minecraft.mixin;

import com.mojang.brigadier.ParseResults;
import fr.denisd3d.mc2discord.minecraft.Mc2DiscordMinecraft;
import net.minecraft.commands.CommandFunction;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.ServerFunctionManager;
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.CallbackInfoReturnable;

@Mixin(CommandFunction.CommandEntry.class)
public class CommandFunctionCommandEntryMixin {
@Final
@Shadow
private ParseResults<CommandSourceStack> parse;

@Inject(method = "execute(Lnet/minecraft/server/ServerFunctionManager;Lnet/minecraft/commands/CommandSourceStack;)I", at = @At("HEAD"))
private void execute(ServerFunctionManager pFunctionManager, CommandSourceStack pSource, CallbackInfoReturnable<Integer> cir) {
Mc2DiscordMinecraft.onCommand(new ParseResults<>(this.parse.getContext().withSource(pSource), this.parse.getReader(), this.parse.getExceptions()));
}
}
23 changes: 12 additions & 11 deletions mc2discord-1.18.x/common/src/main/resources/mc2discord.mixins.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"required": true,
"minVersion": "0.8",
"package": "fr.denisd3d.mc2discord.minecraft.mixin",
"compatibilityLevel": "JAVA_17",
"refmap": "${modId}.refmap.json",
"mixins": [
"PlayerListMixin"
],
"injectors": {
"defaultRequire": 1
}
"required": true,
"minVersion": "0.8",
"package": "fr.denisd3d.mc2discord.minecraft.mixin",
"compatibilityLevel": "JAVA_17",
"refmap": "${modId}.refmap.json",
"mixins": [
"CommandFunctionCommandEntryMixin",
"PlayerListMixin"
],
"injectors": {
"defaultRequire": 1
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package fr.denisd3d.mc2discord.minecraft.mixin;

import com.mojang.brigadier.ParseResults;
import fr.denisd3d.mc2discord.minecraft.Mc2DiscordMinecraft;
import net.minecraft.commands.CommandFunction;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.server.ServerFunctionManager;
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.CallbackInfoReturnable;

@Mixin(CommandFunction.CommandEntry.class)
public class CommandFunctionCommandEntryMixin {
@Final
@Shadow
private ParseResults<CommandSourceStack> parse;

@Inject(method = "execute(Lnet/minecraft/server/ServerFunctionManager;Lnet/minecraft/commands/CommandSourceStack;)I", at = @At("HEAD"))
private void execute(ServerFunctionManager pFunctionManager, CommandSourceStack pSource, CallbackInfoReturnable<Integer> cir) {
Mc2DiscordMinecraft.onCommand(Commands.mapSource(this.parse, (ignored) -> pSource));
}
}
23 changes: 12 additions & 11 deletions mc2discord-1.19.x/common/src/main/resources/mc2discord.mixins.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"required": true,
"minVersion": "0.8",
"package": "fr.denisd3d.mc2discord.minecraft.mixin",
"compatibilityLevel": "JAVA_17",
"refmap": "${modId}.refmap.json",
"mixins": [
"PlayerListMixin"
],
"injectors": {
"defaultRequire": 1
}
"required": true,
"minVersion": "0.8",
"package": "fr.denisd3d.mc2discord.minecraft.mixin",
"compatibilityLevel": "JAVA_17",
"refmap": "${modId}.refmap.json",
"mixins": [
"CommandFunctionCommandEntryMixin",
"PlayerListMixin"
],
"injectors": {
"defaultRequire": 1
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package fr.denisd3d.mc2discord.minecraft.mixin;

import com.mojang.brigadier.ParseResults;
import fr.denisd3d.mc2discord.minecraft.Mc2DiscordMinecraft;
import net.minecraft.commands.CommandFunction;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.server.ServerFunctionManager;
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.CallbackInfoReturnable;

@Mixin(CommandFunction.CommandEntry.class)
public class CommandFunctionCommandEntryMixin {
@Final
@Shadow
private ParseResults<CommandSourceStack> parse;

@Inject(method = "execute(Lnet/minecraft/server/ServerFunctionManager;Lnet/minecraft/commands/CommandSourceStack;)I", at = @At("HEAD"))
private void execute(ServerFunctionManager pFunctionManager, CommandSourceStack pSource, CallbackInfoReturnable<Integer> cir) {
Mc2DiscordMinecraft.onCommand(Commands.mapSource(this.parse, (ignored) -> pSource));
}
}
23 changes: 12 additions & 11 deletions mc2discord-1.20.x/common/src/main/resources/mc2discord.mixins.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"required": true,
"minVersion": "0.8",
"package": "fr.denisd3d.mc2discord.minecraft.mixin",
"compatibilityLevel": "JAVA_17",
"refmap": "${modId}.refmap.json",
"mixins": [
"PlayerListMixin"
],
"injectors": {
"defaultRequire": 1
}
"required": true,
"minVersion": "0.8",
"package": "fr.denisd3d.mc2discord.minecraft.mixin",
"compatibilityLevel": "JAVA_17",
"refmap": "${modId}.refmap.json",
"mixins": [
"CommandFunctionCommandEntryMixin",
"PlayerListMixin"
],
"injectors": {
"defaultRequire": 1
}
}

0 comments on commit e0b3c65

Please sign in to comment.