diff options
| author | Unknown <shekwancheung0528@gmail.com> | 2018-12-30 20:10:36 +0800 |
|---|---|---|
| committer | Unknown <shekwancheung0528@gmail.com> | 2018-12-30 20:10:36 +0800 |
| commit | 3aac033fd430903a1989a48015fadc18e67a7c2f (patch) | |
| tree | cf337b4e12df85cd30d25721bab6c1ba1f4591f8 /src/main/java/me/shedaniel/impl/REIRecipeManager.java | |
| parent | 0fd1d706bdcb3857ff2b943aa82059dad8f4a8e9 (diff) | |
| download | RoughlyEnoughItems-3aac033fd430903a1989a48015fadc18e67a7c2f.tar.gz RoughlyEnoughItems-3aac033fd430903a1989a48015fadc18e67a7c2f.tar.bz2 RoughlyEnoughItems-3aac033fd430903a1989a48015fadc18e67a7c2f.zip | |
Better stuff
Diffstat (limited to 'src/main/java/me/shedaniel/impl/REIRecipeManager.java')
| -rwxr-xr-x | src/main/java/me/shedaniel/impl/REIRecipeManager.java | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/src/main/java/me/shedaniel/impl/REIRecipeManager.java b/src/main/java/me/shedaniel/impl/REIRecipeManager.java new file mode 100755 index 000000000..be8f71bbb --- /dev/null +++ b/src/main/java/me/shedaniel/impl/REIRecipeManager.java @@ -0,0 +1,157 @@ +package me.shedaniel.impl; + +import me.shedaniel.api.IREIPlugin; +import me.shedaniel.api.IDisplayCategory; +import me.shedaniel.api.IRecipe; +import me.shedaniel.api.IRecipeManager; +import me.shedaniel.gui.RecipeGui; +import net.minecraft.client.Minecraft; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.RecipeManager; +import org.dimdev.riftloader.RiftLoader; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +/** + * Created by James on 8/7/2018. + */ +public class REIRecipeManager implements IRecipeManager { + private Map<String, List<IRecipe>> recipeList; + private List<IDisplayCategory> displayAdapters; + public static RecipeManager recipeManager; + + private static REIRecipeManager myInstance; + + private REIRecipeManager() { + recipeList = new HashMap<>(); + displayAdapters = new LinkedList<>(); + } + + public List<IDisplayCategory> getDisplayAdapters() { + return displayAdapters; + } + + public static REIRecipeManager instance() { + if (myInstance == null) { + System.out.println("Newing me up."); + myInstance = new REIRecipeManager(); + } + return myInstance; + } + + @Override + public void addRecipe(String id, IRecipe recipe) { + if (recipeList.containsKey(id)) { + recipeList.get(id).add(recipe); + } else { + List<IRecipe> recipes = new LinkedList<>(); + recipeList.put(id, recipes); + recipes.add(recipe); + } + } + + @Override + public void addRecipe(String id, List<? extends IRecipe> recipes) { + if (recipeList.containsKey(id)) { + recipeList.get(id).addAll(recipes); + } else { + List<IRecipe> newRecipeList = new LinkedList<>(); + recipeList.put(id, newRecipeList); + newRecipeList.addAll(recipes); + } + } + + @Override + public void addDisplayAdapter(IDisplayCategory adapter) { + displayAdapters.add(adapter); + } + + @Override + public Map<IDisplayCategory, List<IRecipe>> getRecipesFor(ItemStack stack) { + Map<IDisplayCategory, List<IRecipe>> categories = new HashMap<>(); + displayAdapters.forEach(f -> categories.put(f, new LinkedList<>())); + for(List<IRecipe> value : recipeList.values()) { + for(IRecipe iRecipe : value) { + for(Object o : iRecipe.getOutput()) { + if (o instanceof ItemStack) { + if (ItemStack.areItemsEqual(stack, (ItemStack) o)) { + for(IDisplayCategory iDisplayCategory : categories.keySet()) { + if (iDisplayCategory.getId() == iRecipe.getId()) { + categories.get(iDisplayCategory).add(iRecipe); + } + } + } + } + } + } + } + categories.keySet().removeIf(f -> categories.get(f).isEmpty()); + return categories; + } + + public Map<IDisplayCategory, List<IRecipe>> getUsesFor(ItemStack stack) { + Map<IDisplayCategory, List<IRecipe>> categories = new HashMap<>(); + displayAdapters.forEach(f -> categories.put(f, new LinkedList<>())); + for(List<IRecipe> value : recipeList.values()) { + for(IRecipe iRecipe : value) { + boolean found = false; + for(Object o : iRecipe.getInput()) { + List<ItemStack> input = (List<ItemStack>) o; + + for(ItemStack itemStack : input) { + if (ItemStack.areItemsEqual(itemStack, stack)) { + for(IDisplayCategory iDisplayCategory : categories.keySet()) { + if (iDisplayCategory.getId() == iRecipe.getId()) { + categories.get(iDisplayCategory).add(iRecipe); + found = true; + } + } + if (found) + break; + } + } + if (found) + break; + } + } + } + categories.keySet().removeIf(f -> categories.get(f).isEmpty()); + return categories; + } + + + public List<IDisplayCategory> getAdatapersForOutput(ItemStack stack) { + return null; + } + + public List<IDisplayCategory> getAdaptersForOutput(Item item) { + return null; + } + + public void RecipesLoaded(RecipeManager manager) { + recipeList.clear(); + displayAdapters.clear(); + REIRecipeManager.instance().recipeManager = manager; + RiftLoader.instance.getListeners(IREIPlugin.class).forEach(IREIPlugin::register); + } + + public void displayRecipesFor(ItemStack stack) { + Map<IDisplayCategory, List<IRecipe>> recipes = REIRecipeManager.instance().getRecipesFor(stack); + if (recipes.isEmpty()) + return; + RecipeGui gui = new RecipeGui(null, Minecraft.getInstance().currentScreen, recipes); + Minecraft.getInstance().displayGuiScreen(gui); + } + + public void displayUsesFor(ItemStack stack) { + Map<IDisplayCategory, List<IRecipe>> recipes = REIRecipeManager.instance().getUsesFor(stack); + if (recipes.isEmpty()) + return; + RecipeGui gui = new RecipeGui(null, Minecraft.getInstance().currentScreen, recipes); + Minecraft.getInstance().displayGuiScreen(gui); + } +} |
