From 7d593ec3ab105a571f7ec04828557d406d3344d5 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 19 Jun 2019 15:49:04 +0800 Subject: stuff --- .../java/me/shedaniel/rei/RoughlyEnoughItemsCore.java | 2 +- src/main/java/me/shedaniel/rei/api/ClientHelper.java | 2 +- src/main/java/me/shedaniel/rei/api/RecipeHelper.java | 6 +++--- .../java/me/shedaniel/rei/client/ClientHelperImpl.java | 12 ++++++------ .../java/me/shedaniel/rei/client/RecipeHelperImpl.java | 16 ++++++++-------- .../java/me/shedaniel/rei/client/ScreenHelper.java | 16 +++++++++------- .../java/me/shedaniel/rei/client/SearchArgument.java | 12 ++++++------ .../me/shedaniel/rei/gui/PreRecipeViewingScreen.java | 4 ++-- .../java/me/shedaniel/rei/gui/RecipeViewingScreen.java | 18 +++++++++--------- .../shedaniel/rei/gui/VillagerRecipeViewingScreen.java | 16 ++++++++++++---- 10 files changed, 57 insertions(+), 47 deletions(-) (limited to 'src/main/java/me') diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index ca1bef9b0..9a5906f32 100644 --- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -171,7 +171,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { if (screen instanceof AbstractContainerScreen) { if (screen instanceof InventoryScreen && minecraftClient.interactionManager.hasCreativeInventory()) return; - ScreenHelper.setLastContainerScreen((AbstractContainerScreen) screen); + ScreenHelper.setLastContainerScreen((AbstractContainerScreen) screen); boolean alreadyAdded = false; for(Element element : Lists.newArrayList(screenHooks.cloth_getInputListeners())) if (ContainerScreenOverlay.class.isAssignableFrom(element.getClass())) diff --git a/src/main/java/me/shedaniel/rei/api/ClientHelper.java b/src/main/java/me/shedaniel/rei/api/ClientHelper.java index 7560564e2..7b6c8b0e7 100644 --- a/src/main/java/me/shedaniel/rei/api/ClientHelper.java +++ b/src/main/java/me/shedaniel/rei/api/ClientHelper.java @@ -47,7 +47,7 @@ public interface ClientHelper { * * @param map the map of recipes */ - void openRecipeViewingScreen(Map> map); + void openRecipeViewingScreen(Map, List> map); /** * Registers REI's keybinds using Fabric API. diff --git a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java index d6f2f80fa..f7ddec0c0 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java @@ -92,7 +92,7 @@ public interface RecipeHelper { * @param stack the stack to be crafted * @return the map of recipes */ - Map> getRecipesFor(ItemStack stack); + Map, List> getRecipesFor(ItemStack stack); RecipeCategory getCategory(Identifier identifier); @@ -116,7 +116,7 @@ public interface RecipeHelper { * @param stack the stack to be used * @return the map of recipes */ - Map> getUsagesFor(ItemStack stack); + Map, List> getUsagesFor(ItemStack stack); /** * Gets the optional of the speed crafting button area from a category @@ -155,7 +155,7 @@ public interface RecipeHelper { * * @return the map of recipes */ - Map> getAllRecipes(); + Map, List> getAllRecipes(); List getAllRecipesFromCategory(RecipeCategory category); diff --git a/src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java b/src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java index 047724957..b577d88bf 100644 --- a/src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java +++ b/src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java @@ -178,7 +178,7 @@ public class ClientHelperImpl implements ClientHelper, ClientModInitializer { @Override public boolean executeRecipeKeyBind(ItemStack stack) { - Map> map = RecipeHelper.getInstance().getRecipesFor(stack); + Map, List> map = RecipeHelper.getInstance().getRecipesFor(stack); if (map.keySet().size() > 0) openRecipeViewingScreen(map); return map.keySet().size() > 0; @@ -186,7 +186,7 @@ public class ClientHelperImpl implements ClientHelper, ClientModInitializer { @Override public boolean executeUsageKeyBind(ItemStack stack) { - Map> map = RecipeHelper.getInstance().getUsagesFor(stack); + Map, List> map = RecipeHelper.getInstance().getUsagesFor(stack); if (map.keySet().size() > 0) openRecipeViewingScreen(map); return map.keySet().size() > 0; @@ -205,7 +205,7 @@ public class ClientHelperImpl implements ClientHelper, ClientModInitializer { @Override public boolean executeViewAllRecipesKeyBind() { - Map> map = RecipeHelper.getInstance().getAllRecipes(); + Map, List> map = RecipeHelper.getInstance().getAllRecipes(); if (map.keySet().size() > 0) openRecipeViewingScreen(map); return map.keySet().size() > 0; @@ -213,7 +213,7 @@ public class ClientHelperImpl implements ClientHelper, ClientModInitializer { @Override public boolean executeViewAllRecipesFromCategory(Identifier category) { - Map> map = Maps.newLinkedHashMap(); + Map, List> map = Maps.newLinkedHashMap(); Optional any = RecipeHelper.getInstance().getAllCategories().stream().filter(c -> c.getIdentifier().equals(category)).findAny(); if (!any.isPresent()) return false; @@ -226,7 +226,7 @@ public class ClientHelperImpl implements ClientHelper, ClientModInitializer { @Override public boolean executeViewAllRecipesFromCategories(List categories) { - Map> map = Maps.newLinkedHashMap(); + Map, List> map = Maps.newLinkedHashMap(); for(Identifier category : categories) { Optional any = RecipeHelper.getInstance().getAllCategories().stream().filter(c -> c.getIdentifier().equals(category)).findAny(); if (!any.isPresent()) @@ -240,7 +240,7 @@ public class ClientHelperImpl implements ClientHelper, ClientModInitializer { } @Override - public void openRecipeViewingScreen(Map> map) { + public void openRecipeViewingScreen(Map, List> map) { if (RoughlyEnoughItemsCore.getConfigManager().getConfig().screenType == RecipeScreenType.VILLAGER) MinecraftClient.getInstance().openScreen(new VillagerRecipeViewingScreen(map)); else if (RoughlyEnoughItemsCore.getConfigManager().getConfig().screenType == RecipeScreenType.UNSET) diff --git a/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java b/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java index 9a9415d9b..0835dd1de 100644 --- a/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java +++ b/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java @@ -119,7 +119,7 @@ public class RecipeHelperImpl implements RecipeHelper { } @Override - public Map> getRecipesFor(ItemStack stack) { + public Map, List> getRecipesFor(ItemStack stack) { Map> categoriesMap = new HashMap<>(); categories.forEach(f -> categoriesMap.put(f.getIdentifier(), Lists.newArrayList())); for(Map.Entry> entry : recipeCategoryListMap.entrySet()) { @@ -131,12 +131,12 @@ public class RecipeHelperImpl implements RecipeHelper { } for(LiveRecipeGenerator liveRecipeGenerator : liveRecipeGenerators) ((Optional) liveRecipeGenerator.getRecipeFor(stack)).ifPresent(o -> categoriesMap.get(liveRecipeGenerator.getCategoryIdentifier()).addAll(o)); - Map> recipeCategoryListMap = Maps.newLinkedHashMap(); + Map, List> recipeCategoryListMap = Maps.newLinkedHashMap(); categories.forEach(category -> { if (categoriesMap.containsKey(category.getIdentifier()) && !categoriesMap.get(category.getIdentifier()).isEmpty()) recipeCategoryListMap.put(category, categoriesMap.get(category.getIdentifier()).stream().filter(display -> isDisplayVisible(display)).collect(Collectors.toList())); }); - for(RecipeCategory category : Lists.newArrayList(recipeCategoryListMap.keySet())) + for(RecipeCategory category : Lists.newArrayList(recipeCategoryListMap.keySet())) if (recipeCategoryListMap.get(category).isEmpty()) recipeCategoryListMap.remove(category); return recipeCategoryListMap; @@ -153,7 +153,7 @@ public class RecipeHelperImpl implements RecipeHelper { } @Override - public Map> getUsagesFor(ItemStack stack) { + public Map, List> getUsagesFor(ItemStack stack) { Map> categoriesMap = new HashMap<>(); categories.forEach(f -> categoriesMap.put(f.getIdentifier(), Lists.newArrayList())); for(Map.Entry> entry : recipeCategoryListMap.entrySet()) { @@ -175,12 +175,12 @@ public class RecipeHelperImpl implements RecipeHelper { } for(LiveRecipeGenerator liveRecipeGenerator : liveRecipeGenerators) ((Optional) liveRecipeGenerator.getUsageFor(stack)).ifPresent(o -> categoriesMap.get(liveRecipeGenerator.getCategoryIdentifier()).addAll(o)); - Map> recipeCategoryListMap = Maps.newLinkedHashMap(); + Map, List> recipeCategoryListMap = Maps.newLinkedHashMap(); categories.forEach(category -> { if (categoriesMap.containsKey(category.getIdentifier()) && !categoriesMap.get(category.getIdentifier()).isEmpty()) recipeCategoryListMap.put(category, categoriesMap.get(category.getIdentifier()).stream().filter(display -> isDisplayVisible(display)).collect(Collectors.toList())); }); - for(RecipeCategory category : Lists.newArrayList(recipeCategoryListMap.keySet())) + for(RecipeCategory category : Lists.newArrayList(recipeCategoryListMap.keySet())) if (recipeCategoryListMap.get(category).isEmpty()) recipeCategoryListMap.remove(category); return recipeCategoryListMap; @@ -309,8 +309,8 @@ public class RecipeHelperImpl implements RecipeHelper { } @Override - public Map> getAllRecipes() { - Map> map = Maps.newLinkedHashMap(); + public Map, List> getAllRecipes() { + Map, List> map = Maps.newLinkedHashMap(); categories.forEach(recipeCategory -> { if (recipeCategoryListMap.containsKey(recipeCategory.getIdentifier())) { List list = recipeCategoryListMap.get(recipeCategory.getIdentifier()).stream().filter(display -> isDisplayVisible(display)).collect(Collectors.toList()); diff --git a/src/main/java/me/shedaniel/rei/client/ScreenHelper.java b/src/main/java/me/shedaniel/rei/client/ScreenHelper.java index 15ba7f335..7f898cc49 100644 --- a/src/main/java/me/shedaniel/rei/client/ScreenHelper.java +++ b/src/main/java/me/shedaniel/rei/client/ScreenHelper.java @@ -6,16 +6,17 @@ package me.shedaniel.rei.client; import com.google.common.collect.Lists; +import me.shedaniel.cloth.hooks.ClothClientHooks; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.gui.ContainerScreenOverlay; import me.shedaniel.rei.gui.widget.SearchFieldWidget; import me.shedaniel.rei.listeners.ContainerScreenHooks; import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.fabric.api.event.client.ClientTickCallback; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen; import net.minecraft.client.util.Window; import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; import org.apache.logging.log4j.util.TriConsumer; import java.util.List; @@ -27,7 +28,7 @@ public class ScreenHelper implements ClientModInitializer { public static List inventoryStacks = Lists.newArrayList(); private static boolean overlayVisible = true; private static ContainerScreenOverlay overlay; - private static AbstractContainerScreen lastContainerScreen = null; + private static AbstractContainerScreen lastContainerScreen = null; public static boolean isOverlayVisible() { return overlayVisible; @@ -53,11 +54,11 @@ public class ScreenHelper implements ClientModInitializer { return getLastOverlay(false, false); } - public static AbstractContainerScreen getLastContainerScreen() { + public static AbstractContainerScreen getLastContainerScreen() { return lastContainerScreen; } - public static void setLastContainerScreen(AbstractContainerScreen lastContainerScreen) { + public static void setLastContainerScreen(AbstractContainerScreen lastContainerScreen) { ScreenHelper.lastContainerScreen = lastContainerScreen; } @@ -86,9 +87,10 @@ public class ScreenHelper implements ClientModInitializer { @Override public void onInitializeClient() { - ClientTickCallback.EVENT.register(client -> { - if (lastContainerScreen != client.currentScreen && client.currentScreen instanceof AbstractContainerScreen) - lastContainerScreen = (AbstractContainerScreen) client.currentScreen; + ClothClientHooks.SCREEN_INIT_PRE.register((client, screen, screenHooks) -> { + if (lastContainerScreen != screen && screen instanceof AbstractContainerScreen) + lastContainerScreen = (AbstractContainerScreen) screen; + return ActionResult.PASS; }); } diff --git a/src/main/java/me/shedaniel/rei/client/SearchArgument.java b/src/main/java/me/shedaniel/rei/client/SearchArgument.java index 3e8a34ddb..cf0a5317c 100644 --- a/src/main/java/me/shedaniel/rei/client/SearchArgument.java +++ b/src/main/java/me/shedaniel/rei/client/SearchArgument.java @@ -14,8 +14,8 @@ public class SearchArgument { public static final SearchArgument ALWAYS = new SearchArgument(ArgumentType.ALWAYS, "", true); private ArgumentType argumentType; private String text; - public final Function INCLUDE = s -> boyerMooreHorspoolSearch(text, s) > -1; - public final Function NOT_INCLUDE = s -> boyerMooreHorspoolSearch(text, s) <= -1; + public final Function INCLUDE = s -> search(text, s); + public final Function NOT_INCLUDE = s -> !search(text, s); private boolean include; private Pattern pattern; @@ -29,10 +29,10 @@ public class SearchArgument { this.include = include; } - public static int boyerMooreHorspoolSearch(CharSequence pattern, CharSequence text) { + public static boolean search(CharSequence pattern, CharSequence text) { int patternLength = pattern.length(); if (patternLength == 0) - return 0; + return true; int shift[] = new int[256]; for(int k = 0; k < 256; k++) shift[k] = patternLength; @@ -44,11 +44,11 @@ public class SearchArgument { while (text.charAt(i + j) == pattern.charAt(j)) { j -= 1; if (j < 0) - return i; + return i >= 0; } i = i + shift[text.charAt(i + patternLength - 1)]; } - return -1; + return false; } public Function getFunction(boolean include) { diff --git a/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java index c3ade4191..ca3c982f8 100644 --- a/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java @@ -37,9 +37,9 @@ public class PreRecipeViewingScreen extends Screen { private static final Identifier IDENTIFIER = new Identifier("roughlyenoughitems", "textures/gui/screenshot.png"); private final List widgets; private boolean original; - private Map> map; + private Map, List> map; - public PreRecipeViewingScreen(Map> map) { + public PreRecipeViewingScreen(Map, List> map) { super(new TranslatableComponent("text.rei.recipe_screen_type.selection")); this.widgets = Lists.newArrayList(); this.original = true; diff --git a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java index c782982ac..5e01b1abc 100644 --- a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java @@ -39,8 +39,8 @@ public class RecipeViewingScreen extends Screen { private final List preWidgets; private final List widgets; private final List tabs; - private final Map> categoriesMap; - private final List categories; + private final Map, List> categoriesMap; + private final List> categories; public int guiWidth; public int guiHeight; public int page, categoryPages; @@ -48,10 +48,10 @@ public class RecipeViewingScreen extends Screen { public boolean choosePageActivated; public RecipeChoosePageWidget recipeChoosePageWidget; private Rectangle bounds; - private RecipeCategory selectedCategory; + private RecipeCategory selectedCategory; private ButtonWidget recipeBack, recipeNext, categoryBack, categoryNext; - public RecipeViewingScreen(Map> categoriesMap) { + public RecipeViewingScreen(Map, List> categoriesMap) { super(new TextComponent("")); this.categoryPages = 0; this.preWidgets = Lists.newArrayList(); @@ -64,7 +64,7 @@ public class RecipeViewingScreen extends Screen { if (categoriesMap.containsKey(category)) categories.add(category); }); - this.selectedCategory = categories.get(0); + this.selectedCategory = (RecipeCategory) categories.get(0); this.tabs = new ArrayList<>(); this.choosePageActivated = false; } @@ -150,7 +150,7 @@ public class RecipeViewingScreen extends Screen { currentCategoryIndex--; if (currentCategoryIndex < 0) currentCategoryIndex = categories.size() - 1; - selectedCategory = categories.get(currentCategoryIndex); + selectedCategory = (RecipeCategory) categories.get(currentCategoryIndex); categoryPages = MathHelper.floor(currentCategoryIndex / (double) TABS_PER_PAGE); page = 0; RecipeViewingScreen.this.init(); @@ -186,7 +186,7 @@ public class RecipeViewingScreen extends Screen { currentCategoryIndex++; if (currentCategoryIndex >= categories.size()) currentCategoryIndex = 0; - selectedCategory = categories.get(currentCategoryIndex); + selectedCategory = (RecipeCategory) categories.get(currentCategoryIndex); categoryPages = MathHelper.floor(currentCategoryIndex / (double) TABS_PER_PAGE); page = 0; RecipeViewingScreen.this.init(); @@ -259,7 +259,7 @@ public class RecipeViewingScreen extends Screen { MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F)); if (getId() + categoryPages * TABS_PER_PAGE == categories.indexOf(selectedCategory)) return false; - selectedCategory = categories.get(getId() + categoryPages * TABS_PER_PAGE); + selectedCategory = (RecipeCategory) categories.get(getId() + categoryPages * TABS_PER_PAGE); page = 0; RecipeViewingScreen.this.init(); return true; @@ -334,7 +334,7 @@ public class RecipeViewingScreen extends Screen { return list; } - public RecipeCategory getSelectedCategory() { + public RecipeCategory getSelectedCategory() { return selectedCategory; } diff --git a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java index a657c49b4..5a93b32d5 100644 --- a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java @@ -41,8 +41,8 @@ import java.util.stream.Collectors; public class VillagerRecipeViewingScreen extends Screen { private static final int TABS_PER_PAGE = 8; - private final Map> categoryMap; - private final List categories; + private final Map, List> categoryMap; + private final List> categories; private final List widgets; private final List buttonWidgets; private final List recipeRenderers; @@ -56,7 +56,7 @@ public class VillagerRecipeViewingScreen extends Screen { private boolean draggingScrollBar = false; private int tabsPage; - public VillagerRecipeViewingScreen(Map> map) { + public VillagerRecipeViewingScreen(Map, List> map) { super(new TextComponent("")); this.widgets = Lists.newArrayList(); this.categoryMap = Maps.newLinkedHashMap(); @@ -90,7 +90,7 @@ public class VillagerRecipeViewingScreen extends Screen { this.tabs.clear(); int largestWidth = width - 100; int largestHeight = height - 40; - RecipeCategory category = categories.get(selectedCategoryIndex); + RecipeCategory category = (RecipeCategory) categories.get(selectedCategoryIndex); RecipeDisplay display = categoryMap.get(category).get(selectedRecipeIndex); int guiWidth = MathHelper.clamp(category.getDisplayWidth(display) + 30, 0, largestWidth) + 100; int guiHeight = MathHelper.clamp(category.getDisplayHeight() + 40, 166, largestHeight); @@ -249,6 +249,14 @@ public class VillagerRecipeViewingScreen extends Screen { return super.mouseClicked(mouseX, mouseY, int_1); } + @Override + public boolean charTyped(char char_1, int int_1) { + for(Element listener : children()) + if (listener.charTyped(char_1, int_1)) + return true; + return super.charTyped(char_1, int_1); + } + @Override public boolean mouseScrolled(double double_1, double double_2, double double_3) { double height = buttonWidgets.stream().map(ButtonWidget::getBounds).collect(Collectors.summingDouble(Rectangle::getHeight)); -- cgit