1

我正在创建一个 Minecraft mod,并且我收到错误 Syntax error on token ";", ,预期在此行

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() {
    }
}
4

2 回答 2

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);
于 2013-10-19T13:39:32.690 回答
0

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


class{
create block with properties here.

    @EventHandler
    public void preInit(FMLPreInitializationEvent event) {
        Register block with game here
    }
}
于 2014-08-13T11:37:22.053 回答