diff options
Diffstat (limited to 'src/main/java')
10 files changed, 57 insertions, 47 deletions
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<RecipeCategory, List<RecipeDisplay>> map); + void openRecipeViewingScreen(Map<RecipeCategory<?>, List<RecipeDisplay>> 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<RecipeCategory, List<RecipeDisplay>> getRecipesFor(ItemStack stack); + Map<RecipeCategory<?>, List<RecipeDisplay>> 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<RecipeCategory, List<RecipeDisplay>> getUsagesFor(ItemStack stack); + Map<RecipeCategory<?>, List<RecipeDisplay>> 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<RecipeCategory, List<RecipeDisplay>> getAllRecipes(); + Map<RecipeCategory<?>, List<RecipeDisplay>> getAllRecipes(); List<RecipeDisplay> 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<RecipeCategory, List<RecipeDisplay>> map = RecipeHelper.getInstance().getRecipesFor(stack); + Map<RecipeCategory<?>, List<RecipeDisplay>> 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<RecipeCategory, List<RecipeDisplay>> map = RecipeHelper.getInstance().getUsagesFor(stack); + Map<RecipeCategory<?>, List<RecipeDisplay>> 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<RecipeCategory, List<RecipeDisplay>> map = RecipeHelper.getInstance().getAllRecipes(); + Map<RecipeCategory<?>, List<RecipeDisplay>> 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<RecipeCategory, List<RecipeDisplay>> map = Maps.newLinkedHashMap(); + Map<RecipeCategory<?>, List<RecipeDisplay>> map = Maps.newLinkedHashMap(); Optional<RecipeCategory> 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<Identifier> categories) { - Map<RecipeCategory, List<RecipeDisplay>> map = Maps.newLinkedHashMap(); + Map<RecipeCategory<?>, List<RecipeDisplay>> map = Maps.newLinkedHashMap(); for(Identifier category : categories) { Optional<RecipeCategory> 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<RecipeCategory, List<RecipeDisplay>> map) { + public void openRecipeViewingScreen(Map<RecipeCategory<?>, List<RecipeDisplay>> 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<RecipeCategory, List<RecipeDisplay>> getRecipesFor(ItemStack stack) { + public Map<RecipeCategory<?>, List<RecipeDisplay>> getRecipesFor(ItemStack stack) { Map<Identifier, List<RecipeDisplay>> categoriesMap = new HashMap<>(); categories.forEach(f -> categoriesMap.put(f.getIdentifier(), Lists.newArrayList())); for(Map.Entry<Identifier, List<RecipeDisplay>> entry : recipeCategoryListMap.entrySet()) { @@ -131,12 +131,12 @@ public class RecipeHelperImpl implements RecipeHelper { } for(LiveRecipeGenerator liveRecipeGenerator : liveRecipeGenerators) ((Optional<List>) liveRecipeGenerator.getRecipeFor(stack)).ifPresent(o -> categoriesMap.get(liveRecipeGenerator.getCategoryIdentifier()).addAll(o)); - Map<RecipeCategory, List<RecipeDisplay>> recipeCategoryListMap = Maps.newLinkedHashMap(); + Map<RecipeCategory<?>, List<RecipeDisplay>> 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<RecipeCategory, List<RecipeDisplay>> getUsagesFor(ItemStack stack) { + public Map<RecipeCategory<?>, List<RecipeDisplay>> getUsagesFor(ItemStack stack) { Map<Identifier, List<RecipeDisplay>> categoriesMap = new HashMap<>(); categories.forEach(f -> categoriesMap.put(f.getIdentifier(), Lists.newArrayList())); for(Map.Entry<Identifier, List<RecipeDisplay>> entry : recipeCategoryListMap.entrySet()) { @@ -175,12 +175,12 @@ public class RecipeHelperImpl implements RecipeHelper { } for(LiveRecipeGenerator liveRecipeGenerator : liveRecipeGenerators) ((Optional<List>) liveRecipeGenerator.getUsageFor(stack)).ifPresent(o -> categoriesMap.get(liveRecipeGenerator.getCategoryIdentifier()).addAll(o)); - Map<RecipeCategory, List<RecipeDisplay>> recipeCategoryListMap = Maps.newLinkedHashMap(); + Map<RecipeCategory<?>, List<RecipeDisplay>> 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<RecipeCategory, List<RecipeDisplay>> getAllRecipes() { - Map<RecipeCategory, List<RecipeDisplay>> map = Maps.newLinkedHashMap(); + public Map<RecipeCategory<?>, List<RecipeDisplay>> getAllRecipes() { + Map<RecipeCategory<?>, List<RecipeDisplay>> map = Maps.newLinkedHashMap(); categories.forEach(recipeCategory -> { if (recipeCategoryListMap.containsKey(recipeCategory.getIdentifier())) { List<RecipeDisplay> 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<ItemStack> 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<String, Boolean> INCLUDE = s -> boyerMooreHorspoolSearch(text, s) > -1; - public final Function<String, Boolean> NOT_INCLUDE = s -> boyerMooreHorspoolSearch(text, s) <= -1; + public final Function<String, Boolean> INCLUDE = s -> search(text, s); + public final Function<String, Boolean> 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<String, Boolean> 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<Widget> widgets; private boolean original; - private Map<RecipeCategory, List<RecipeDisplay>> map; + private Map<RecipeCategory<?>, List<RecipeDisplay>> map; - public PreRecipeViewingScreen(Map<RecipeCategory, List<RecipeDisplay>> map) { + public PreRecipeViewingScreen(Map<RecipeCategory<?>, List<RecipeDisplay>> 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<Widget> preWidgets; private final List<Widget> widgets; private final List<TabWidget> tabs; - private final Map<RecipeCategory, List<RecipeDisplay>> categoriesMap; - private final List<RecipeCategory> categories; + private final Map<RecipeCategory<?>, List<RecipeDisplay>> categoriesMap; + private final List<RecipeCategory<?>> 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<RecipeDisplay> selectedCategory; private ButtonWidget recipeBack, recipeNext, categoryBack, categoryNext; - public RecipeViewingScreen(Map<RecipeCategory, List<RecipeDisplay>> categoriesMap) { + public RecipeViewingScreen(Map<RecipeCategory<?>, List<RecipeDisplay>> 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<RecipeDisplay>) 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<RecipeDisplay>) 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<RecipeDisplay>) 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<RecipeDisplay>) 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<RecipeCategory, List<RecipeDisplay>> categoryMap; - private final List<RecipeCategory> categories; + private final Map<RecipeCategory<?>, List<RecipeDisplay>> categoryMap; + private final List<RecipeCategory<?>> categories; private final List<Widget> widgets; private final List<ButtonWidget> buttonWidgets; private final List<Renderer> recipeRenderers; @@ -56,7 +56,7 @@ public class VillagerRecipeViewingScreen extends Screen { private boolean draggingScrollBar = false; private int tabsPage; - public VillagerRecipeViewingScreen(Map<RecipeCategory, List<RecipeDisplay>> map) { + public VillagerRecipeViewingScreen(Map<RecipeCategory<?>, List<RecipeDisplay>> 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<RecipeDisplay> category = (RecipeCategory<RecipeDisplay>) 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); @@ -250,6 +250,14 @@ public class VillagerRecipeViewingScreen extends Screen { } @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)); if (scrollListBounds.contains(double_1, double_2) && height > scrollListBounds.height - 2) { |
