New build limits, recipe refactoring
This commit is contained in:
@@ -1,17 +1,32 @@
|
||||
package io.anuke.mindustry.resource;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
|
||||
import static io.anuke.mindustry.Vars.debug;
|
||||
|
||||
public class Recipe {
|
||||
public Block result;
|
||||
public ItemStack[] requirements;
|
||||
public Section section;
|
||||
private static int lastid;
|
||||
private static Array<Recipe> allRecipes = new Array<>();
|
||||
private static ObjectMap<Block, Recipe> recipeMap = new ObjectMap<>();
|
||||
|
||||
public final int id;
|
||||
public final Block result;
|
||||
public final ItemStack[] requirements;
|
||||
public final Section section;
|
||||
|
||||
public boolean desktopOnly = false, debugOnly = false;
|
||||
|
||||
public Recipe(Section section, Block result, ItemStack... requirements){
|
||||
this.id = lastid ++;
|
||||
this.result = result;
|
||||
this.requirements = requirements;
|
||||
this.section = section;
|
||||
|
||||
allRecipes.add(this);
|
||||
recipeMap.put(result, this);
|
||||
}
|
||||
|
||||
public Recipe setDesktop(){
|
||||
@@ -23,4 +38,30 @@ public class Recipe {
|
||||
debugOnly = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static Array<Recipe> getBySection(Section section, Array<Recipe> r){
|
||||
for(Recipe recipe : allRecipes){
|
||||
if(recipe.section == section && !(Vars.mobile && recipe.desktopOnly) && !(!debug && recipe.debugOnly)) {
|
||||
r.add(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
public static Array<Recipe> all(){
|
||||
return allRecipes;
|
||||
}
|
||||
|
||||
public static Recipe getByResult(Block block){
|
||||
return recipeMap.get(block);
|
||||
}
|
||||
|
||||
public static Recipe getByID(int id){
|
||||
if(id < 0 || id >= allRecipes.size){
|
||||
return null;
|
||||
}else{
|
||||
return allRecipes.get(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user