diff options
| author | Unknown <shekwancheung0528@gmail.com> | 2019-01-30 00:12:47 +0800 |
|---|---|---|
| committer | Unknown <shekwancheung0528@gmail.com> | 2019-01-30 00:12:47 +0800 |
| commit | e7ba883beed7d3d5697c1095249c7dd05518ba76 (patch) | |
| tree | 4eb02c5643701791294dbe85fd704c5505bae272 /src/main/java/me/shedaniel/rei/client | |
| parent | e8353e0d95d00266e9b188a816b73ce7a4dc090b (diff) | |
| download | RoughlyEnoughItems-e7ba883beed7d3d5697c1095249c7dd05518ba76.tar.gz RoughlyEnoughItems-e7ba883beed7d3d5697c1095249c7dd05518ba76.tar.bz2 RoughlyEnoughItems-e7ba883beed7d3d5697c1095249c7dd05518ba76.zip | |
Fixes Bugs
Close #13
Close #15
Close #18
Diffstat (limited to 'src/main/java/me/shedaniel/rei/client')
3 files changed, 64 insertions, 46 deletions
diff --git a/src/main/java/me/shedaniel/rei/client/ClientHelper.java b/src/main/java/me/shedaniel/rei/client/ClientHelper.java index 86b099bc3..55061aa90 100644 --- a/src/main/java/me/shedaniel/rei/client/ClientHelper.java +++ b/src/main/java/me/shedaniel/rei/client/ClientHelper.java @@ -9,7 +9,6 @@ import me.shedaniel.rei.api.IRecipeDisplay; import me.shedaniel.rei.gui.ContainerGuiOverlay; import me.shedaniel.rei.gui.widget.ConfigWidget; import me.shedaniel.rei.gui.widget.RecipeViewingWidget; -import me.shedaniel.rei.listeners.IMixinContainerGui; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding; import net.fabricmc.fabric.impl.client.keybinding.KeyBindingRegistryImpl; @@ -116,17 +115,17 @@ public class ClientHelper implements ClientModInitializer { } } - public static boolean executeRecipeKeyBind(ContainerGuiOverlay overlay, ItemStack stack, IMixinContainerGui parent) { - Map<IRecipeCategory, List<IRecipeDisplay>> map = RecipeHelper.getRecipesFor(stack); + public static boolean executeRecipeKeyBind(ContainerGuiOverlay overlay, ItemStack stack) { + Map<IRecipeCategory, List<IRecipeDisplay>> map = RecipeHelper.getInstance().getRecipesFor(stack); if (map.keySet().size() > 0) - MinecraftClient.getInstance().openGui(new RecipeViewingWidget(MinecraftClient.getInstance().window, parent, map)); + MinecraftClient.getInstance().openGui(new RecipeViewingWidget(MinecraftClient.getInstance().window, map)); return map.keySet().size() > 0; } - public static boolean executeUsageKeyBind(ContainerGuiOverlay overlay, ItemStack stack, IMixinContainerGui parent) { - Map<IRecipeCategory, List<IRecipeDisplay>> map = RecipeHelper.getUsagesFor(stack); + public static boolean executeUsageKeyBind(ContainerGuiOverlay overlay, ItemStack stack) { + Map<IRecipeCategory, List<IRecipeDisplay>> map = RecipeHelper.getInstance().getUsagesFor(stack); if (map.keySet().size() > 0) - MinecraftClient.getInstance().openGui(new RecipeViewingWidget(MinecraftClient.getInstance().window, parent, map)); + MinecraftClient.getInstance().openGui(new RecipeViewingWidget(MinecraftClient.getInstance().window, map)); return map.keySet().size() > 0; } diff --git a/src/main/java/me/shedaniel/rei/client/GuiHelper.java b/src/main/java/me/shedaniel/rei/client/GuiHelper.java index 6fbb6a2a8..b962866f2 100644 --- a/src/main/java/me/shedaniel/rei/client/GuiHelper.java +++ b/src/main/java/me/shedaniel/rei/client/GuiHelper.java @@ -4,6 +4,7 @@ import com.google.common.collect.Lists; import me.shedaniel.rei.gui.ContainerGuiOverlay; import me.shedaniel.rei.gui.widget.TextFieldWidget; import me.shedaniel.rei.listeners.IMixinContainerGui; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.ContainerGui; import net.minecraft.item.ItemStack; @@ -15,6 +16,8 @@ public class GuiHelper { private static boolean overlayVisible = true; private static ContainerGuiOverlay overlay; public static List<ItemStack> inventoryStacks = Lists.newArrayList(); + private static ContainerGui lastContainerGui; + private static IMixinContainerGui lastMixinContainerGui; public static boolean isOverlayVisible() { return overlayVisible; @@ -24,14 +27,6 @@ public class GuiHelper { overlayVisible = !overlayVisible; } - public static ContainerGuiOverlay getOverlay(IMixinContainerGui lastGui) { - if (overlay == null) { - overlay = new ContainerGuiOverlay(lastGui); - overlay.onInitialized(); - } - return overlay; - } - public static ContainerGuiOverlay getLastOverlay() { return overlay; } @@ -41,8 +36,27 @@ public class GuiHelper { overlay.onInitialized(); } - public static void resetOverlay() { - overlay = null; + public static void onTick(MinecraftClient client) { + if (client.currentGui instanceof ContainerGui && lastContainerGui != client.currentGui) { + GuiHelper.lastContainerGui = (ContainerGui) client.currentGui; + GuiHelper.lastMixinContainerGui = (IMixinContainerGui) lastContainerGui; + } + } + + public static ContainerGui getLastContainerGui() { + return lastContainerGui; + } + + public static IMixinContainerGui getLastMixinContainerGui() { + return lastMixinContainerGui; + } + + public static void setLastContainerGui(ContainerGui lastContainerGui) { + GuiHelper.lastContainerGui = lastContainerGui; + } + + public static void setLastMixinContainerGui(IMixinContainerGui lastMixinContainerGui) { + GuiHelper.lastMixinContainerGui = lastMixinContainerGui; } } diff --git a/src/main/java/me/shedaniel/rei/client/RecipeHelper.java b/src/main/java/me/shedaniel/rei/client/RecipeHelper.java index 378eb2f59..0224933fa 100644 --- a/src/main/java/me/shedaniel/rei/client/RecipeHelper.java +++ b/src/main/java/me/shedaniel/rei/client/RecipeHelper.java @@ -15,20 +15,17 @@ import java.util.stream.Collectors; public class RecipeHelper { - private static Map<Identifier, List<IRecipeDisplay>> recipeCategoryListMap; - private static List<IRecipeCategory> categories; - private static RecipeManager recipeManager; - private static Map<Identifier, SpeedCraftAreaSupplier> speedCraftAreaSupplierMap; - private static Map<Identifier, List<SpeedCraftFunctional>> speedCraftFunctionalMap; - - public RecipeHelper() { - this.recipeCategoryListMap = Maps.newHashMap(); - this.categories = Lists.newArrayList(); - this.speedCraftAreaSupplierMap = Maps.newHashMap(); - this.speedCraftFunctionalMap = Maps.newHashMap(); + private final Map<Identifier, List<IRecipeDisplay>> recipeCategoryListMap = Maps.newHashMap(); + private final List<IRecipeCategory> categories = Lists.newArrayList(); + private final Map<Identifier, SpeedCraftAreaSupplier> speedCraftAreaSupplierMap = Maps.newHashMap(); + private final Map<Identifier, List<SpeedCraftFunctional>> speedCraftFunctionalMap = Maps.newHashMap(); + private RecipeManager recipeManager; + + public static RecipeHelper getInstance() { + return RoughlyEnoughItemsCore.getRecipeHelper(); } - public static List<ItemStack> findCraftableByItems(List<ItemStack> inventoryItems) { + public List<ItemStack> findCraftableByItems(List<ItemStack> inventoryItems) { List<ItemStack> craftables = new ArrayList<>(); for(List<IRecipeDisplay> value : recipeCategoryListMap.values()) for(IRecipeDisplay recipeDisplay : value) { @@ -57,25 +54,27 @@ public class RecipeHelper { return craftables.stream().distinct().collect(Collectors.toList()); } - public static void registerCategory(IRecipeCategory category) { + public void registerCategory(IRecipeCategory category) { categories.add(category); recipeCategoryListMap.put(category.getIdentifier(), Lists.newArrayList()); } - public static void registerRecipe(Identifier categoryIdentifier, IRecipeDisplay display) { + public void registerRecipe(Identifier categoryIdentifier, IRecipeDisplay display) { if (!recipeCategoryListMap.containsKey(categoryIdentifier)) return; recipeCategoryListMap.get(categoryIdentifier).add(display); } - public static Map<IRecipeCategory, List<IRecipeDisplay>> getRecipesFor(ItemStack stack) { + public Map<IRecipeCategory, List<IRecipeDisplay>> getRecipesFor(ItemStack stack) { Map<Identifier, List<IRecipeDisplay>> categoriesMap = new HashMap<>(); categories.forEach(f -> categoriesMap.put(f.getIdentifier(), new LinkedList<>())); - for(List<IRecipeDisplay> value : recipeCategoryListMap.values()) - for(IRecipeDisplay recipeDisplay : value) + for(Map.Entry<Identifier, List<IRecipeDisplay>> entry : recipeCategoryListMap.entrySet()) { + IRecipeCategory category = getCategory(entry.getKey()); + for(IRecipeDisplay recipeDisplay : entry.getValue()) for(ItemStack outputStack : (List<ItemStack>) recipeDisplay.getOutput()) - if (ItemStack.areEqualIgnoreTags(stack, outputStack)) + if (category.checkTags() ? ItemStack.areEqual(stack, outputStack) : ItemStack.areEqualIgnoreTags(stack, outputStack)) categoriesMap.get(recipeDisplay.getRecipeCategory()).add(recipeDisplay); + } categoriesMap.keySet().removeIf(f -> categoriesMap.get(f).isEmpty()); Map<IRecipeCategory, List<IRecipeDisplay>> recipeCategoryListMap = Maps.newHashMap(); categories.forEach(category -> { @@ -85,19 +84,24 @@ public class RecipeHelper { return recipeCategoryListMap; } - public static RecipeManager getRecipeManager() { + private IRecipeCategory getCategory(Identifier identifier) { + return categories.stream().filter(category -> category.getIdentifier().equals(identifier)).findFirst().orElse(null); + } + + public RecipeManager getRecipeManager() { return recipeManager; } - public static Map<IRecipeCategory, List<IRecipeDisplay>> getUsagesFor(ItemStack stack) { + public Map<IRecipeCategory, List<IRecipeDisplay>> getUsagesFor(ItemStack stack) { Map<Identifier, List<IRecipeDisplay>> categoriesMap = new HashMap<>(); categories.forEach(f -> categoriesMap.put(f.getIdentifier(), new LinkedList<>())); - for(List<IRecipeDisplay> value : recipeCategoryListMap.values()) - for(IRecipeDisplay recipeDisplay : value) { + for(Map.Entry<Identifier, List<IRecipeDisplay>> entry : recipeCategoryListMap.entrySet()) { + IRecipeCategory category = getCategory(entry.getKey()); + for(IRecipeDisplay recipeDisplay : entry.getValue()) { boolean found = false; for(List<ItemStack> input : (List<List<ItemStack>>) recipeDisplay.getInput()) { for(ItemStack itemStack : input) { - if (ItemStack.areEqualIgnoreTags(itemStack, stack)) { + if (category.checkTags() ? ItemStack.areEqual(itemStack, stack) : ItemStack.areEqualIgnoreTags(itemStack, stack)) { categoriesMap.get(recipeDisplay.getRecipeCategory()).add(recipeDisplay); found = true; break; @@ -107,6 +111,7 @@ public class RecipeHelper { break; } } + } categoriesMap.keySet().removeIf(f -> categoriesMap.get(f).isEmpty()); Map<IRecipeCategory, List<IRecipeDisplay>> recipeCategoryListMap = Maps.newHashMap(); categories.forEach(category -> { @@ -116,11 +121,11 @@ public class RecipeHelper { return recipeCategoryListMap; } - public static List<IRecipeCategory> getCategories() { - return categories; + public List<IRecipeCategory> getCategories() { + return new LinkedList<>(categories); } - public static SpeedCraftAreaSupplier getSpeedCraftButtonArea(IRecipeCategory category) { + public SpeedCraftAreaSupplier getSpeedCraftButtonArea(IRecipeCategory category) { if (!speedCraftAreaSupplierMap.containsKey(category.getIdentifier())) return bounds -> { return new Rectangle((int) bounds.getMaxX() - 16, (int) bounds.getMaxY() - 16, 10, 10); @@ -128,17 +133,17 @@ public class RecipeHelper { return speedCraftAreaSupplierMap.get(category.getIdentifier()); } - public static void registerSpeedCraftButtonArea(Identifier category, SpeedCraftAreaSupplier rectangle) { + public void registerSpeedCraftButtonArea(Identifier category, SpeedCraftAreaSupplier rectangle) { speedCraftAreaSupplierMap.put(category, rectangle); } - public static List<SpeedCraftFunctional> getSpeedCraftFunctional(IRecipeCategory category) { + public List<SpeedCraftFunctional> getSpeedCraftFunctional(IRecipeCategory category) { if (speedCraftFunctionalMap.get(category.getIdentifier()) == null) return Lists.newArrayList(); return speedCraftFunctionalMap.get(category.getIdentifier()); } - public static void registerSpeedCraftFunctional(Identifier category, SpeedCraftFunctional functional) { + public void registerSpeedCraftFunctional(Identifier category, SpeedCraftFunctional functional) { List<SpeedCraftFunctional> list = speedCraftFunctionalMap.containsKey(category) ? new LinkedList<>(speedCraftFunctionalMap.get(category)) : Lists.newLinkedList(); list.add(functional); speedCraftFunctionalMap.put(category, list); |
