Posted June 13, 20241 yr 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?
June 14, 20241 yr 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.
June 15, 20241 yr 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");
June 15, 20241 yr 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 June 15, 20241 yr by wasmachgrah
June 16, 20241 yr 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.
June 18, 20241 yr 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 June 18, 20241 yr by knuers
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.