java 运行Fabric Minecraft Mod时遇到问题

dauxcl2d  于 2023-06-04  发布在  Java
关注(0)|答案(1)|浏览(327)

我一直在争取试图让一个面料国防部的工作,但无济于事。我已经遵循了人类所知的每一个教程,但我总是被困在同一个地方。

  1. package net.example;
  2. import net.fabricmc.api.ModInitializer;
  3. import static net.minecraft.server.command.CommandManager.*;
  4. public class ExampleMod implements ModInitializer {
  5. @Override
  6. public void onInitialize() {
  7. CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(literal("foo")
  8. .executes(context -> {
  9. // For versions below 1.19, replace "Text.literal" with "new LiteralText".
  10. context.getSource().sendMessage(LiteralText("Called /foo with no arguments"));
  11. return 1;
  12. })));
  13. }
  14. }

这段代码告诉我“CommandRegistrationCallback”“无法解析”,这是https://fabricmc.net/wiki/tutorial:commands中提供的代码,所以我不知道我做错了什么。
以下是我的其他文件:
build.gradle:

  1. plugins {
  2. id 'fabric-loom' version '1.1-SNAPSHOT'
  3. id 'maven-publish'
  4. }
  5. version = project.mod_version
  6. group = project.maven_group
  7. repositories {
  8. // Add repositories to retrieve artifacts from in here.
  9. // You should only use this when depending on other mods because
  10. // Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
  11. // See https://docs.gradle.org/current/userguide/declaring_repositories.html
  12. // for more information about repositories.
  13. }
  14. dependencies {
  15. // To change the versions see the gradle.properties file
  16. minecraft "com.mojang:minecraft:${project.minecraft_version}"
  17. mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
  18. modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
  19. // Fabric API. This is technically optional, but you probably want it anyway.
  20. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
  21. // Uncomment the following line to enable the deprecated Fabric API modules.
  22. // 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.
  23. // modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}"
  24. }
  25. base {
  26. archivesName = project.archives_base_name
  27. }
  28. processResources {
  29. inputs.property "version", project.version
  30. filesMatching("fabric.mod.json") {
  31. expand "version": project.version
  32. }
  33. }
  34. tasks.withType(JavaCompile).configureEach {
  35. // Minecraft 1.18 (1.18-pre2) upwards uses Java 17.
  36. it.options.release = 17
  37. }
  38. java {
  39. // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
  40. // if it is present.
  41. // If you remove this line, sources will not be generated.
  42. withSourcesJar()
  43. sourceCompatibility = JavaVersion.VERSION_17
  44. targetCompatibility = JavaVersion.VERSION_17
  45. }
  46. jar {
  47. from("LICENSE") {
  48. rename { "${it}_${base.archivesName.get()}"}
  49. }
  50. }
  51. // configure the maven publication
  52. publishing {
  53. publications {
  54. mavenJava(MavenPublication) {
  55. from components.java
  56. }
  57. }
  58. // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
  59. repositories {
  60. // Add repositories to publish to here.
  61. // Notice: This block does NOT have the same function as the block in the top level.
  62. // The repositories here will be used for publishing your artifact, not for
  63. // retrieving dependencies.
  64. }
  65. }

fabric.mod.json:

  1. {
  2. "schemaVersion": 1,
  3. "id": "example",
  4. "version": "${version}",
  5. "name": "example",
  6. "description": "idk",
  7. "authors": [
  8. "me"
  9. ],
  10. "contact": {
  11. },
  12. "license": "CC0-1.0",
  13. "icon": "assets/example/icon.png",
  14. "environment": "*",
  15. "entrypoints": {
  16. "main": [
  17. "net.example.ExampleMod"
  18. ]
  19. },
  20. "mixins": [
  21. ],
  22. "depends": {
  23. "fabricloader": ">=0.14.17",
  24. "fabric-api": "*",
  25. "minecraft": "~1.19.4",
  26. "java": ">=17"
  27. },
  28. "suggests": {
  29. "another-mod": "*"
  30. }
  31. }

gradle.properties:

  1. # Done to increase the memory available to gradle.
  2. org.gradle.jvmargs=-Xmx10G
  3. org.gradle.parallel=true
  4. # Fabric Properties
  5. # check these on https://fabricmc.net/develop
  6. minecraft_version=1.19.4
  7. yarn_mappings=1.19.4+build.2
  8. loader_version=0.14.19
  9. # Mod Properties
  10. mod_version = 1.0.0
  11. maven_group = net.byescreen
  12. archives_base_name = byescreen
  13. # Dependencies
  14. fabric_version=0.78.0+1.19.4

这是我的文件夹结构:Folder Structure
我超越了我自己,凌晨4点,我什么也没做。我需要互联网的帮助。
已经有了所有的最新版本。Java有20版,不得不降级到最后的17版。就这样
已经重建与gradlew约200倍,复制和粘贴几十个例子从互联网上和没有工作。我总是得到的问题,它找不到“CommandRegistrationCallback”或任何其他类,我需要只是阅读球员的命令。

oknrviil

oknrviil1#

在>=1.19.4中必须使用“CommandManager.literal(“test”)”而不是“literal(“test”)"注册。注册时。

  1. CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
  2. dispatcher.register(CommandManager.literal("test").executes(context -> {
  3. context.getSource().sendMessage(literal("working"));
  4. return 1;
  5. }));
  6. });

相关问题