Search code examples
javaminecraftminecraft-forge

'Annotations are not allowed here'


Im creating a forge 1.12.2 mod but in my main class when i do

@SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.COMMON_PROXY_CLASS);
    public static CommonProxy proxy;

It gives the following error(s):

Annotations are not allowed here: 18
Identifier or type expected: 18

for some more information:

package com.pironielsje.furge;

import com.pironielsje.furge.proxy.CommonProxy;
import com.pironielsje.furge.util.Reference;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.*;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;

@Mod(modid = Reference.MOD_ID, version = Reference.VERSION, name = Reference.MOD_NAME)
public class FurgeMod {
    @Instance
    public static FurgeMod instance;

    @SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.COMMON_PROXY_CLASS);
    public static CommonProxy proxy;

    @EventHandler
    public void Init(FMLInitializationEvent event) {

    }

    @EventHandler
    public void postInit(FMLPostInitializationEvent event) {

    }

    @EventHandler
    public void preInit(FMLPreInitializationEvent event) {

    }

    @EventHandler
    public void serverInit(FMLServerStartingEvent event) {

    }
}

this is my main class

package com.pironielsje.furge.util;

public class Reference {
    public static final String MOD_ID = "furge";
    public static final String VERSION = "0.1";
    public static final String MC_VERSION = "[1.12.2]";
    public static final String MOD_NAME = "Furge Mod";

    public static final String CLIENT_PROXY_CLASS = "";
    public static final String COMMON_PROXY_CLASS = "";
}

This is my Reference class


Solution

  • Remove the semicolon after the annotation.

    The error Identifier or type expected: 18 reflects the fact that an annotation must be applied to a declaration, as would be the case for

    @SidedProxy(...)
    public static CommonProxy proxy;
    

    The stray semicolon splits this into two separate statements. The first is the invalid annotation with an expected (but missing) identifier/type (for the declaration that it would annotate) and the second is a well-formed, but unannotated declaration of a public static CommonProxy.