Jump to content

NoSuchMethodExceptions on world load


SirWindfield

Recommended Posts

I am pretty new to modding so please keep that in mind :D

I want to disable all vanilla swords and tried it with the following code (basically just registering a custom event handler using MinecraftForge#EVENT_BUS):

@SubscribeEvent(priority = EventPriority.HIGHEST)
    public void onDamageTaken(LivingHurtEvent event) {
        // only consider any calculations if the source is the player itself
        Entity entity = event.getSource().getEntity();
        if (entity instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer) entity;
            // only look for the main hand
            ItemStack stack = player.getHeldItemMainhand();
            if (!ItemStackTools.isEmpty(stack)) {
                if (stack.getItem() instanceof ItemSword) {
                    event.setCanceled(true);
                }
            }
        }
    }

But for some odd reasons, as soon as I load into a world, I get a `java.lang.NoSuchMethodError: net.minecraft.util.DamageSource.getEntity()Lnet/minecraft/entity/Entity;`. To be honest, I have no idea what is going wrong here D:

If I run the code within eclipse by using the gradle runClient command all works fine. But if I build the jar using `gradle build` and add it to the mods folder, the game crashes on world load.

Here is the full stack trace: https://pastebin.com/3TrnL5NS

I have a general idea what is happening though. Not every entitiy has a damage source I guess. And it looks like the Bat is one of them. But how would I check for that too? 

I tried it early on with `event.getSource().getDamageType()` but that through the same exception on mobs added by oder mods.

 

Any help is appreciated,

Sir

Link to comment
Share on other sites

It seems that the part of the code is not obfuscated. Could you post your build.gradle file and the log from the gradle build command?

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

buildscript {
    repositories {
        jcenter()
        maven { url = "http://files.minecraftforge.net/maven" }
    }
    dependencies {
        classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT'
    }
}
repositories {
    maven { // JEI, McJtyLib and TOP
        url "http://modmaven.k-4u.nl/"
    }
}
apply plugin: 'net.minecraftforge.gradle.forge'
//Only edit below this line, the above code adds and enables the nessasary things for Forge to be setup.


version = "1.0.1"
group= "de.zerotask.minecraft.vanillatools" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "vanillatools"

sourceCompatibility = targetCompatibility = "1.8" // Need this here so eclipse task generates correctly.
compileJava {
    sourceCompatibility = targetCompatibility = "1.8"
}

minecraft {
    version = "1.10.2-12.18.3.2281"
    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_20161111"
    // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
}

dependencies {
    // you may put jars on which you depend on in ./libs
    // or you may define them like so..
    //compile "some.group:artifact:version:classifier"
    //compile "some.group:artifact:version"
      
    // real examples
    //compile 'com.mod-buildcraft:buildcraft:6.0.8:dev'  // adds buildcraft to the dev env
    //compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env

    // the 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime.
    //provided 'com.mod-buildcraft:buildcraft:6.0.8:dev'

    // the deobf configurations:  'deobfCompile' and 'deobfProvided' are the same as the normal compile and provided,
    // except that these dependencies get remapped to your current MCP mappings
    //deobfCompile 'com.mod-buildcraft:buildcraft:6.0.8:dev'
    //deobfProvided 'com.mod-buildcraft:buildcraft:6.0.8:dev'

    // for more info...
    // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
    // http://www.gradle.org/docs/current/userguide/dependency_management.html
    deobfCompile "com.github.mcjty:compatlayer:1.10-0.2.8"

}

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'
    }
}

And here is my log file: https://pastebin.com/TJg8vhcj

Link to comment
Share on other sites

Rather than "gradle build", try gradlew build (run the script that came with the Forge installation). And, I don't know what Eclipse might be doing to gradle, but be safe by opening a command window and running the gradlew script from a command prompt.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

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.

Announcements



×
×
  • Create New...

Important Information

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