本帖最后由 1696144659 于 2020-2-5 23:15 编辑
我想用meta储存Block的信息,于是定义了六个Boolean值
复制代码复制代码但是一调试就崩,而且只要把getStateFromMeta方法返回this.getDefultState();getMetaFromState方法返回0就不会崩
这是怎么回事?谁能帮我看一下这两个方法哪错了?
崩溃日志:
我想用meta储存Block的信息,于是定义了六个Boolean值
- public static final PropertyBool UP = PropertyBool.create("up");
- public static final PropertyBool DOWN = PropertyBool.create("down");
- public static final PropertyBool NORTH = PropertyBool.create("north");
- public static final PropertyBool SOUTH = PropertyBool.create("south");
- public static final PropertyBool EAST = PropertyBool.create("east");
- public static final PropertyBool WEST = PropertyBool.create("west");
- @Override
- protected BlockStateContainer createBlockState() {
- return new BlockStateContainer(this, UP, DOWN, EAST, NORTH, SOUTH, WEST);
- }
- @Override
- public IBlockState getStateFromMeta(int meta) {
- boolean[] position = new boolean[]{false, false, false, false, false, false};
- String s = Integer.toBinaryString(meta);
- char[] c = s.toCharArray();
- for (int i = 0; i < 6; i++){
- if (c[i] == 1){position[i] = true;}else {position[i] = false;}
- }
- return this.getDefaultState()
- .withProperty(UP, position[0]).withProperty(DOWN, position[1])
- .withProperty(EAST, position[2]).withProperty(NORTH, position[3])
- .withProperty(SOUTH, position[4]).withProperty(WEST, position[5]);
- }
- @Override
- public int getMetaFromState(IBlockState state) {
- int i = 0;
- if (state.getValue(UP)){ i++; }
- i *= 2;
- if (state.getValue(DOWN)){ i++; }
- i *= 2;
- if (state.getValue(EAST)){ i++; }
- i *= 2;
- if (state.getValue(NORTH)){ i++; }
- i *= 2;
- if (state.getValue(SOUTH)){ i++; }
- i *= 2;
- if (state.getValue(WEST)){ i++; }
- return i;
- }
这是怎么回事?谁能帮我看一下这两个方法哪错了?
崩溃日志:
定义了六个Boolean值
六个 boolean 需要 6-bit 来存储,一个方块只有 4-bit(0到15)的 metadata,你这样肯定是不行的。
这个是 Minecraft 区块存储格式的限制。
1.13 起这个限制倒是没有了……