Created
June 13, 2014 23:40
-
-
Save TrainerGuy22/b3d94938fed59086edf5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cpw.mods.fml.common.FMLLog; | |
import cpw.mods.fml.common.registry.GameRegistry; | |
import net.minecraft.block.Block; | |
import net.minecraft.item.Item; | |
import net.minecraft.item.ItemStack; | |
import org.apache.commons.lang3.ArrayUtils; | |
import java.util.*; | |
public abstract class CraftingRecipeBuilder { | |
public static CraftingRecipeBuilder instance; | |
protected ItemStack output; | |
public static class ShapedCraftingRecipeBuilder extends CraftingRecipeBuilder { | |
private String[] input; | |
private Map<Character, Object> replacements = new HashMap<Character, Object>(); | |
public ShapedCraftingRecipeBuilder() { | |
} | |
public ShapedCraftingRecipeBuilder output(ItemStack stack) { | |
if(output != null) | |
FMLLog.warning("ShapedCraftingRecipeBuilder: It's bad practice to replace a preexisting output()! Replacing."); | |
output = stack; | |
return this; | |
} | |
public ShapedCraftingRecipeBuilder output(Item item) { | |
return this.output(new ItemStack(item)); | |
} | |
public ShapedCraftingRecipeBuilder output(Block block) { | |
return this.output(new ItemStack(block)); | |
} | |
public ShapedCraftingRecipeBuilder input(String... input) { | |
if(input.length > 3) | |
FMLLog.warning("ShapedCraftingRecipeBuilder: Input array larger than 3! Truncating array."); | |
this.input = ArrayUtils.subarray(input, 0, 3); | |
return this; | |
} | |
private void where(char key, Object object) { | |
if(replacements.containsKey(key)) { | |
FMLLog.warning("ShapedCraftingRecipeBuilder: It's bad practice to have two where()s with the same key! Replacing."); | |
replacements.remove(key); | |
} | |
replacements.put(key, object); | |
} | |
public ShapedCraftingRecipeBuilder where(char key, ItemStack stack) { | |
this.where(key, (Object) stack); | |
return this; | |
} | |
public ShapedCraftingRecipeBuilder where(char key, Item item) { | |
this.where(key, (Object) item); | |
return this; | |
} | |
public ShapedCraftingRecipeBuilder where(char key, Block block) { | |
this.where(key, (Object) block); | |
return this; | |
} | |
@Override | |
public void build() { | |
List<Object> object = new ArrayList<Object>(); | |
Collections.addAll(object, input); | |
for(Map.Entry<Character, Object> replacement : replacements.entrySet()) { | |
object.add(replacement.getKey()); | |
object.add(replacement.getValue()); | |
} | |
GameRegistry.addShapedRecipe(output, object.toArray()); | |
} | |
} | |
public static ShapedCraftingRecipeBuilder shaped() { | |
instance = new ShapedCraftingRecipeBuilder(); | |
return (ShapedCraftingRecipeBuilder) instance; | |
} | |
abstract public void build(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment