1696144659
本帖最后由 1696144659 于 2020-2-5 23:15 编辑

我想用meta储存Block的信息,于是定义了六个Boolean值
  1.     public static final PropertyBool UP = PropertyBool.create("up");
  2.     public static final PropertyBool DOWN = PropertyBool.create("down");
  3.     public static final PropertyBool NORTH = PropertyBool.create("north");
  4.     public static final PropertyBool SOUTH = PropertyBool.create("south");
  5.     public static final PropertyBool EAST = PropertyBool.create("east");
  6.     public static final PropertyBool WEST = PropertyBool.create("west");
复制代码
  1. @Override
  2.     protected BlockStateContainer createBlockState() {
  3.         return new BlockStateContainer(this, UP, DOWN, EAST, NORTH, SOUTH, WEST);
  4.     }

  5.     @Override
  6.     public IBlockState getStateFromMeta(int meta) {
  7.         boolean[] position = new boolean[]{false, false, false, false, false, false};
  8.         String s = Integer.toBinaryString(meta);
  9.         char[] c = s.toCharArray();
  10.         for (int i = 0; i < 6; i++){
  11.             if (c[i] == 1){position[i] = true;}else {position[i] = false;}
  12.         }
  13.         return this.getDefaultState()
  14.                 .withProperty(UP, position[0]).withProperty(DOWN, position[1])
  15.                 .withProperty(EAST, position[2]).withProperty(NORTH, position[3])
  16.                 .withProperty(SOUTH, position[4]).withProperty(WEST, position[5]);
  17.     }

  18.     @Override
  19.     public int getMetaFromState(IBlockState state) {
  20.         int i = 0;
  21.         if (state.getValue(UP)){ i++; }
  22.         i *= 2;
  23.         if (state.getValue(DOWN)){ i++; }
  24.         i *= 2;
  25.         if (state.getValue(EAST)){ i++; }
  26.         i *= 2;
  27.         if (state.getValue(NORTH)){ i++; }
  28.         i *= 2;
  29.         if (state.getValue(SOUTH)){ i++; }
  30.         i *= 2;
  31.         if (state.getValue(WEST)){ i++; }
  32.         return i;
  33.     }
复制代码
但是一调试就崩,而且只要把getStateFromMeta方法返回this.getDefultState();getMetaFromState方法返回0就不会崩
这是怎么回事?谁能帮我看一下这两个方法哪错了?


崩溃日志:


3TUSK
定义了六个Boolean值


六个 boolean 需要 6-bit 来存储,一个方块只有 4-bit(0到15)的 metadata,你这样肯定是不行的。
这个是 Minecraft 区块存储格式的限制。




1.13 起这个限制倒是没有了……

第一页 上一页 下一页 最后一页