Fix default patterns to not be recorded

This commit is contained in:
Andrew Miner
2015-01-10 02:16:38 -08:00
parent 2f7ae584a0
commit f5681a84aa
5 changed files with 37 additions and 17 deletions
+1 -1
View File
@@ -176,7 +176,7 @@
"tools": "Crafting Table" "tools": "Crafting Table"
}, { }, {
"output": "Sawmill", "output": "Sawmill",
"input": [[2, "Copper Ingot"], [2, "Oak Plank"], "Iron Axe", "Machine Frame", "Redstone Reception Coil"], "input": [[2, "Copper Ingot"], [2, "Oak Wood Planks], "Iron Axe", "Machine Frame", "Redstone Reception Coil"],
"tools": "Crafting Table" "tools": "Crafting Table"
}, { }, {
"output": "Schematic", "output": "Schematic",
+1 -1
View File
@@ -8,11 +8,11 @@ All rights reserved.
exports.DefaultBookUrls = DefaultBookUrls = [ exports.DefaultBookUrls = DefaultBookUrls = [
'/data/minecraft/recipes.json' '/data/minecraft/recipes.json'
'/data/buildcraft/recipes.json' '/data/buildcraft/recipes.json'
'/data/ic2_classic/recipes.json'
# Disabled until shaped crafting can be added -- aminer 2015-01-09 # Disabled until shaped crafting can be added -- aminer 2015-01-09
# '/data/applied_energetics/recipes.json' # '/data/applied_energetics/recipes.json'
# '/data/gravisuite/recipes.json' # '/data/gravisuite/recipes.json'
# '/data/industrial_craft/recipes.json'
# '/data/more_blocks/recipes.json' # '/data/more_blocks/recipes.json'
# '/data/thermal_expansion/recipes.json' # '/data/thermal_expansion/recipes.json'
] ]
+2
View File
@@ -34,6 +34,8 @@ module.exports = class Item extends BaseModel
@recipes.push recipe @recipes.push recipe
compareTo: (that)-> compareTo: (that)->
if this.slug isnt that.slug
return if this.slug < that.slug then -1 else +1
if this.name isnt that.name if this.name isnt that.name
return if this.name < that.name then -1 else +1 return if this.name < that.name then -1 else +1
return 0 return 0
+1 -1
View File
@@ -203,7 +203,7 @@ module.exports.V1 = class V1
result.push ' "input": ' result.push ' "input": '
@_unparseStackList recipe.input, result @_unparseStackList recipe.input, result
if recipe.pattern is recipe._computeShapelessPattern(recipe.input) if recipe.pattern?
result.push ',\n' result.push ',\n'
result.push ' "pattern": "' result.push ' "pattern": "'
result.push recipe.pattern result.push recipe.pattern
+31 -13
View File
@@ -16,7 +16,7 @@ module.exports = class Recipe extends BaseModel
if not attributes.input? then throw new Error 'attributes.input is required' if not attributes.input? then throw new Error 'attributes.input is required'
if not attributes.output? then throw new Error 'attributes.output is required' if not attributes.output? then throw new Error 'attributes.output is required'
attributes.pattern = @_parsePattern attributes.pattern, attributes.input attributes.pattern = @_parsePattern attributes.pattern
attributes.tools ?= [] attributes.tools ?= []
super attributes, options super attributes, options
@@ -25,8 +25,10 @@ module.exports = class Recipe extends BaseModel
# Public Methods ############################################################################### # Public Methods ###############################################################################
getItemSlugAt: (index)-> getItemSlugAt: (index)->
pattern = if @pattern? then @pattern else @_computeDefaultPattern()
trueIndex = 0:0, 1:1, 2:2, 3:4, 4:5, 5:6, 6:8, 7:9, 8:10 trueIndex = 0:0, 1:1, 2:2, 3:4, 4:5, 5:6, 6:8, 7:9, 8:10
patternDigit = @pattern[trueIndex[index]] patternDigit = pattern[trueIndex[index]]
return null unless patternDigit? return null unless patternDigit?
return null unless patternDigit.match /[0-9]/ return null unless patternDigit.match /[0-9]/
@@ -85,24 +87,40 @@ module.exports = class Recipe extends BaseModel
# Private Methods ############################################################################## # Private Methods ##############################################################################
_parsePattern: (pattern, input)-> _parsePattern: (pattern)->
pattern ?= '' return unless pattern?
pattern = pattern.replace /\ /g, '' pattern = pattern.replace /\ /g, ''
return if pattern.length is 0
if pattern.length > 0
pattern = pattern.replace /[^0-9]/g, '.' pattern = pattern.replace /[^0-9]/g, '.'
else
pattern = @_computeShapelessPattern input
array = pattern.split ''
array = array[0...9]
while array.length isnt 9
array.push '.'
pattern = array.join ''
pattern = pattern.replace /(...)(...)(...)/, '$1 $2 $3' pattern = pattern.replace /(...)(...)(...)/, '$1 $2 $3'
return pattern return pattern
_computeShapelessPattern: (input)-> _computeDefaultPattern: ->
result = '728506314' itemCount = @input.length
slotCount = _.reduce @input, ((total, stack)-> total + stack.quantity), 0
total = _.reduce input, ((total, stack)-> total + stack.quantity), 0 return '... .0. ...' if itemCount is 1 and slotCount is 1
return '00. 00. ...' if itemCount is 1 and slotCount is 4
return '000 000 000' if itemCount is 1 and slotCount is 9
for i in [total...9] result = ['.', '.', '.', '.', '.', '.', '.', '.', '.']
result = result.replace "#{i}", '.' indexes = [4, 7, 1, 3, 5, 6, 8, 0, 2]
return result for i in [0...@input.length]
stack = @input[i]
for j in [0...stack.quantity]
index = indexes.shift()
result[index] = "#{i}"
pattern = result.join ''
pattern = pattern.replace /(...)(...)(...)/, '$1 $2 $3'
return pattern