Reputation: 1
I have been fighting trying to get a fabric mod to work but to no avail. I have followed every tutorial known to man but I always get stuck in the same place.
package net.example;
import net.fabricmc.api.ModInitializer;
import static net.minecraft.server.command.CommandManager.*;
public class ExampleMod implements ModInitializer {
@Override
public void onInitialize() {
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(literal("foo")
.executes(context -> {
// For versions below 1.19, replace "Text.literal" with "new LiteralText".
context.getSource().sendMessage(LiteralText("Called /foo with no arguments"));
return 1;
})));
}
}
with that code this thing tells me that "CommandRegistrationCallback" "cannot be resolved" this is literally the code provided in https://fabricmc.net/wiki/tutorial:commands so I don't know what I'm doing wrong.
Here's my other files:
build.gradle:
plugins {
id 'fabric-loom' version '1.1-SNAPSHOT'
id 'maven-publish'
}
version = project.mod_version
group = project.maven_group
repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
}
dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
// Uncomment the following line to enable the deprecated Fabric API modules.
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.
// modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}"
}
base {
archivesName = project.archives_base_name
}
processResources {
inputs.property "version", project.version
filesMatching("fabric.mod.json") {
expand "version": project.version
}
}
tasks.withType(JavaCompile).configureEach {
// Minecraft 1.18 (1.18-pre2) upwards uses Java 17.
it.options.release = 17
}
java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
jar {
from("LICENSE") {
rename { "${it}_${base.archivesName.get()}"}
}
}
// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
// Notice: This block does NOT have the same function as the block in the top level.
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
}
fabric.mod.json:
{
"schemaVersion": 1,
"id": "example",
"version": "${version}",
"name": "example",
"description": "idk",
"authors": [
"me"
],
"contact": {
},
"license": "CC0-1.0",
"icon": "assets/example/icon.png",
"environment": "*",
"entrypoints": {
"main": [
"net.example.ExampleMod"
]
},
"mixins": [
],
"depends": {
"fabricloader": ">=0.14.17",
"fabric-api": "*",
"minecraft": "~1.19.4",
"java": ">=17"
},
"suggests": {
"another-mod": "*"
}
}
gradle.properties:
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx10G
org.gradle.parallel=true
# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.19.4
yarn_mappings=1.19.4+build.2
loader_version=0.14.19
# Mod Properties
mod_version = 1.0.0
maven_group = net.byescreen
archives_base_name = byescreen
# Dependencies
fabric_version=0.78.0+1.19.4
and here's my folder structure: Folder Structure
I am beyond myself, its 4am and I have achieved nothing. I need the internet's help for this one.
Already have all the latest versions of everything. Well java had version 20 and had to downgrade to the last 17 one. That's about it.
Already rebuilt with gradlew about 200 times, copied an pasted dozens of examples from the internet and nothing works. I always get to the problem that it doesn't find the "CommandRegistrationCallback" or any other class I need to just read the players commands.
Upvotes: 0
Views: 1602
Reputation: 1
It is necessary in>=1.19.4 to register with "CommandManager.literal("test")" instead of "literal("test")". when registering.
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
dispatcher.register(CommandManager.literal("test").executes(context -> {
context.getSource().sendMessage(literal("working"));
return 1;
}));
});
Upvotes: 0