Fix default patterns to not be recorded
This commit is contained in:
@@ -8,11 +8,11 @@ All rights reserved.
|
||||
exports.DefaultBookUrls = DefaultBookUrls = [
|
||||
'/data/minecraft/recipes.json'
|
||||
'/data/buildcraft/recipes.json'
|
||||
'/data/ic2_classic/recipes.json'
|
||||
|
||||
# Disabled until shaped crafting can be added -- aminer 2015-01-09
|
||||
# '/data/applied_energetics/recipes.json'
|
||||
# '/data/gravisuite/recipes.json'
|
||||
# '/data/industrial_craft/recipes.json'
|
||||
# '/data/more_blocks/recipes.json'
|
||||
# '/data/thermal_expansion/recipes.json'
|
||||
]
|
||||
|
||||
@@ -34,6 +34,8 @@ module.exports = class Item extends BaseModel
|
||||
@recipes.push recipe
|
||||
|
||||
compareTo: (that)->
|
||||
if this.slug isnt that.slug
|
||||
return if this.slug < that.slug then -1 else +1
|
||||
if this.name isnt that.name
|
||||
return if this.name < that.name then -1 else +1
|
||||
return 0
|
||||
|
||||
@@ -203,7 +203,7 @@ module.exports.V1 = class V1
|
||||
result.push ' "input": '
|
||||
@_unparseStackList recipe.input, result
|
||||
|
||||
if recipe.pattern is recipe._computeShapelessPattern(recipe.input)
|
||||
if recipe.pattern?
|
||||
result.push ',\n'
|
||||
result.push ' "pattern": "'
|
||||
result.push recipe.pattern
|
||||
|
||||
@@ -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.output? then throw new Error 'attributes.output is required'
|
||||
|
||||
attributes.pattern = @_parsePattern attributes.pattern, attributes.input
|
||||
attributes.pattern = @_parsePattern attributes.pattern
|
||||
attributes.tools ?= []
|
||||
super attributes, options
|
||||
|
||||
@@ -25,8 +25,10 @@ module.exports = class Recipe extends BaseModel
|
||||
# Public Methods ###############################################################################
|
||||
|
||||
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
|
||||
patternDigit = @pattern[trueIndex[index]]
|
||||
patternDigit = pattern[trueIndex[index]]
|
||||
return null unless patternDigit?
|
||||
return null unless patternDigit.match /[0-9]/
|
||||
|
||||
@@ -85,24 +87,40 @@ module.exports = class Recipe extends BaseModel
|
||||
|
||||
# Private Methods ##############################################################################
|
||||
|
||||
_parsePattern: (pattern, input)->
|
||||
pattern ?= ''
|
||||
_parsePattern: (pattern)->
|
||||
return unless pattern?
|
||||
|
||||
pattern = pattern.replace /\ /g, ''
|
||||
return if pattern.length is 0
|
||||
|
||||
if pattern.length > 0
|
||||
pattern = pattern.replace /[^0-9]/g, '.'
|
||||
else
|
||||
pattern = @_computeShapelessPattern input
|
||||
pattern = pattern.replace /[^0-9]/g, '.'
|
||||
|
||||
array = pattern.split ''
|
||||
array = array[0...9]
|
||||
while array.length isnt 9
|
||||
array.push '.'
|
||||
|
||||
pattern = array.join ''
|
||||
pattern = pattern.replace /(...)(...)(...)/, '$1 $2 $3'
|
||||
return pattern
|
||||
|
||||
_computeShapelessPattern: (input)->
|
||||
result = '728506314'
|
||||
_computeDefaultPattern: ->
|
||||
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.replace "#{i}", '.'
|
||||
result = ['.', '.', '.', '.', '.', '.', '.', '.', '.']
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user