访问枚举

时间:2016-10-04 00:46:07

标签: java arrays enums nullpointerexception

不确定我的标题是否适用于我的问题。基本上我有一个enum包含我正在创建的一些块的各种值(是的,这是一个minecraft mod)。我的目标是制作一张"规格表"它包含所有值,然后我将它们提供给我的BlockMaker类,它实际上完成了繁重的工作。

我将基本块定义为带有值和构造函数的枚举。其中一个值(或一组值)定义块是否应具有替代块,例如楼梯。我最初的想法是使用一系列与每个替代块相关的布尔值。然后我有了创建另一个枚举的想法,它只包含备用块的所有名称。我只是添加了一个枚举数组作为块枚举的值而不是布尔值。 blockMaker类将检查数组中存在哪些枚举并相应地创建块。但现在的问题是我无法弄清楚如何访问它们,我在运行游戏时不断获得nullPointerException

说到这一点,我甚至不确定一系列枚举甚至是存储数据的最佳方式。如果有人有更好的想法,我想知道。

以下是我正在使用的代码;

"主"带有块值的枚举;

public enum UBCBlockConstants {

TEST_ROCK("testRock", IGNEOUS, 1.0F, 1.0F, new ConstructTypes[]{STONE, COBBLESTONE, BRICKS, SLAB, STAIRS, WALL}),

String unlocalizedName = "";
UBCRockTypes rockType;
Float hardness = 0.0F;
Float resistance = 0.0F;
ConstructTypes[] constructTypes;

UBCBlockConstants(String unlocalizedName, UBCRockTypes rockType, Float hardness, Float resistance, ConstructTypes[] constructTypes) {

    this.unlocalizedName = unlocalizedName;
    this.rockType = rockType;
    this.hardness = hardness;
    this.resistance = resistance;
    this.constructTypes = constructTypes;

}

public UBCRockTypes getBlockType() { return rockType; }

public String getUnlocalizedName() { return unlocalizedName; }

public Float getHardness() {
    return hardness;
}

public Float getResistance(){
    return resistance;
}

public ConstructTypes[] getConstructTypes() { return constructTypes; }

}

ConstructType枚举;

public enum ConstructTypes {

STONE,
COBBLESTONE,
BRICKS,
SLAB,
STAIRS,
WALL;

}

正如我上面提到的那样,嵌入在枚举中的枚举数组真的是最好的方法吗?使用其他存储方法会更好吗?

0 个答案:

没有答案
相关问题