コード例 #1
0
  private static ForgeMaterialData getMaterial0(String input)
      throws NumberFormatException, InvalidConfigException {
    String blockName = input;
    int blockData = -1;

    // When there is a . or a : in the name, extract block data
    int splitIndex = input.lastIndexOf(":");
    if (splitIndex == -1) {
      splitIndex = input.lastIndexOf(".");
    }
    if (splitIndex != -1) {
      blockName = input.substring(0, splitIndex);
      blockData = Integer.parseInt(input.substring(splitIndex + 1));
    }

    // Parse block name
    Block block = Block.getBlockFromName(blockName);
    if (block == null) {
      DefaultMaterial defaultMaterial = DefaultMaterial.getMaterial(blockName);
      if (defaultMaterial != DefaultMaterial.UNKNOWN_BLOCK) {
        block = Block.getBlockById(defaultMaterial.id);
      }
    }

    // Get the block
    if (block != null) {
      if (blockData == -1) {
        // Use default
        return ForgeMaterialData.ofMinecraftBlock(block);
      } else {
        // Use specified data
        try {
          return ForgeMaterialData.ofMinecraftBlockState(block.getStateFromMeta(blockData));
        } catch (IllegalArgumentException e) {
          throw new InvalidConfigException(
              "Illegal block data for the block type, cannot use " + input);
        }
      }
    }

    // Failed
    throw new InvalidConfigException("Unknown material: " + input);
  }
コード例 #2
0
 @Override
 public DefaultMaterial toDefaultMaterial() {
   return DefaultMaterial.getMaterial(getBlockId());
 }