1

I'm making a mod, and I am getting an error(no duh) and I have tried searching it up but I want an answer specific to my problem because I am not very good at this. I am getting this error in my block class.

Implicit super constructor Block() is undefined for default constructor. Must define an explicit constructor

and I don't know how to fix it. Please Help its for a project.

block class:

package GDMCrocknrollkid.fandomcraft;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;

public class BlockCbBlock extends Block {

protected BlockCbBlock(Material material) {
    super(material);
}

}

mod class:

    package GDMCrocknrollkid.fandomcraft;

    import net.minecraft.block.Block;
    import net.minecraft.item.Item;
    import cpw.mods.fml.common.Mod;
    import cpw.mods.fml.common.Mod.EventHandler;
    import cpw.mods.fml.common.event.FMLInitializationEvent;
    import cpw.mods.fml.common.event.FMLPostInitializationEvent;
    import cpw.mods.fml.common.event.FMLPreInitializationEvent;
    import cpw.mods.fml.common.registry.GameRegistry;

    @Mod(modid = "fc", name = "Fandomcraft", version = "1.0")
    public class fandomcraft {

    public static Item itemCbIngot;
    public static Block blockCbBlock;

    @EventHandler
    public void preInit(FMLPreInitializationEvent event){
        //Item/Block initialization and registering
        //Config Handling
        itemCbIngot = new ItemCbIngot().setUnlocalizedName("ItemCbIngot").setTextureName("fc:itemCbIngot"); //item.itemCbIngot.name
        blockCbBlock = new BlockCbBlock(Material.iron);




        GameRegistry.registerItem(itemCbIngot, itemCbIngot.getUnlocalizedName().substring(5));
    }

    @EventHandler
    public void init(FMLInitializationEvent event){
        //Proxy, TileEntity, entity, GUI and Packet Registering
    }

    @EventHandler
    public void postInit(FMLPostInitializationEvent event) {

    }
}
Shree Krishna
  • 8,474
  • 6
  • 40
  • 68
Bob Smith
  • 11
  • 2

1 Answers1

0

This error pertains to all of java, not just minecraft forge. Check this for some more reference. There are a couple possible reasons for this error. It is most likely 1, but 2 and 3 can be a contributing factor to the error.

  1. Your BlockCbBlock Class declares a constructor that is not the default, no-argument constructor that the compiler would otherwise provide (that is, if the Block class doesn't have a constructor) and, if in fact the Block class is using the default constructor, then you can't call super() on the arguements because the Block class uses a constructor with no arguments. Because of this, if you wanted to modify the Block constructor, it would be safier and easier to create a custom construcotr inside of the BlockCbBlock class itself.

  2. You are trying to inherit the constructor of Block, but you have declared it as protected, when the constructor in your class should be public to match the inherited .

  3. If you're using Eclipse, it can give this error when you have your project setup incorrectly (system configuration mismatch)

  4. Probably not directly realted to this specific error, but a possible cause of other errors in the near future; you are using the annotation @EventHandler, but you have not actually declared the forge event handler.

  5. You don't actually register the block for some reason. Even if you're using the block as a recipe item, you still need to register it

To fix potential problems 1, 2, and 4, try this (obtained from here):

package GDMCrocknrollkid.fandomcraft;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;

private final String name = "BlockCbBlock";
public class BlockCbBlock extends Block {
    public BlockCbBlock() {
        super(Material.iron);
        GameRegistry.registerBlock(this, name);
        setUnlocalizedName(Reference.MODID + "_" + name);
        setCreativeTab(CreativeTabs.tabBlock);
    }
    public String getName() {
        return name;
    }
}

This way, you'll declare its UnlocalizedName, Material, and CreativeTab ahead of time. This method might be unnecessary, but its a good precaution to help prevent the error. Now, all you have to do is declare it like this:

//You need to make your own EventHandler class. Search online for that.
FCEventHandler handler = new FCEventHandler();
@EventHandler
public void preInit(FMLPreInitializationEvent event){
    //Config Handling
    //event handler registry
    FMLCommonHandler.instance().bus().register(handler);
    MinecraftForge.EVENT_BUS.register(handler);
    //the same thing can be similarly done with this if you wish    
    itemCbIngot = new ItemCbIngot().setUnlocalizedName("ItemCbIngot").setTextureName("fc:itemCbIngot"); 
    blockCbBlock = new BlockCbBlock();
    GameRegistry.registerItem(itemCbIngot, itemCbIngot.getUnlocalizedName().substring(5));
}
Community
  • 1
  • 1
Abob
  • 751
  • 5
  • 27
  • #4 is not applicable. The @EventHandler annotation is part of Forge. `import cpw.mods.fml.common.Mod.EventHandler` and denotes the Forge Mod Lifecycle Events, which are the `FMLPreInitializationEvent`, `FMLInitializationEvent`, and `FMLPostInitializationEvent` and searched for on any class annotated with @Mod – Draco18s no longer trusts SE Apr 17 '17 at 20:30