Jump to content

Forge 1.21 - 51.0.1 | Config.java uses ResourceLocation, but it is set to private.


Garutako

Recommended Posts

I am learning how to create my first mod. I have followed the first page of the following tutorial up to the Building and Testing Your Mod section: https://docs.minecraftforge.net/en/1.20.x/gettingstarted/

The Config.java class that is bundled in the MDK download uses the ResourceLocation.java class in two locations:

    private static boolean validateItemName(final Object obj)
    {
        return obj instanceof final String itemName && ForgeRegistries.ITEMS.containsKey(new ResourceLocation(itemName)); // <-----
    }

	/* ... */

    static void onLoad(final ModConfigEvent event)
    {
      /* ... */
        items = ITEM_STRINGS.get().stream()
                .map(itemName -> ForgeRegistries.ITEMS.getValue(new ResourceLocation(itemName))) // <-----
                .collect(Collectors.toSet());
    }

However, new ResourceLocation is underlined red on my Intellij IDE, with this popup when hovered on:

'ResourceLocation(java.lang.String, java.lang.String)' has private access in 'net.minecraft.resources.ResourceLocation'

With this being RecourceLocation's constructor

    private ResourceLocation(String p_135811_, String p_135812_) {
        assert isValidNamespace(p_135811_);

        assert isValidPath(p_135812_);

        this.namespace = p_135811_;
        this.path = p_135812_;
    }

In addition, this is the error that pops up while running the build task

error: constructor ResourceLocation in class ResourceLocation cannot be applied to given types;
        return obj instanceof final String itemName && ForgeRegistries.ITEMS.containsKey(new ResourceLocation(itemName));
                                                                                         ^
  required: String,String
  found:    String

What steps would I have to follow to follow to fix this?

Link to comment
Share on other sites

Use the static methods in ResourceLocation to create an instance.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

If you want to access Resource from Minecraft, use:

ResourceLocation.withDefaultNamespace("potato"); or

If you want to access Resource from your mod, use:

ResourceLocation.fromNamespaceAndPath("your_mod_id", "your_key");

Link to comment
Share on other sites

On 6/13/2024 at 6:20 PM, Garutako said:

I am learning how to create my first mod. I have followed the first page of the following tutorial up to the Building and Testing Your Mod section: https://docs.minecraftforge.net/en/1.20.x/gettingstarted/

The Config.java class that is bundled in the MDK download uses the ResourceLocation.java class in two locations:

    private static boolean validateItemName(final Object obj)
    {
        return obj instanceof final String itemName && ForgeRegistries.ITEMS.containsKey(new ResourceLocation(itemName)); // <-----
    }

	/* ... */

    static void onLoad(final ModConfigEvent event)
    {
      /* ... */
        items = ITEM_STRINGS.get().stream()
                .map(itemName -> ForgeRegistries.ITEMS.getValue(new ResourceLocation(itemName))) // <-----
                .collect(Collectors.toSet());
    }

However, new ResourceLocation is underlined red on my Intellij IDE, with this popup when hovered on:

'ResourceLocation(java.lang.String, java.lang.String)' has private access in 'net.minecraft.resources.ResourceLocation'

With this being RecourceLocation's constructor

    private ResourceLocation(String p_135811_, String p_135812_) {
        assert isValidNamespace(p_135811_);

        assert isValidPath(p_135812_);

        this.namespace = p_135811_;
        this.path = p_135812_;
    }

In addition, this is the error that pops up while running the build task

error: constructor ResourceLocation in class ResourceLocation cannot be applied to given types;
        return obj instanceof final String itemName && ForgeRegistries.ITEMS.containsKey(new ResourceLocation(itemName));
                                                                                         ^
  required: String,String
  found:    String

What steps would I have to follow to follow to fix this?

Is your issue fixed? if it is fixed please tell me how did you fixed it. Because im getting the same error.

Edited by wasmachgrah
Link to comment
Share on other sites

6 hours ago, wasmachgrah said:

Is your issue fixed? if it is fixed please tell me how did you fixed it. Because im getting the same error.

See the two posts above yours.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

On 6/15/2024 at 12:48 PM, Adil Yilan said:

If you want to access Resource from Minecraft, use:

ResourceLocation.withDefaultNamespace("potato"); or

If you want to access Resource from your mod, use:

ResourceLocation.fromNamespaceAndPath("your_mod_id", "your_key");

Could you be more specific please? How are we supposed to use that on .getValue/.containsKey or generally?
The item names are suddenly minecraft:minecraft: and it crashes because of that ofc.
 

Caused by: net.minecraft.ResourceLocationException: Non [a-z0-9/._-] character in path of location: minecraft:minecraft:iron_ingot



I politely ask for an explanation for which there is no documentation, not that i found and not that i found one in this topic. Here you would rather be asked to see something complete in front of your face instead of having to experiment stupidly with the API and waste time because some change was made.
Thanks in advance.

https://docs.minecraftforge.net/en/latest/concepts/resources/#resourcelocation

Quote

When a ResourceLocation is written/read as from a string, it is seen as <namespace>:<path>. If the namespace and the colon are left out, then when the string is read into an ResourceLocation the namespace will always default to "minecraft".

apparently not.. More of <namespace>:minecraft:<path>

Edited by knuers
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.