Fabric API

Fabric API

106M Downloads

ITEM cannot be resolved or is not a field when using Registry.ITEM

Patzlyk opened this issue ยท 16 comments

commented

I get this error when accessing Registry.ITEM in onInitialization() method of ModInitializer.

commented

Posting on issues that are 4 years old is not how one should ask for help. Please ask on the discussion page or on the discord server.

commented

package br.com.modpack.item;

import br.com.modpack.RedPlanetLost;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.minecraft.item.Item;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import java.rmi.registry.Registry;

public class ModItems {

public static final Item SEMENTE_DE_ALPISTE = registerItem("semente_de_alpiste", new Item(new FabricItemSettings()));

private static Item registerItem(String name, Item item) {
    return Registry.register(Registries.ITEM, new Identifier(RedPlanetLost.MOD_ID, name), item);
}

public static void registerModItems() {
    RedPlanetLost.LOGGER.info("Registrando itens modificados para " + RedPlanetLost.MOD_ID);
}

}

Error: Cannot resolve method 'register' in 'Registry'

commented

wrong import for Registry

commented

Did you import the minecraft registry class? or the sun/whatever other one

commented

I have imported net.minecraft.util.registry.*

commented
---- Minecraft Crash Report ----
// Hi. I'm Minecraft, and I'm a crashaholic.

Time: 11.07.19 14:12
Description: Initializing game

java.lang.RuntimeException: Could not execute entrypoint stage 'main' due to errors!
	at net.fabricmc.loader.entrypoint.hooks.EntrypointUtils.logErrors(EntrypointUtils.java:45)
	at net.fabricmc.loader.entrypoint.hooks.EntrypointClient.start(EntrypointClient.java:34)
	at net.minecraft.client.MinecraftClient.init(MinecraftClient.java)
	at net.minecraft.client.MinecraftClient.start(MinecraftClient.java:368)
	at net.minecraft.client.main.Main.main(Main.java:126)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at net.fabricmc.loader.game.MinecraftGameProvider.launch(MinecraftGameProvider.java:170)
	at net.fabricmc.loader.launch.knot.Knot.init(Knot.java:129)
	at net.fabricmc.loader.launch.knot.KnotClient.main(KnotClient.java:26)
	Suppressed: java.lang.Error: Unresolved compilation problem: 
	ITEM cannot be resolved or is not a field

		at net.fabricmc.example.ExampleMod.onInitialize(ExampleMod.java:21)
		at net.fabricmc.loader.entrypoint.hooks.EntrypointUtils.lambda$logErrors$0(EntrypointUtils.java:38)
		at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
		at net.fabricmc.loader.entrypoint.hooks.EntrypointUtils.logErrors(EntrypointUtils.java:36)
		... 11 more


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Client thread
Stacktrace:
	at net.fabricmc.loader.entrypoint.hooks.EntrypointUtils.logErrors(EntrypointUtils.java:45)
	at net.fabricmc.loader.entrypoint.hooks.EntrypointClient.start(EntrypointClient.java:34)
	at net.minecraft.client.MinecraftClient.init(MinecraftClient.java)

-- Initialization --
Details:
Stacktrace:
	at net.minecraft.client.MinecraftClient.start(MinecraftClient.java:368)
	at net.minecraft.client.main.Main.main(Main.java:126)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at net.fabricmc.loader.game.MinecraftGameProvider.launch(MinecraftGameProvider.java:170)
	at net.fabricmc.loader.launch.knot.Knot.init(Knot.java:129)
	at net.fabricmc.loader.launch.knot.KnotClient.main(KnotClient.java:26)

-- System Details --
Details:
	Minecraft Version: 1.14.3
	Operating System: Windows 10 (amd64) version 10.0
	Java Version: 11.0.3, AdoptOpenJDK
	Java VM Version: OpenJDK 64-Bit Server VM (mixed mode), AdoptOpenJDK
	Memory: 303561504 bytes (289 MB) / 568328192 bytes (542 MB) up to 2130706432 bytes (2032 MB)
	JVM Flags: 3 total; -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=localhost:60176,server=n,suspend=y
	Fabric Mods: 
		fabric: Fabric API 0.3.0+build.191
		fabric-api-base: fabric-api-base 0.1.0+59147463
		fabric-biomes-v1: fabric-biomes-v1 0.1.0+896c7fbb
		fabric-commands-v0: fabric-commands-v0 0.1.1+25fd0c52
		fabric-containers-v0: fabric-containers-v0 0.1.2+25fd0c52
		fabric-content-registries-v0: fabric-content-registries-v0 0.1.1+05f11b75
		fabric-crash-report-info-v1: fabric-crash-report-info-v1 0.1.0+59147463
		fabric-events-interaction-v0: fabric-events-interaction-v0 0.1.0+59147463
		fabric-events-lifecycle-v0: fabric-events-lifecycle-v0 0.1.0+59147463
		fabric-item-groups-v0: fabric-item-groups-v0 0.1.0+f0d56800
		fabric-keybindings-v0: fabric-keybindings-v0 0.1.1+7dfef87c
		fabric-loot-tables-v1: fabric-loot-tables-v1 0.1.0+43028fa6
		fabric-mining-levels-v0: fabric-mining-levels-v0 0.1.0+bdffbb2c
		fabric-models-v0: fabric-models-v0 0.1.0+59147463
		fabric-networking-blockentity-v0: fabric-networking-blockentity-v0 0.1.1+25fd0c52
		fabric-networking-v0: fabric-networking-v0 0.1.2+200eb5c2
		fabric-object-builders-v0: fabric-object-builders-v0 0.1.1+39ff57de
		fabric-registry-sync-v0: fabric-registry-sync-v0 0.2.2+f0d56800
		fabric-renderer-api-v1: fabric-renderer-api-v1 0.1.1+099c1e8b
		fabric-renderer-indigo: fabric-renderer-indigo 0.1.8+099c1e8b
		fabric-rendering-data-attachment-v1: fabric-rendering-data-attachment-v1 0.1.0+02a46d5b
		fabric-rendering-fluids-v1: fabric-rendering-fluids-v1 0.1.0+dc4c57c2
		fabric-rendering-v0: fabric-rendering-v0 0.1.1+6dad974e
		fabric-resource-loader-v0: fabric-resource-loader-v0 0.1.1+59147463
		fabric-tag-extensions-v0: fabric-tag-extensions-v0 0.1.1+c189dc5c
		fabric-textures-v0: fabric-textures-v0 0.1.4+792c1c35
		fabricloader: Fabric Loader 0.4.8+build.155
		modid: Example Mod ${version}
	Launched Version: Fabric
	LWJGL: 3.2.2 build 10
	OpenGL: NO CONTEXT
	GL Caps: 
	Using VBOs: Yes
	Is Modded: Definitely; Client brand changed to 'fabric'
	Type: Client (map_client.txt)
	Resource Packs: ~~ERROR~~ NullPointerException: null
	Current Language: ~~ERROR~~ NullPointerException: null
	CPU: <unknown>
commented

Oh, this is in runtime. assumed it was in a dev environment, my bad.

commented

I get this error in dev environment, I tried to run the game.

commented

Got the word wrong, I meant that I thought it was an error showing up during compilation before even getting the game to run

commented

I get the error before i start debugging.
Bez nรกzvu

commented

Can you send the all the lines of the class?

commented

This is the entire file:

package net.fabricmc.example;

import java.rmi.registry.Registry;

import net.fabricmc.api.ModInitializer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.*;
import net.fabricmc.fabric.api.registry.*;
import net.fabricmc.fabric.impl.registry.*;

public class ExampleMod implements ModInitializer
{
    // an instance of our new item
    public static final Item FABRIC_ITEM = new Item(new Item.Settings().group(ItemGroup.MISC));
 
    @Override
    public void onInitialize()
    {
        Registry.register(Registry.ITEM, new Identifier("tutorial", "fabric_item"), FABRIC_ITEM);
    } 
}
commented

import java.rmi.registry.Registry; yep, another registry import as i thought. try it without this line.

commented

It works now, thanks.

commented

a whole year+ later this still solves this issue lol

commented

this isn't an issue on fabric's end, it's just the issue that you have imported and used the wrong Registry.