Mission 1: Stage 3: Parse Recipe Details - mverteuil/alminac GitHub Wiki

2015/03/31

I'm now at the stage where it's going to be important to figure out how I want to represent the data that I mine. That will be a guideline for how to slice and dice the raw data.

In lines like this:

addRecipe(new ItemStack(Blocks.brick_block, 1), new Object[] {"##", "##", '#', Items.brick});

The constituent parts are:

  • addRecipe
    • new ItemStack
      • Blocks.brick_block
      • 1
    • new Object[]
      • ##, ##
      • #
        • Items.brick

I'd rather extract less now so that it's less work later, so I'm going to try and aim to get the following constituent parts into this intermediary JSON format as soon as possible:

{
  "type": "(Recipe|ShapelessRecipe)",
  "yield": {
    "item": "BrickBlock",
    "quantity": 1,
    "metadata": null
  },
  "method": [
    "##",
    "##"
  ],
  "ingredients": {
    "#": "Brick"
  },
}

I have a regex that can group these now:

(ShapelessRecipe|Recipe)\(new ItemStack\((Items|Blocks)\.(\w+)(|, (\d+)|, (\d+), ((|4 \+ )[a-zA-Z0-9._]*(|\(\))(| \- 4)))\), new Object\[\] {((".*")('.*|.*))}

Regular expression visualization View Regex at Debuggex

2015/04/04

I've found a series of regular expressions that, when applied in the correct sequence, will produce an intermediary format for formulae as I've come to refer to them as. Recipe and ShapelessRecipe formula are now parseable and this can be played with using recipe.pyformula_converter.py and recipes.txtformulae.txt. I still need to handle the ItemStacks that show up in the ShapelessRecipe ingredients list a bit better, though.


This is ultimately how I deal with metadata: Regular expression visualization https://www.debuggex.com/r/OlGobVA7L8Rv8wvJ


All handled, moved formula_converter.py into tools/.

{'form_method': {'ingredients': {'P': {'item': 'piston',
                                        'metadata': None,
                                        'quantity': '1'},
                                  'S': {'item': 'slime_ball',
                                        'metadata': None,
                                        'quantity': '1'}},
                  'shape': ['S', 'P']},
  'form_type': 'Recipe',
  'form_yield': {'item': 'sticky_piston', 'metadata': None, 'quantity': '1'}
 {'form_method': [{'item': 'paper', 'metadata': None, 'quantity': '1'},
                  {'item': 'paper', 'metadata': None, 'quantity': '1'},
                  {'item': 'paper', 'metadata': None, 'quantity': '1'},
                  {'item': 'leather', 'metadata': None, 'quantity': '1'}],
  'form_type': 'ShapelessRecipe',
  'form_yield': {'item': 'book', 'metadata': None, 'quantity': '1'}}

I need to work on furnace formulae next.