diff options
42 files changed, 1877 insertions, 512 deletions
diff --git a/build.gradle b/build.gradle index 64d1d2d5b..6371abebe 100755 --- a/build.gradle +++ b/build.gradle @@ -117,7 +117,7 @@ curseforge { df.setTimeZone(TimeZone.getTimeZone("UTC")) def time = df.format(new Date()) changelog = "<h2>REI v$project.version</h2>Updated at <b>$time</b>.<br><a href=\"https://gist.github.com/shedaniel/b7593e692319976f3349263208792922\">Click here for full changelog</a>" - addGameVersion '1.15-Snapshot' + addGameVersion '1.16-Snapshot' addGameVersion 'Java 8' addGameVersion 'Fabric' relations { @@ -126,7 +126,7 @@ curseforge { embeddedLibrary 'cloth-config' } mainArtifact(file("${project.buildDir}/libs/${project.archivesBaseName}-${project.version}.jar")) { - displayName = "[Fabric 20w06a] v$project.version" + displayName = "[Fabric 20w07a] v$project.version" } afterEvaluate { uploadTask.dependsOn("remapJar") diff --git a/gradle.properties b/gradle.properties index b1ad76978..f59c7a87f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,11 +1,11 @@ -mod_version=4.0.0-unstable -minecraft_version=20w06a -yarn_version=20w06a+build.3 +mod_version=4.0.4-unstable +minecraft_version=20w07a +yarn_version=20w07a+build.1 fabricloader_version=0.7.8+build.184 cloth_events_version=1.2.0 -cloth_config_version=2.9.3 -modmenu_version=1.8.5+build.23 -fabric_api=0.4.30+build.294-1.16 +cloth_config_version=2.10 +modmenu_version=1.10.1+build.30 +fabric_api=0.4.33+build.298-1.16 autoconfig1u=1.2.4 api_include=me.shedaniel.cloth:cloth-events,me.shedaniel.cloth:config-2,me.sargunvohra.mcmods:autoconfig1u,org.jetbrains:annotations api_exculde= diff --git a/src/main/java/me/shedaniel/rei/REIModMenuEntryPoint.java b/src/main/java/me/shedaniel/rei/REIModMenuEntryPoint.java index 15d45f389..08951a061 100644 --- a/src/main/java/me/shedaniel/rei/REIModMenuEntryPoint.java +++ b/src/main/java/me/shedaniel/rei/REIModMenuEntryPoint.java @@ -5,11 +5,9 @@ package me.shedaniel.rei; +import io.github.prospector.modmenu.api.ConfigScreenFactory; import io.github.prospector.modmenu.api.ModMenuApi; import me.shedaniel.rei.api.ConfigManager; -import net.minecraft.client.gui.screen.Screen; - -import java.util.function.Function; public class REIModMenuEntryPoint implements ModMenuApi { @@ -19,8 +17,7 @@ public class REIModMenuEntryPoint implements ModMenuApi { } @Override - public Function<Screen, ? extends Screen> getConfigScreenFactory() { + public ConfigScreenFactory<?> getModConfigScreenFactory() { return parent -> ConfigManager.getInstance().getConfigScreen(parent); } - } diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index f007f5008..0d19edfdb 100644 --- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -52,7 +52,6 @@ import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.atomic.AtomicLong; @ApiStatus.Internal public class RoughlyEnoughItemsCore implements ClientModInitializer { @@ -131,13 +130,13 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { } @ApiStatus.Internal - public static void syncRecipes(AtomicLong lastSync) { + public static void syncRecipes(long[] lastSync) { if (lastSync != null) { - if (lastSync.get() > 0 && System.currentTimeMillis() - lastSync.get() <= 5000) { + if (lastSync[0] > 0 && System.currentTimeMillis() - lastSync[0] <= 5000) { RoughlyEnoughItemsCore.LOGGER.warn("[REI] Suppressing Sync Recipes!"); return; } - lastSync.set(System.currentTimeMillis()); + lastSync[0] = System.currentTimeMillis(); } RecipeManager recipeManager = MinecraftClient.getInstance().getNetworkHandler().getRecipeManager(); if (ConfigObject.getInstance().doesRegisterRecipesInAnotherThread()) { @@ -147,6 +146,11 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { } } + @ApiStatus.Internal + public static boolean isDebugModeEnabled() { + return System.getProperty("rei.test", "false").equals("true"); + } + @Override public void onInitializeClient() { configManager = new ConfigManagerImpl(); @@ -220,14 +224,25 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { } private void loadTestPlugins() { - if (System.getProperty("rei.test", "false").equals("true")) { + if (isDebugModeEnabled()) { registerPlugin(new REITestPlugin()); } } + private boolean shouldReturn(Class<?> screen) { + for (OverlayDecider decider : DisplayHelper.getInstance().getAllOverlayDeciders()) { + if (!decider.isHandingScreen(screen)) + continue; + ActionResult result = decider.shouldScreenBeOverlayed(screen); + if (result != ActionResult.PASS) + return result == ActionResult.FAIL || ScreenHelper.getLastContainerScreenHooks() == null; + } + return true; + } + private void registerClothEvents() { final Identifier recipeButtonTex = new Identifier("textures/gui/recipe_button.png"); - AtomicLong lastSync = new AtomicLong(-1); + long[] lastSync = {-1}; ClothClientHooks.SYNC_RECIPES.register((minecraftClient, recipeManager, synchronizeRecipesS2CPacket) -> syncRecipes(lastSync)); ClothClientHooks.SCREEN_ADD_BUTTON.register((minecraftClient, screen, abstractButtonWidget) -> { if (ConfigObject.getInstance().doesDisableRecipeBook() && screen instanceof ContainerScreen && abstractButtonWidget instanceof TexturedButtonWidget) @@ -236,29 +251,32 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { return ActionResult.PASS; }); ClothClientHooks.SCREEN_INIT_POST.register((minecraftClient, screen, screenHooks) -> { - if (screen instanceof ContainerScreen) { - if (screen instanceof InventoryScreen && minecraftClient.interactionManager.hasCreativeInventory()) - return; + if (screen instanceof InventoryScreen && minecraftClient.interactionManager.hasCreativeInventory()) + return; + if (shouldReturn(screen.getClass())) + return; + if (screen instanceof ContainerScreen) ScreenHelper.setLastContainerScreen((ContainerScreen<?>) screen); - boolean alreadyAdded = false; - for (Element element : Lists.newArrayList(screenHooks.cloth_getInputListeners())) - if (ContainerScreenOverlay.class.isAssignableFrom(element.getClass())) - if (alreadyAdded) - screenHooks.cloth_getInputListeners().remove(element); - else - alreadyAdded = true; - if (!alreadyAdded) - screenHooks.cloth_getInputListeners().add(ScreenHelper.getLastOverlay(true, false)); - } + boolean alreadyAdded = false; + for (Element element : Lists.newArrayList(screenHooks.cloth_getInputListeners())) + if (ContainerScreenOverlay.class.isAssignableFrom(element.getClass())) + if (alreadyAdded) + screenHooks.cloth_getInputListeners().remove(element); + else + alreadyAdded = true; + if (!alreadyAdded) + screenHooks.cloth_getInputListeners().add(ScreenHelper.getLastOverlay(true, false)); }); ClothClientHooks.SCREEN_RENDER_POST.register((minecraftClient, screen, i, i1, v) -> { - if (screen instanceof ContainerScreen) - ScreenHelper.getLastOverlay().render(i, i1, v); + if (shouldReturn(screen.getClass())) + return; + ScreenHelper.getLastOverlay().render(i, i1, v); }); ClothClientHooks.SCREEN_MOUSE_DRAGGED.register((minecraftClient, screen, v, v1, i, v2, v3) -> { - if (screen instanceof ContainerScreen) - if (ScreenHelper.isOverlayVisible() && ScreenHelper.getLastOverlay().mouseDragged(v, v1, i, v2, v3)) - return ActionResult.SUCCESS; + if (shouldReturn(screen.getClass())) + return ActionResult.PASS; + if (ScreenHelper.isOverlayVisible() && ScreenHelper.getLastOverlay().mouseDragged(v, v1, i, v2, v3)) + return ActionResult.SUCCESS; return ActionResult.PASS; }); ClothClientHooks.SCREEN_MOUSE_CLICKED.register((minecraftClient, screen, v, v1, i) -> { @@ -272,29 +290,33 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { return ActionResult.PASS; }); ClothClientHooks.SCREEN_MOUSE_SCROLLED.register((minecraftClient, screen, v, v1, v2) -> { - if (screen instanceof ContainerScreen) - if (ScreenHelper.isOverlayVisible() && ScreenHelper.getLastOverlay().mouseScrolled(v, v1, v2)) - return ActionResult.SUCCESS; + if (shouldReturn(screen.getClass())) + return ActionResult.PASS; + if (ScreenHelper.isOverlayVisible() && ScreenHelper.getLastOverlay().mouseScrolled(v, v1, v2)) + return ActionResult.SUCCESS; return ActionResult.PASS; }); ClothClientHooks.SCREEN_CHAR_TYPED.register((minecraftClient, screen, character, keyCode) -> { - if (screen instanceof ContainerScreen) - if (ScreenHelper.getLastOverlay().charTyped(character, keyCode)) - return ActionResult.SUCCESS; + if (shouldReturn(screen.getClass())) + return ActionResult.PASS; + if (ScreenHelper.getLastOverlay().charTyped(character, keyCode)) + return ActionResult.SUCCESS; return ActionResult.PASS; }); ClothClientHooks.SCREEN_LATE_RENDER.register((minecraftClient, screen, i, i1, v) -> { if (!ScreenHelper.isOverlayVisible()) return; - if (screen instanceof ContainerScreen) - ScreenHelper.getLastOverlay().lateRender(i, i1, v); + if (shouldReturn(screen.getClass())) + return; + ScreenHelper.getLastOverlay().lateRender(i, i1, v); }); ClothClientHooks.SCREEN_KEY_PRESSED.register((minecraftClient, screen, i, i1, i2) -> { if (screen.getFocused() != null && screen.getFocused() instanceof TextFieldWidget || (screen.getFocused() instanceof RecipeBookWidget && ((RecipeBookGuiHooks) screen.getFocused()).rei_getSearchField() != null && ((RecipeBookGuiHooks) screen.getFocused()).rei_getSearchField().isFocused())) return ActionResult.PASS; - if (screen instanceof ContainerScreen) - if (ScreenHelper.getLastOverlay().keyPressed(i, i1, i2)) - return ActionResult.SUCCESS; + if (shouldReturn(screen.getClass())) + return ActionResult.PASS; + if (ScreenHelper.getLastOverlay().keyPressed(i, i1, i2)) + return ActionResult.SUCCESS; if (screen instanceof ContainerScreen && ConfigObject.getInstance().doesDisableRecipeBook() && ConfigObject.getInstance().doesFixTabCloseContainer()) if (i == 258 && minecraftClient.options.keyInventory.matchesKey(i, i1)) { minecraftClient.player.closeContainer(); diff --git a/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java b/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java index 1bd251725..7efc6d19a 100644 --- a/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java +++ b/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java @@ -12,6 +12,11 @@ import java.util.List; import java.util.function.Supplier; public interface BaseBoundsHandler extends DisplayHelper.DisplayBoundsHandler<Screen> { + + static BaseBoundsHandler getInstance() { + return DisplayHelper.getInstance().getBaseBoundsHandler(); + } + /** * Gets the exclusion zones by the screen class * diff --git a/src/main/java/me/shedaniel/rei/api/ConfigManager.java b/src/main/java/me/shedaniel/rei/api/ConfigManager.java index 3f0da4e93..d87beb1c7 100644 --- a/src/main/java/me/shedaniel/rei/api/ConfigManager.java +++ b/src/main/java/me/shedaniel/rei/api/ConfigManager.java @@ -17,6 +17,7 @@ public interface ConfigManager { return RoughlyEnoughItemsCore.getConfigManager(); } + @Deprecated List<EntryStack> getFavorites(); /** diff --git a/src/main/java/me/shedaniel/rei/api/ConfigObject.java b/src/main/java/me/shedaniel/rei/api/ConfigObject.java index c45ae56c9..e882f2e9d 100644 --- a/src/main/java/me/shedaniel/rei/api/ConfigObject.java +++ b/src/main/java/me/shedaniel/rei/api/ConfigObject.java @@ -13,10 +13,7 @@ import me.shedaniel.rei.impl.ConfigManagerImpl; import me.shedaniel.rei.impl.ConfigObjectImpl; import org.jetbrains.annotations.ApiStatus; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; +import java.util.List; public interface ConfigObject { @@ -121,28 +118,16 @@ public interface ConfigObject { boolean isLowerConfigButton(); - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.FIELD}) - @interface AddInFrontKeyCode {} + List<EntryStack> getFavorites(); - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.FIELD}) - @interface DontApplyFieldName {} + List<EntryStack> getFilteredStacks(); - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.FIELD}) - @interface UseEnumSelectorInstead {} + @ApiStatus.Experimental + boolean shouldAsyncSearch(); - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.FIELD}) - @interface UseSpecialRecipeTypeScreen {} - - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.FIELD}) - @interface UsePercentage { - double min(); - - double max(); - } + @ApiStatus.Experimental + int getNumberAsyncSearch(); + @ApiStatus.Experimental + boolean doDebugSearchTimeRequired(); } diff --git a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java index 2e1a174b1..a641eb372 100644 --- a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java +++ b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java @@ -8,7 +8,9 @@ package me.shedaniel.rei.api; import me.shedaniel.math.api.Rectangle; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.gui.config.SearchFieldLocation; +import me.shedaniel.rei.utils.CollectionUtils; import net.minecraft.util.ActionResult; +import org.jetbrains.annotations.ApiStatus; import java.util.List; import java.util.function.Supplier; @@ -34,8 +36,20 @@ public interface DisplayHelper { * Gets all registered bounds handlers * * @return the list of registered bounds handlers + * @deprecated see {@link #getAllOverlayDeciders()} */ - List<DisplayBoundsHandler<?>> getAllBoundsHandlers(); + @Deprecated + @ApiStatus.ScheduledForRemoval + default List<DisplayBoundsHandler<?>> getAllBoundsHandlers() { + return (List) CollectionUtils.castAndMap(getAllOverlayDeciders(), DisplayBoundsHandler.class); + } + + /** + * Gets all registered overlay deciders + * + * @return the list of registered overlay deciders + */ + List<OverlayDecider> getAllOverlayDeciders(); /** * Gets all responsible bounds handlers @@ -50,17 +64,31 @@ public interface DisplayHelper { * Registers a bounds handler * * @param handler the handler to register + * @deprecated see {@link #registerHandler(OverlayDecider)} + */ + @Deprecated + @ApiStatus.ScheduledForRemoval + default void registerBoundsHandler(DisplayBoundsHandler<?> handler) { + registerHandler(handler); + } + + /** + * Registers a bounds decider + * + * @param decider the decider to register */ - void registerBoundsHandler(DisplayBoundsHandler<?> handler); + void registerHandler(OverlayDecider decider); /** * Gets the base bounds handler api for exclusion zones * * @return the base bounds handler + * @see BaseBoundsHandler#getInstance() */ + @ApiStatus.Internal BaseBoundsHandler getBaseBoundsHandler(); - interface DisplayBoundsHandler<T> { + interface DisplayBoundsHandler<T> extends OverlayDecider { /** * Gets the base supported class for the bounds handler * @@ -68,6 +96,11 @@ public interface DisplayHelper { */ Class<?> getBaseSupportedClass(); + @Override + default boolean isHandingScreen(Class<?> screen) { + return getBaseSupportedClass().isAssignableFrom(screen); + } + /** * Gets the left bounds of the overlay * @@ -140,6 +173,7 @@ public interface DisplayHelper { * * @return the priority in float */ + @Override default float getPriority() { return 0f; } diff --git a/src/main/java/me/shedaniel/rei/api/EntryRegistry.java b/src/main/java/me/shedaniel/rei/api/EntryRegistry.java index 39af13fec..9da100bf7 100644 --- a/src/main/java/me/shedaniel/rei/api/EntryRegistry.java +++ b/src/main/java/me/shedaniel/rei/api/EntryRegistry.java @@ -28,6 +28,8 @@ public interface EntryRegistry { */ List<EntryStack> getStacksList(); + List<EntryStack> getPreFilteredList(); + List<ItemStack> appendStacksForItem(Item item); /** diff --git a/src/main/java/me/shedaniel/rei/api/EntryStack.java b/src/main/java/me/shedaniel/rei/api/EntryStack.java index 9d36a0550..713d74428 100644 --- a/src/main/java/me/shedaniel/rei/api/EntryStack.java +++ b/src/main/java/me/shedaniel/rei/api/EntryStack.java @@ -50,7 +50,7 @@ public interface EntryStack { } static EntryStack create(ItemConvertible item) { - return new ItemEntryStack(new ItemStack(item)); + return create(new ItemStack(item)); } @ApiStatus.Internal @@ -135,6 +135,27 @@ public interface EntryStack { return hashCode(); } + /** + * {@link #hashCode()} for {@link #equalsIgnoreAmount(EntryStack)} + */ + default int hashIgnoreAmount() { + return hashCode(); + } + + /** + * {@link #hashCode()} for {@link #equalsIgnoreTags(EntryStack)} + */ + default int hashIgnoreTags() { + return hashCode(); + } + + /** + * {@link #hashCode()} for {@link #equalsIgnoreTagsAndAmount(EntryStack)} + */ + default int hashIgnoreAmountAndTags() { + return hashCode(); + } + int getZ(); void setZ(int z); @@ -185,6 +206,7 @@ public interface EntryStack { public static final Supplier<Boolean> FALSE = () -> false; public static final Settings<Supplier<Boolean>> RENDER = new Settings<>(TRUE); public static final Settings<Supplier<Boolean>> CHECK_TAGS = new Settings<>(FALSE); + public static final Settings<Supplier<Boolean>> CHECK_AMOUNT = new Settings<>(FALSE); public static final Settings<Supplier<Boolean>> TOOLTIP_ENABLED = new Settings<>(TRUE); public static final Settings<Supplier<Boolean>> TOOLTIP_APPEND_MOD = new Settings<>(TRUE); public static final Settings<Supplier<Boolean>> RENDER_COUNTS = new Settings<>(TRUE); diff --git a/src/main/java/me/shedaniel/rei/api/OverlayDecider.java b/src/main/java/me/shedaniel/rei/api/OverlayDecider.java new file mode 100644 index 000000000..4f6120e2a --- /dev/null +++ b/src/main/java/me/shedaniel/rei/api/OverlayDecider.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2018, 2019, 2020 shedaniel + * Licensed under the MIT License (the "License"). + */ + +package me.shedaniel.rei.api; + +import net.minecraft.util.ActionResult; + +public interface OverlayDecider { + boolean isHandingScreen(Class<?> screen); + + default ActionResult shouldScreenBeOverlayed(Class<?> screen) { + return ActionResult.PASS; + } + + /** + * Gets the priority of the handler, the higher it is, the earlier it is called. + * + * @return the priority in float + */ + default float getPriority() { + return 0f; + } +} diff --git a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java index 4e8a07f21..d502100c1 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java @@ -75,11 +75,21 @@ public interface RecipeHelper { List<List<EntryStack>> getWorkingStations(Identifier category); /** - * Registers a recipe display + * Registers a recipe display. + * + * @param display |
