mirror of
https://github.com/System-End/Discord-MC-Chat.git
synced 2026-04-19 19:45:14 +00:00
Mixin测试
This commit is contained in:
parent
f61c2725b3
commit
f25f40b2d4
15 changed files with 235 additions and 52 deletions
|
|
@ -12,15 +12,15 @@ dependencies {
|
|||
exclude module: "opus-java" // for encoding audio into opus
|
||||
exclude module: "tink" // for encrypting and decrypting audio
|
||||
exclude module: "slf4j-api"
|
||||
exclude module: "jackson-core"
|
||||
exclude module: "jackson-databind"
|
||||
exclude module: "jackson-annotations"
|
||||
// exclude module: "jackson-core"
|
||||
// exclude module: "jackson-databind"
|
||||
// exclude module: "jackson-annotations"
|
||||
}
|
||||
|
||||
shadow("org.slf4j:slf4j-api:2.0.17")
|
||||
|
||||
shadow("com.fasterxml.jackson.core:jackson-databind:2.19.2")
|
||||
shadow("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.19.2")
|
||||
// shadow("com.fasterxml.jackson.core:jackson-databind:2.19.2")
|
||||
// shadow("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.19.2")
|
||||
}
|
||||
|
||||
neoForge {
|
||||
|
|
|
|||
|
|
@ -20,8 +20,10 @@ public class DMCC {
|
|||
}
|
||||
|
||||
public static void init(String loader, String version) {
|
||||
VERSION = version;
|
||||
new Thread(() -> {
|
||||
VERSION = version;
|
||||
|
||||
LOGGER.info("Initializing DMCC {} with loader: {}", VERSION, loader);
|
||||
LOGGER.info("Initializing DMCC {} with loader: {}", VERSION, loader);
|
||||
}, "DMCC-Main").start();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
package com.xujiayao.discord_mc_chat.common.mixins;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
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 static com.xujiayao.discord_mc_chat.common.DMCC.LOGGER;
|
||||
|
||||
/**
|
||||
* @author Xujiayao
|
||||
*/
|
||||
@Mixin(MinecraftServer.class)
|
||||
public class MixinMinecraftServer {
|
||||
@Inject(at = @At("HEAD"), method = "loadLevel")
|
||||
private void init(CallbackInfo info) {
|
||||
// This code is injected into the start of MinecraftServer.loadLevel()V
|
||||
LOGGER.info("This line is printed by an example mod mixin!");
|
||||
}
|
||||
}
|
||||
2
common/src/main/resources/config/config.yml
Normal file
2
common/src/main/resources/config/config.yml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
# Discord-MC-Chat Configuration File
|
||||
language: en_us
|
||||
|
|
@ -38,26 +38,6 @@ jar {
|
|||
inputs.property "archivesName", base.archivesName
|
||||
}
|
||||
|
||||
//========== Fabric Mixins ==========
|
||||
|
||||
def commonMixins = file("../common/src/main/java/com/xujiayao/discord_mc_chat/common/mixins")
|
||||
def fabricMixins = file("src/main/java/com/xujiayao/discord_mc_chat/common/mixins")
|
||||
def fabricCommon = file("src/main/java/com/xujiayao/discord_mc_chat/common")
|
||||
|
||||
tasks.compileJava.doFirst {
|
||||
if (commonMixins.exists()) {
|
||||
ant.copy(todir: fabricMixins) {
|
||||
fileset(dir: commonMixins)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.compileJava.doLast {
|
||||
if (fabricCommon.exists()) {
|
||||
ant.delete(dir: fabricCommon)
|
||||
}
|
||||
}
|
||||
|
||||
loom {
|
||||
mixin {
|
||||
defaultRefmapName = "fabric.dmcc.refmap.json"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
package com.xujiayao.discord_mc_chat.fabric.mixins;
|
||||
|
||||
import net.minecraft.advancements.AdvancementHolder;
|
||||
import net.minecraft.server.PlayerAdvancements;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
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;
|
||||
|
||||
import static com.xujiayao.discord_mc_chat.common.DMCC.LOGGER;
|
||||
|
||||
/**
|
||||
* @author Xujiayao
|
||||
*/
|
||||
@Mixin(PlayerAdvancements.class)
|
||||
public class MixinPlayerAdvancements {
|
||||
|
||||
@Shadow
|
||||
private ServerPlayer player;
|
||||
|
||||
@Inject(method = "award", at = @At(value = "INVOKE", target = "Lnet/minecraft/advancements/AdvancementRewards;grant(Lnet/minecraft/server/level/ServerPlayer;)V", shift = At.Shift.AFTER))
|
||||
private void award(AdvancementHolder advancementHolder, String string, CallbackInfoReturnable<Boolean> cir) {
|
||||
// PlayerAdvancement Event
|
||||
LOGGER.info("Player {} has made the advancement {}", player.getName().getString(), advancementHolder.value().name());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.xujiayao.discord_mc_chat.fabric.mixins;
|
||||
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.CommonListenerCookie;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
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 static com.xujiayao.discord_mc_chat.common.DMCC.LOGGER;
|
||||
|
||||
/**
|
||||
* @author Xujiayao
|
||||
*/
|
||||
@Mixin(PlayerList.class)
|
||||
public class MixinPlayerList {
|
||||
|
||||
@Inject(method = "placeNewPlayer", at = @At("RETURN"))
|
||||
private void placeNewPlayer(Connection connection, ServerPlayer serverPlayer, CommonListenerCookie commonListenerCookie, CallbackInfo ci) {
|
||||
// PlayerJoin Event
|
||||
LOGGER.info("Player {} joined the game", serverPlayer.getName().getString());
|
||||
}
|
||||
|
||||
@Inject(method = "remove", at = @At("HEAD"))
|
||||
private void remove(ServerPlayer serverPlayer, CallbackInfo ci) {
|
||||
// PlayerQuit Event
|
||||
LOGGER.info("Player {} left the game", serverPlayer.getName().getString());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package com.xujiayao.discord_mc_chat.fabric.mixins;
|
||||
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.arguments.MessageArgument;
|
||||
import net.minecraft.server.commands.SayCommand;
|
||||
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.CallbackInfoReturnable;
|
||||
|
||||
import static com.xujiayao.discord_mc_chat.common.DMCC.LOGGER;
|
||||
|
||||
/**
|
||||
* @author Xujiayao
|
||||
*/
|
||||
@Mixin(SayCommand.class)
|
||||
public class MixinSayCommand {
|
||||
|
||||
@Inject(method = "method_13563", at = @At("HEAD"))
|
||||
private static void method_13563(CommandContext<CommandSourceStack> commandContext, CallbackInfoReturnable<Integer> cir) {
|
||||
// PlayerSay Event
|
||||
LOGGER.info("Player {} said: {}", commandContext.getSource().getTextName(), commandContext.getArgument("message", MessageArgument.class));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package com.xujiayao.discord_mc_chat.fabric.mixins;
|
||||
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
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 static com.xujiayao.discord_mc_chat.common.DMCC.LOGGER;
|
||||
|
||||
/**
|
||||
* @author Xujiayao
|
||||
*/
|
||||
@Mixin(ServerPlayer.class)
|
||||
public class MixinServerPlayer {
|
||||
|
||||
@Inject(method = "die", at = @At("HEAD"))
|
||||
private void die(DamageSource damageSource, CallbackInfo ci) {
|
||||
// PlayerDie Event
|
||||
LOGGER.info("Player {} has died", ((ServerPlayer) (Object) this).getName().getString());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,12 @@
|
|||
{
|
||||
"required": true,
|
||||
"package": "com.xujiayao.discord_mc_chat.common.mixins",
|
||||
"package": "com.xujiayao.discord_mc_chat.fabric.mixins",
|
||||
"compatibilityLevel": "JAVA_21",
|
||||
"mixins": [
|
||||
"MixinMinecraftServer"
|
||||
"MixinPlayerAdvancements",
|
||||
"MixinPlayerList",
|
||||
"MixinSayCommand",
|
||||
"MixinServerPlayer"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
package com.xujiayao.discord_mc_chat.neoforge.mixins;
|
||||
|
||||
import net.minecraft.advancements.AdvancementHolder;
|
||||
import net.minecraft.server.PlayerAdvancements;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
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;
|
||||
|
||||
import static com.xujiayao.discord_mc_chat.common.DMCC.LOGGER;
|
||||
|
||||
/**
|
||||
* @author Xujiayao
|
||||
*/
|
||||
@Mixin(PlayerAdvancements.class)
|
||||
public class MixinPlayerAdvancements {
|
||||
|
||||
@Shadow
|
||||
private ServerPlayer player;
|
||||
|
||||
@Inject(method = "award", at = @At(value = "INVOKE", target = "Lnet/minecraft/advancements/AdvancementRewards;grant(Lnet/minecraft/server/level/ServerPlayer;)V", shift = At.Shift.AFTER))
|
||||
private void award(AdvancementHolder advancementHolder, String string, CallbackInfoReturnable<Boolean> cir) {
|
||||
// PlayerAdvancement Event
|
||||
LOGGER.info("Player {} has made the advancement {}", player.getName().getString(), advancementHolder.value().name());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.xujiayao.discord_mc_chat.neoforge.mixins;
|
||||
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.CommonListenerCookie;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
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 static com.xujiayao.discord_mc_chat.common.DMCC.LOGGER;
|
||||
|
||||
/**
|
||||
* @author Xujiayao
|
||||
*/
|
||||
@Mixin(PlayerList.class)
|
||||
public class MixinPlayerList {
|
||||
|
||||
@Inject(method = "placeNewPlayer", at = @At("RETURN"))
|
||||
private void placeNewPlayer(Connection connection, ServerPlayer serverPlayer, CommonListenerCookie commonListenerCookie, CallbackInfo ci) {
|
||||
// PlayerJoin Event
|
||||
LOGGER.info("Player {} joined the game", serverPlayer.getName().getString());
|
||||
}
|
||||
|
||||
@Inject(method = "remove", at = @At("HEAD"))
|
||||
private void remove(ServerPlayer serverPlayer, CallbackInfo ci) {
|
||||
// PlayerQuit Event
|
||||
LOGGER.info("Player {} left the game", serverPlayer.getName().getString());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package com.xujiayao.discord_mc_chat.neoforge.mixins;
|
||||
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.arguments.MessageArgument;
|
||||
import net.minecraft.server.commands.SayCommand;
|
||||
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.CallbackInfoReturnable;
|
||||
|
||||
import static com.xujiayao.discord_mc_chat.common.DMCC.LOGGER;
|
||||
|
||||
/**
|
||||
* @author Xujiayao
|
||||
*/
|
||||
@Mixin(SayCommand.class)
|
||||
public class MixinSayCommand {
|
||||
|
||||
@Inject(method = "lambda$register$1", at = @At("HEAD"))
|
||||
private static void lambda$register$1(CommandContext<CommandSourceStack> commandContext, CallbackInfoReturnable<Integer> cir) {
|
||||
// PlayerSay Event
|
||||
LOGGER.info("Player {} said: {}", commandContext.getSource().getTextName(), commandContext.getArgument("message", MessageArgument.class));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package com.xujiayao.discord_mc_chat.neoforge.mixins;
|
||||
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
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 static com.xujiayao.discord_mc_chat.common.DMCC.LOGGER;
|
||||
|
||||
/**
|
||||
* @author Xujiayao
|
||||
*/
|
||||
@Mixin(ServerPlayer.class)
|
||||
public class MixinServerPlayer {
|
||||
|
||||
@Inject(method = "die", at = @At("HEAD"))
|
||||
private void die(DamageSource damageSource, CallbackInfo ci) {
|
||||
// PlayerDie Event
|
||||
LOGGER.info("Player {} has died", ((ServerPlayer) (Object) this).getName().getString());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,12 @@
|
|||
{
|
||||
"required": true,
|
||||
"package": "com.xujiayao.discord_mc_chat.common.mixins",
|
||||
"package": "com.xujiayao.discord_mc_chat.neoforge.mixins",
|
||||
"compatibilityLevel": "JAVA_21",
|
||||
"mixins": [
|
||||
"MixinMinecraftServer"
|
||||
"MixinPlayerAdvancements",
|
||||
"MixinPlayerList",
|
||||
"MixinSayCommand",
|
||||
"MixinServerPlayer"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue