Jump to content

Recommended Posts

Posted

Heya,

 

I'm having dependency troubles during mod loading. I have a set of dependencies including slf4j, and the mod is not finding them during load. It functions correctly in the development environment, and builds correctly, but as soon as I try to run the mod from forge, the dependency is not found. Here is the relevant section of my build file:

dependencies {

//both added as an effort to overcome the problem.

embed ('org.slf4j:slf4j-api:1.7.5')

embed ('org.slf4j:jcl-over-slf4j:1.7.12')

//other dependencies

}

Here is the error I'm getting:

 

java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory

at org.drools.compiler.kie.builder.impl.KieContainerImpl.<clinit>(KieContainerImpl.java:84) ~[KieContainerImpl.class:?]

at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieClasspathContainer(KieServicesImpl.java:99) ~[KieServicesImpl.class:?]

at org.drools.compiler.kie.builder.impl.KieServicesImpl.getKieClasspathContainer(KieServicesImpl.java:82) ~[KieServicesImpl.class:?]

at org.drools.compiler.kie.builder.impl.KieServicesImpl.getKieClasspathContainer(KieServicesImpl.java:73) ~[KieServicesImpl.class:?]

at org.drools.game.core.GameSessionImpl.bootstrap(GameSessionImpl.java:92) ~[GameSessionImpl.class:?]

at org.drools.minecraft.adapter.NewAdapter.bootstrapWorld(NewAdapter.java:83) ~[NewAdapter.class:?]

at org.drools.minecraft.adapter.NewAdapter.<init>(NewAdapter.java:59) ~[NewAdapter.class:?]

at org.drools.minecraft.adapter.NewAdapter.<clinit>(NewAdapter.java:43) ~[NewAdapter.class:?]

at com.example.droolsinterface.InitCommon.preInit(InitCommon.java:29) ~[initCommon.class:?]

at com.example.examplemod.ExampleMod.preInit(ExampleMod.java:23) ~[ExampleMod.class:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_25]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_25]

at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_25]

at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:566) ~[forge-1.9.4-12.17.0.1976.jar:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_25]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_25]

at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_25]

at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?]

at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?]

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?]

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?]

at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?]

at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:228) ~[forge-1.9.4-12.17.0.1976.jar:?]

at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:206) ~[forge-1.9.4-12.17.0.1976.jar:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_25]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_25]

at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_25]

at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?]

at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?]

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?]

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?]

at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?]

at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:135) [LoadController.class:?]

at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:586) [Loader.class:?]

at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:249) [FMLClientHandler.class:?]

at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:437) [bcd.class:?]

at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:349) [bcd.class:?]

at net.minecraft.client.main.Main.main(SourceFile:124) [Main.class:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_25]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_25]

at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_25]

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]

at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]

Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory

at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:101) ~[launchwrapper-1.12.jar:?]

at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:1.8.0_25]

at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:1.8.0_25]

... 47 more

[10:18:07] [Client thread/INFO] [sTDOUT/]: [net.minecraft.init.Bootstrap:func_179870_a:560]: ---- Minecraft Crash Report ----

// Surprise! Haha. Well, this is awkward.

 

Time: 8/3/16 10:18 AM

Description: There was a severe problem during mod loading that has caused the game to fail

 

net.minecraftforge.fml.common.LoaderException: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory

at net.minecraftforge.fml.common.LoadController.transition(LoadController.java:179)

at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:589)

at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:249)

at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:437)

at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:349)

at net.minecraft.client.main.Main.main(SourceFile:124)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:483)

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

Caused by: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory

at org.drools.compiler.kie.builder.impl.KieContainerImpl.<clinit>(KieContainerImpl.java:84)

at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieClasspathContainer(KieServicesImpl.java:99)

at org.drools.compiler.kie.builder.impl.KieServicesImpl.getKieClasspathContainer(KieServicesImpl.java:82)

at org.drools.compiler.kie.builder.impl.KieServicesImpl.getKieClasspathContainer(KieServicesImpl.java:73)

at org.drools.game.core.GameSessionImpl.bootstrap(GameSessionImpl.java:92)

at org.drools.minecraft.adapter.NewAdapter.bootstrapWorld(NewAdapter.java:83)

at org.drools.minecraft.adapter.NewAdapter.<init>(NewAdapter.java:59)

at org.drools.minecraft.adapter.NewAdapter.<clinit>(NewAdapter.java:43)

at com.example.droolsinterface.InitCommon.preInit(InitCommon.java:29)

at com.example.examplemod.ExampleMod.preInit(ExampleMod.java:23)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:483)

at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:566)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:483)

at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)

at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)

at com.google.common.eventbus.EventBus.post(EventBus.java:275)

at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:228)

at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:206)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:483)

at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)

at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)

at com.google.common.eventbus.EventBus.post(EventBus.java:275)

at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:135)

at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:586)

... 10 more

Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory

at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:101)

at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

... 47 more

 

 

 

I also tried adding

 

{

      "name": "org.slf4j:slf4j-api:1.7.2”,

      "url": "http://files.minecraftforge.net/maven/"

}

 

to the "libraries" section in minecraft's configuration files, for my version of Forge. This didn't work, either.

 

Any ideas how to effectively add dependencies?

Posted

Is there any alternative for shaded (/fat) jars? In our case, the main problem of shaded jars is that we have serveral META-INF/ files in different jars that overlaps each other, and we will need to create a way to merge these files for the shaded approach. It will be interesting to know if there is a way to define the classpath of the mod in a different way, such a libs directory or a mod specific configuration file to define which dependencies needs to be picked up.

 

Also for the  org.slf4j.LoggerFactory issue, we can see the class being bundled inside the shaded jar, but for some reason minecraft is not picking it up. Is there any Classloader magic happening for mods?

Posted
  On 8/4/2016 at 2:12 PM, diesieben07 said:

There isn't an alternative, sadly.

 

I wish we had some kind of maven resolution for mods either in the launcher or in forge startup, but alas that comes with a lot of security concerns.

Thanks, this is something I very much needed to know.

 

Do you have any idea what could cause the problem in my first post, where built-in dependencies were not being found? At this point, even a general "well, you might look *here*, but I really don't know" would be massively useful.

Posted

I have a couple gradle files. (was trying some things, and they got kind of stretched out.)

 

/*


root project build.gradle


*/
import org.gradle.api.artifacts.*

apply plugin: 'base' // To add "clean" task to the root project.

subprojects {
    apply from: rootProject.file('common.gradle')
}

task mergedJavadoc(type: Javadoc, description: 'Creates Javadoc from all the projects.') {
    title = 'All modules'
    destinationDir = new File(project.buildDir, 'merged-javadoc')

    // Note: The closures below are executed lazily.
    source {
       subprojects*.sourceSets*.main*.allSource
    }
    classpath.from {
        subprojects*.configurations*.compile*.copyRecursive({ !(it instanceof ProjectDependency); })*.resolve()
    }
}






/*


root project common.gradle


*/
//
// This file is to be applied to every subproject.
//

apply plugin: 'java'
apply plugin: 'maven'

String mavenGroupId = 'org.drools.minecraft'
String mavenVersion = '1.0-SNAPSHOT'

sourceCompatibility = '1.8'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

repositories {
    mavenCentral();
    // You may define additional repositories, or even remove "mavenCentral()".
    // Read more about repositories here:
    //   http://www.gradle.org/docs/current/userguide/dependency_management.html#sec:repositories
}

dependencies {
    // Adding dependencies here will add the dependencies to each subproject.
    testCompile group: 'junit', name: 'junit', version: '4.10'
}

String mavenArtifactId = name

group = mavenGroupId
version = mavenVersion

task sourcesJar(type: Jar, dependsOn: classes, description: 'Creates a jar from the source files.') {
    classifier = 'sources'
    from sourceSets.main.allSource
}

artifacts {
    archives jar
    archives sourcesJar
}

configure(install.repositories.mavenInstaller) {
    pom.project {
        groupId = mavenGroupId
        artifactId = mavenArtifactId
        version = mavenVersion
    }
}

task createFolders(description: 'Creates the source folders if they do not exist.') doLast {
    sourceSets*.allSource*.srcDirs*.each { File srcDir ->
        if (!srcDir.isDirectory()) {
            println "Creating source folder: ${srcDir}"
            srcDir.mkdirs()
        }
    }
}





/*


Root project settings.gradle


*/
rootProject.name = 'minecraft-drools-game'

// Find the directories containing a "build.gradle" file in the root directory
// of the project. That is, every directory containing a "build.gradle" will
// be automatically the subproject of this project.
def subDirs = rootDir.listFiles(new FileFilter() {
    public boolean accept(File file) {
        if (!file.isDirectory()) {
            return false
        }
        if (file.name == 'buildSrc') {
            return false
        }
        return new File(file, 'build.gradle').isFile()
    }
});

subDirs.each { File dir ->
    include dir.name
}










/*


mod build.gradle


*/
// For those who want the bleeding edge
buildscript {
    repositories {
        jcenter()
        maven {
            name = "forge"
            url = "http://files.minecraftforge.net/maven"
        }
        
    }
    dependencies {
        classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT'
    }
}
apply plugin: 'net.minecraftforge.gradle.forge'

/*
// for people who want stable - not yet functional for MC 1.8.8 - we require the forgegradle 2.1 snapshot
plugins {
    id "net.minecraftforge.gradle.forge" version "2.0.2"
}
*/
version = "1.0"
group= "org.drools.minecraft" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "minecraft-drools-game"

configurations {
    embed
    compile.extendsFrom(embed)
}

minecraft {
    version = "1.9.4-12.17.0.1976"
    runDir = "run"
    
    // the mappings can be changed at any time, and must be in the following format.
    // snapshot_YYYYMMDD   snapshot are built nightly.
    // stable_#            stables are built at the discretion of the MCP team.
    // Use non-default mappings at your own risk. they may not allways work.
    // simply re-run your setup task after changing the mappings to update your workspace.
    mappings = "snapshot_20160518"
    // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
}

repositories {
        mavenLocal()
        maven{
            name = "jboss"
            url = "https://repository.jboss.org/nexus/content/groups/public-jboss"
        }
        
    }

dependencies {
embed ('org.slf4j:slf4j-api:1.7.5')
embed ('org.slf4j:jcl-over-slf4j:1.7.12')


    embed ('org.drools.game:drools-game-engine-core-impl:1.0-SNAPSHOT'){
        exclude group: 'commons-io', module: 'commons-io'
        transitive = true
    }
    embed ('org.drools.game:drools-game-engine-horserace-kjar:1.0-SNAPSHOT'){
        exclude group: 'commons-io', module: 'commons-io'
        transitive = true
    }


    
    runtime 'org.drools.game:drools-game-engine-horserace-kjar:1.0-SNAPSHOT'
}


processResources
{
    // this will ensure that this task is redone when the versions change.
    inputs.property "version", project.version
    inputs.property "mcversion", project.minecraft.version
    
    
    
    // replace stuff in mcmod.info, nothing else
    from(sourceSets.main.resources.srcDirs) {
        include 'mcmod.info'
                
        // replace version and mcversion
        expand 'version':project.version, 'mcversion':project.minecraft.version
    }
        
    // copy everything else, thats not the mcmod.info
    from(sourceSets.main.resources.srcDirs) {
        exclude 'mcmod.info'
    }
}
jar {
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    from configurations.embed.collect { it.isDirectory() ? it : zipTree(it) }
}


Posted

I tried shifting over to the shadow plugin, and while it does a very nice job of putting all the dependencies together, It produces a .zip file that is not recognized by minecraft as a mod. Do you know any tricks to either make it produce a compatible .jar, or get minecraft to recognize the zip?

 

 

(the new build.gradle):

 

// For those who want the bleeding edge
buildscript {
    repositories {
        jcenter()
        maven {
            name = "forge"
            url = "http://files.minecraftforge.net/maven"
        }
        
    }
    dependencies {
        classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT'
    }
    
    dependencies {
        classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3'
    }
   
}
apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'application'
/*
// for people who want stable - not yet functional for MC 1.8.8 - we require the forgegradle 2.1 snapshot
plugins {
id "net.minecraftforge.gradle.forge" version "2.0.2"
}
*/
version = "1.0"
group= "org.drools.minecraft" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "minecraft-drools-game"

mainClassName='com.example.examplemod.ExampleMod'

minecraft {
    version = "1.9.4-12.17.0.1976"
    runDir = "run"
    
    // the mappings can be changed at any time, and must be in the following format.
    // snapshot_YYYYMMDD   snapshot are built nightly.
    // stable_#            stables are built at the discretion of the MCP team.
    // Use non-default mappings at your own risk. they may not allways work.
    // simply re-run your setup task after changing the mappings to update your workspace.
    mappings = "snapshot_20160518"
    // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
}

repositories {
    mavenLocal()
    maven{
        name = "jboss"
        url = "https://repository.jboss.org/nexus/content/groups/public-jboss"
    }
        
}


dependencies {

    compile ('org.drools.game:drools-game-engine-core-impl:1.0-SNAPSHOT'){
        exclude group: 'commons-io', module: 'commons-io'
        transitive = true
    }
    compile ('org.drools.game:drools-game-engine-horserace-kjar:1.0-SNAPSHOT'){
        exclude group: 'commons-io', module: 'commons-io'
        transitive = true
    }
    
    runtime 'org.drools.game:drools-game-engine-horserace-kjar:1.0-SNAPSHOT'
    
    shadow ('org.drools.game:drools-game-engine-core-impl:1.0-SNAPSHOT'){
        exclude group: 'commons-io', module: 'commons-io'
        exclude group: 'xmlpull', module: 'xmlpull'
        exclude group: 'org.slf4j', module: 'slf4j-api'
        transitive = true
    }
    shadow ('org.drools.game:drools-game-engine-horserace-kjar:1.0-SNAPSHOT'){
        exclude group: 'xmlpull', module: 'xmlpull'
        exclude group: 'commons-io', module: 'commons-io'
        exclude group: 'org.slf4j', module: 'slf4j-api'
        transitive = true
    }
    
}
processResources
{
    // this will ensure that this task is redone when the versions change.
    inputs.property "version", project.version
    inputs.property "mcversion", project.minecraft.version
    
    // replace stuff in mcmod.info, nothing else
    from(sourceSets.main.resources.srcDirs) {
        include 'mcmod.info'
                
        // replace version and mcversion
        expand 'version':project.version, 'mcversion':project.minecraft.version
    }
        
    // copy everything else, thats not the mcmod.info
    from(sourceSets.main.resources.srcDirs) {
        exclude 'mcmod.info'
    }
}

shadowJar {
    baseName = 'horse-race-fatjar'
    classifier = null
    version = null
    mergeServiceFiles()
}

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • just rewatched the tutorial and my code is exactly the same as kaupenjoe's.  the item is added into the game but like i said to start it doesnt have a texture or a proper name for whatever reason.
    • yes the name is en_us.json and it is in resources -> assests -> testmod -> lang folders.  i have checked my code and am pretty confident that the code itself is correct.  i even tried loading the project in eclipse and it has the same problems, I think i will just rewatch the whole tutorial and will give an update on the situation.
    • same error, I also tried removing Valkyrian skies as well because I noticed it coming up a lot in the debug log errors
    • Hey man,    i have only been modding Minecraft for a few days but maybe I can help you. First of all make sure to follow every step of Kaupenjoe's tutorial, I found it to been very helpful and complete. The game uses the raw translation key for the item (in your case "item.testmod.alexandrite") if it can't find the correct lang file. Make sure it's name is "en_us.json" and it is saved under "ressources" -> "assets" -> "testmod".
    • whenever I try to get this item to render into the game it appears with the not texture purple and black squares and calls itself by the lang translation file path instead of the name i gave it.   { "item.testmod.alexandrite": "Alexandrite" } this is the lang json file package net.Hurst.testmod.item; import net.Hurst.testmod.TestMod; import net.minecraft.world.item.Item; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.RegistryObject; public class ModItems { public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, TestMod.MOD_ID); public static final RegistryObject<Item> ALEXANDRITE = ITEMS.register("alexandrite", () -> new Item(new Item.Properties())); public static void register(IEventBus eventBus){ ITEMS.register(eventBus); } } this is my ModItems.java file package net.Hurst.testmod; import com.mojang.logging.LogUtils; import net.Hurst.testmod.item.ModItems; import net.minecraft.world.item.CreativeModeTabs; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.BuildCreativeModeTabContentsEvent; import net.minecraftforge.event.server.ServerStartingEvent; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.config.ModConfig; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import org.slf4j.Logger; // The value here should match an entry in the META-INF/mods.toml file @Mod(TestMod.MOD_ID) public class TestMod { public static final String MOD_ID = "testmod"; private static final Logger LOGGER = LogUtils.getLogger(); public TestMod() { IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); modEventBus.addListener(this::commonSetup); ModItems.register(modEventBus); MinecraftForge.EVENT_BUS.register(this); modEventBus.addListener(this::addCreative); ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, Config.SPEC); } private void commonSetup(final FMLCommonSetupEvent event) { } // Add the example block item to the building blocks tab private void addCreative(BuildCreativeModeTabContentsEvent event) { if(event.getTabKey() == CreativeModeTabs.INGREDIENTS){ event.accept(ModItems.ALEXANDRITE); } } // You can use SubscribeEvent and let the Event Bus discover methods to call @SubscribeEvent public void onServerStarting(ServerStartingEvent event) { } // You can use EventBusSubscriber to automatically register all static methods in the class annotated with @SubscribeEvent @Mod.EventBusSubscriber(modid = MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) public static class ClientModEvents { @SubscribeEvent public static void onClientSetup(FMLClientSetupEvent event) { } } } this is my TestMod.java file { "parent": "minecraft:item/generated", "textures": { "layer0": "testmod:item/generated" } } this is my model file for the item. I am using intellij 2025.1.2 with fdk 1.21 and java 21 I would appreciate the help.
  • Topics

×
×
  • Create New...

Important Information

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