Mission 1: Stage 2: Locate Recipe Details - mverteuil/alminac GitHub Wiki
2015/03/29
src/minecraft/net/minecraft/item/crafting
Interesting files in this package:
- CraftingManager.java looks like the master list of items that can be produced on a crafting table. I don't see FurnaceRecipes.java mentioned in this file. Naïvely, I'd say it's going to be necessary to work those out too, and that kind of sucks.
- FurnaceRecipes.java looks like the list of things that can be produced by smelting. I believe the deobfuscated signature for addaddSmeltingRecipeForBlock should be
addSmeltingRecipeForBlock(Block in, ItemStack out, float cookTime)
.
2015/03/30
CraftingManager.java
I'm looking for unique patterns now. I think that a reasonable good first step is to deal with CraftingManager.java recipes for now, then work out modelling and parsing others as I accumulate data.
this.addRecipe(new ItemStack(Items.paper, 3), new Object[] {"###", '#', Items.reeds});
this.addShapelessRecipe(new ItemStack(Items.writable_book, 1), new Object[] {Items.book, new ItemStack(Items.dye, 1, EnumDyeColor.BLACK.getDyeColorDamage()), Items.feather});
this.addRecipe(new ItemStack(Blocks.oak_fence, 3), new Object[] {"W#W", "W#W", '#', Items.stick, 'W', new ItemStack(Blocks.planks, 1, BlockPlanks.EnumType.OAK.func_176839_a())});
this.addRecipe(new ItemStack(Items.golden_apple, 1, 0), new Object[] {"###", "#X#", "###", '#', Items.gold_ingot, 'X', Items.apple});
this.addRecipe(new ItemStack(Items.golden_apple, 1, 1), new Object[] {"###", "#X#", "###", '#', Blocks.gold_block, 'X', Items.apple});
I was talking to @mcfletch the other day and he mentioned there's readily available Java parsers for python. So I looked into it and I found plyj
which seemed to be a completed and documented project readily available for my use. I decided to experiment with plyj
on CraftingManager.java
.
Here's the class:
ClassDeclaration(
name='CraftingManager',
body=[
FieldDeclaration(
type=Type(
name=Name(value='CraftingManager'),
type_arguments=[],
enclosed_in=None,
dimensions=0),
variable_declarators=[
VariableDeclarator(
variable=Variable(
name='instance',
dimensions=0),
initializer=InstanceCreation(
type=Type(
name=Name(value='CraftingManager'),
type_arguments=[],
enclosed_in=None,
dimensions=0
),
type_arguments=[],
arguments=[],
body=[],
enclosed_in=None))],
modifiers=['private',
'static',
'final']),
FieldDeclaration(type=Type(name=Name(value='List'),
type_arguments=[],
enclosed_in=None,
dimensions=0),
variable_declarators=[VariableDeclarator(variable=Variable(name='recipes',
dimensions=0),
initializer=MethodInvocation(name='newArrayList',
arguments=[],
type_arguments=[],
target=Name(value='Lists')))],
modifiers=['private',
'final']),
FieldDeclaration(type=Type(name=Name(value='String'),
type_arguments=[],
enclosed_in=None,
dimensions=0),
variable_declarators=[VariableDeclarator(variable=Variable(name='__OBFID',
dimensions=0),
initializer=Literal(value='"CL_00000090"'))],
modifiers=['private',
'static',
'final']),
MethodDeclaration(name='getInstance',
modifiers=['public',
'static'],
type_parameters=[],
parameters=[],
return_type=Type(name=Name(value='CraftingManager'),
type_arguments=[],
enclosed_in=None,
dimensions=0),
body=[Return(result=Name(value='instance'))],
abstract=False,
extended_dims=0,
throws=None),
ConstructorDeclaration(name='CraftingManager',
block=[MethodInvocation(name='addRecipes',
arguments=['this'],
type_arguments=[],
target=InstanceCreation(type=Type(name=Name(value='RecipesTools'),
type_arguments=[],
enclosed_in=None,
dimensions=0),
type_arguments=[],
arguments=[],
body=[],
enclosed_in=None)),
MethodInvocation(name='addRecipes',
arguments=['this'],
type_arguments=[],
target=InstanceCreation(type=Type(name=Name(value='RecipesWeapons'),
type_arguments=[],
enclosed_in=None,
dimensions=0),
type_arguments=[],
arguments=[],
body=[],
enclosed_in=None)),
MethodInvocation(name='addRecipes',
arguments=['this'],
type_arguments=[],
target=InstanceCreation(type=Type(name=Name(value='RecipesIngots'),
type_arguments=[],
enclosed_in=None,
dimensions=0),
type_arguments=[],
arguments=[],
body=[],
enclosed_in=None)),
MethodInvocation(name='addRecipes',
arguments=['this'],
type_arguments=[],
target=InstanceCreation(type=Type(name=Name(value='RecipesFood'),
type_arguments=[],
enclosed_in=None,
dimensions=0),
type_arguments=[],
arguments=[],
body=[],
enclosed_in=None)),
MethodInvocation(name='addRecipes',
arguments=['this'],
type_arguments=[],
...
That's obviously not the route I'm going to go down.
2015/03/31
I've been sick, but playing with grep
, sed
and awk
as mining tools and they paid off much quicker than it would take for plyj to. Performing the Java source parsing in python was a novel idea, but ultimately it appeared too cumbersome for this particular project. It would have the benefit of being safe from formatting irregularities, but it would also suffer from the fact that I'd have to re-learn the API every time a new semantic variation occurs in the recipe code. With grep
and sed
, I could trivially adjust the regex to include a new semantic variation. I also pipe the results through sort
and get a result that is much nicer in terms of moving forward than the above:
addRecipe(new ItemStack(Blocks.acacia_fence, 3), new Object[] {"W#W", "W#W", '#', Items.stick, 'W', new ItemStack(Blocks.planks, 1, 4 + BlockPlanks.EnumType.ACACIA.func_176839_a() - 4)});
addRecipe(new ItemStack(Blocks.acacia_fence_gate, 1), new Object[] {"#W#", "#W#", '#', Items.stick, 'W', new ItemStack(Blocks.planks, 1, 4 + BlockPlanks.EnumType.ACACIA.func_176839_a() - 4)});
addRecipe(new ItemStack(Blocks.acacia_stairs, 4), new Object[] {"# ", "## ", "###", '#', new ItemStack(Blocks.planks, 1, 4 + BlockPlanks.EnumType.ACACIA.func_176839_a() - 4)});
addRecipe(new ItemStack(Blocks.activator_rail, 6), new Object[] {"XSX", "X#X", "XSX", 'X', Items.iron_ingot, '#', Blocks.redstone_torch, 'S', Items.stick});
addRecipe(new ItemStack(Blocks.anvil, 1), new Object[] {"III", " i ", "iii", 'I', Blocks.iron_block, 'i', Items.iron_ingot});
I'm going to add the bash
script for this to the tools folder of the repo and push it up.