My Mixin code:
@Mixin(ClientPlayNetworkHandler.class)
public abstract class ClientPlayNetworkHandlerMixin {
@Shadow public abstract ClientConnection getConnection();
@Inject(method = "<init>", at = @At("RETURN"))
private void onInit(CallbackInfo info) {
System.out.println("ClientPlayNetworkHandler initialized. Connection: " + getConnection());
}
@Overwrite
private void sendResourcePackStatus(ResourcePackStatusC2SPacket.Status packStatus) {
if (this.getConnection() != null && packStatus != null) {
this.getConnection().send(new ResourcePackStatusC2SPacket(packStatus));
System.out.println("test " + packStatus);
} else {
System.err.println("Connection is null, cannot send resource pack status.");
}
}
}
fabric.mod.json:
{
"schemaVersion": 1,
"id": "yesidownloadedyourresourcepack",
"version": "${version}",
"name": "YesIDownloadedYourResourcepack",
"description": "now you wont be kicked from server because you dont want to download his faithful resourcepack",
"authors": [
"TheMixRay"
],
"contact": {
"homepage": "https://fabricmc.net/",
"sources": "https://github.com/FabricMC/fabric-example-mod"
},
"license": "CC0-1.0",
"icon": "assets/yesidownloadedyourresourcepack/icon.png",
"environment": "client",
"entrypoints": {
"client": [
"com.themixray.YesIDownloadedYourResourcepack"
]
},
"mixins": [
"yesidownloadedyourresourcepack.mixins.json"
],
"depends": {
"fabricloader": ">=0.15.7",
"minecraft": "~1.20.1",
"java": ">=17",
"fabric-api": "*"
},
"suggests": {
"another-mod": "*"
}
}
yesidownloadedyourresourcepack.mixins.json:
{
"required": true,
"package": "com.themixray.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"ClientPlayNetworkHandlerMixin"
],
"injectors": {
"defaultRequire": 1
}
}
my folders tree
essentially, when I go to the server and reject/accept a resource pack, I should see it in the console, but in the console I only see this error, which hardly relates to my mod:
[20:28:32] [Worker-Main-3/ERROR]: Caught exception in thread Thread[Worker-Main-3,4,main]
java.lang.NullPointerException: Cannot read field "field_3752" because "$$0" is null
at net.minecraft.class_641.method_44294(class_641.java:157) ~[client-intermediary.jar:?]
at net.minecraft.class_641.method_44090(class_641.java:170) ~[client-intermediary.jar:?]
at net.minecraft.class_3846.method_16907(class_3846.java:91) ~[client-intermediary.jar:?]
at net.minecraft.class_3846.method_16900(class_3846.java:146) ~[client-intermediary.jar:?]
at net.minecraft.class_3846.run(class_3846.java:102) ~[client-intermediary.jar:?]
at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1395) ~[?:?]
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?]
at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?]
at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?]
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?]
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?]
I tried to remove the client
folder and write all my code in main
, but it doesn’t make sense