标记“;”上的错误语法错误,预期 - Minecraft

时间:2013-10-19 13:34:21

标签: java mod-rewrite syntax minecraft

我正在创建一个Minecraft mod,我在令牌“;”上收到错误语法错误,预计在此行

public static Block BasaltSmooth;

以下是代码:

package BitBox.Mods.BetterEgg;

import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid = "BitBox's Mod", name = "BitBoxMod", version = "V0.1")
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class mainClass {
    // Initialization

    //tabs
    public static Item BitBoxTabIcon;

    //items

    //blocks
    public static Block BasaltSmooth;

    BasaltSmooth = new BitBoxBlock(500, Material.rock)
        .setHardness(0.5F)
        .setUnlocalizedName("Basalt Stone")
        .setCreativeTab(CreativeTabs.tabBlock);

    public static CreativeTabs bitBoxTab;

    @EventHandler
    public void load(FMLInitializationEvent event) {
        LanguageRegistry.addName(BasaltSmooth, "Basalt Stone");
        MinecraftForge.setBlockHarvestLevel(BasaltSmooth, "pickaxe", 0);
        GameRegistry.registerBlock(BasaltSmooth, "Basalt Stone");
    }

    public mainClass() {
    }
}

2 个答案:

答案 0 :(得分:2)

你不能这样做

public static Block BasaltSmooth;

BasaltSmooth = new BitBoxBlock(500, Material.rock).setHardness(0.5F).setUnlocalizedName("Basalt            
 Stone").setCreativeTab(CreativeTabs.tabBlock);

这样做

public static Block BasaltSmooth = new BitBoxBlock(500, Material.rock).setHardness(0.5F).setUnlocalizedName("Basalt            
 Stone").setCreativeTab(CreativeTabs.tabBlock);

答案 1 :(得分:0)

Prabhakaran的答案应该可以帮助你正确地实例化Block,但Minecraft有时会很挑剔。但是,另一个问题是你应该在FML PreInit阶段注册它:


class{
create block with properties here.

    @EventHandler
    public void preInit(FMLPreInitializationEvent event) {
        Register block with game here
    }
}