diff options
| author | shedaniel <daniel@shedaniel.me> | 2021-11-14 02:36:33 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2021-11-14 02:36:33 +0800 |
| commit | 760f20e8bdf63ee4af47bb408cdac18e6dd7a591 (patch) | |
| tree | c82c23af4b13334723345612dc65f225f81cf5c3 /runtime | |
| parent | 5b99b04e23728c32387183df3719b1f696e994fe (diff) | |
| parent | 57f59e7da8ae83f1ad952e410601409eecf2e1c4 (diff) | |
| download | RoughlyEnoughItems-760f20e8bdf63ee4af47bb408cdac18e6dd7a591.tar.gz RoughlyEnoughItems-760f20e8bdf63ee4af47bb408cdac18e6dd7a591.tar.bz2 RoughlyEnoughItems-760f20e8bdf63ee4af47bb408cdac18e6dd7a591.zip | |
Merge remote-tracking branch 'origin/6.x-1.17' into 7.x-1.18
# Conflicts:
# gradle.properties
Diffstat (limited to 'runtime')
46 files changed, 1578 insertions, 796 deletions
diff --git a/runtime/build.gradle b/runtime/build.gradle index b77410d22..25b8d9fed 100644 --- a/runtime/build.gradle +++ b/runtime/build.gradle @@ -16,6 +16,7 @@ dependencies { modCompileOnly("net.fabricmc:fabric-loader:${project.fabricloader_version}") modApi("me.shedaniel.cloth:cloth-config:${cloth_config_version}") modApi("dev.architectury:architectury:${architectury_version}") + compileClasspath(annotationProcessor("org.projectlombok:lombok:1.18.22")) compileClasspath(project(path: ":api", configuration: "namedElements")) } diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java index 094bbe4ea..2069d8139 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java @@ -283,6 +283,7 @@ public class RoughlyEnoughItemsCoreClient { reloadPlugins(endReload, Platform.isFabric() ? ReloadStage.END : null); }); ClientGuiEvent.INIT_POST.register((screen, access) -> { + REIRuntime.getInstance().getOverlay(false, true); REIRuntimeImpl.getInstance().setPreviousScreen(screen); if (ConfigObject.getInstance().doesDisableRecipeBook() && screen instanceof AbstractContainerScreen) { access.getRenderables().removeIf(widget -> widget instanceof ImageButton button && button.resourceLocation.equals(recipeButtonTex)); @@ -380,7 +381,7 @@ public class RoughlyEnoughItemsCoreClient { public static void reloadPlugins(MutableLong lastReload, @Nullable ReloadStage start) { if (lastReload != null) { if (lastReload.getValue() > 0 && System.currentTimeMillis() - lastReload.getValue() <= 5000) { - RoughlyEnoughItemsCore.LOGGER.warn("Suppressing Reload Plugins!"); + RoughlyEnoughItemsCore.LOGGER.warn("Suppressing Reload Plugins of stage " + start); return; } lastReload.setValue(System.currentTimeMillis()); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java index e80e5f572..d5d89a653 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java @@ -33,6 +33,7 @@ import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.REIRuntime; import me.shedaniel.rei.api.client.config.ConfigManager; import me.shedaniel.rei.api.client.config.ConfigObject; +import me.shedaniel.rei.api.client.gui.config.DisplayPanelLocation; import me.shedaniel.rei.api.client.gui.config.SearchFieldLocation; import me.shedaniel.rei.api.client.gui.screen.DisplayScreen; import me.shedaniel.rei.api.client.gui.widgets.TextField; @@ -55,6 +56,8 @@ import org.jetbrains.annotations.Nullable; import java.util.*; +import static me.shedaniel.rei.impl.client.gui.widget.EntryListWidget.entrySize; + @ApiStatus.Internal @Environment(EnvType.CLIENT) public class REIRuntimeImpl implements REIRuntime { @@ -137,8 +140,8 @@ public class REIRuntimeImpl implements REIRuntime { } @Override - public Optional<ScreenOverlay> getOverlay(boolean reset) { - if (overlay == null || reset) { + public Optional<ScreenOverlay> getOverlay(boolean reset, boolean init) { + if ((overlay == null && init) || reset) { overlay = new ScreenOverlayImpl(); overlay.init(); getSearchField().setFocused(false); @@ -194,8 +197,7 @@ public class REIRuntimeImpl implements REIRuntime { } @Override - public Rectangle calculateEntryListArea() { - Rectangle bounds = ScreenRegistry.getInstance().getOverlayBounds(ConfigObject.getInstance().getDisplayPanelLocation(), Minecraft.getInstance().screen); + public Rectangle calculateEntryListArea(Rectangle bounds) { SearchFieldLocation searchFieldLocation = getContextualSearchFieldLocation(); int yOffset = 2; @@ -212,7 +214,20 @@ public class REIRuntimeImpl implements REIRuntime { int yOffset = 8; if (!ConfigObject.getInstance().isLowerConfigButton()) yOffset += 25; - return new Rectangle(bounds.x, bounds.y + yOffset, bounds.width, bounds.height - 3 - yOffset); + bounds = new Rectangle(bounds.x, bounds.y + yOffset, bounds.width, bounds.height - 3 - yOffset); + + int widthReduction = (int) Math.round(bounds.width * (1 - ConfigObject.getInstance().getFavoritesHorizontalEntriesBoundariesPercentage())); + if (ConfigObject.getInstance().getDisplayPanelLocation() == DisplayPanelLocation.LEFT) + bounds.x += widthReduction; + bounds.width -= widthReduction; + int maxWidth = (int) Math.ceil(entrySize() * ConfigObject.getInstance().getFavoritesHorizontalEntriesBoundariesColumns() + entrySize() * 0.75) + 8; + if (bounds.width > maxWidth) { + if (ConfigObject.getInstance().getDisplayPanelLocation() == DisplayPanelLocation.LEFT) + bounds.x += bounds.width - maxWidth; + bounds.width = maxWidth; + } + + return bounds; } @Override @@ -240,7 +255,7 @@ public class REIRuntimeImpl implements REIRuntime { return EventResult.pass(); }); ClientTickEvent.CLIENT_POST.register(minecraft -> { - if (isOverlayVisible()) { + if (isOverlayVisible() && REIRuntime.getInstance().getOverlay().isPresent()) { ScreenOverlayImpl.getInstance().tick(); } }); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java index e6eefa6b6..231709cf0 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java @@ -49,6 +49,7 @@ import me.shedaniel.clothconfig2.gui.entries.TextListEntry; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.client.REIRuntime; import me.shedaniel.rei.api.client.config.ConfigManager; +import me.shedaniel.rei.api.client.config.entry.EntryStackProvider; import me.shedaniel.rei.api.client.favorites.FavoriteEntry; import me.shedaniel.rei.api.client.gui.config.DisplayScreenType; import me.shedaniel.rei.api.client.gui.config.SyntaxHighlightingMode; @@ -82,6 +83,7 @@ import org.apache.commons.lang3.mutable.MutableLong; import org.jetbrains.annotations.ApiStatus; import java.util.*; +import java.util.function.Consumer; import static me.shedaniel.autoconfig.util.Utils.getUnsafely; import static me.shedaniel.autoconfig.util.Utils.setUnsafely; @@ -116,11 +118,17 @@ public class ConfigManagerImpl implements ConfigManager { guiRegistry.registerAnnotationProvider((i13n, field, config, defaults, guiProvider) -> Collections.singletonList(new SearchFilterSyntaxHighlightingEntry(new TranslatableComponent(i13n), getUnsafely(field, config, SyntaxHighlightingMode.COLORFUL), getUnsafely(field, defaults), type -> setUnsafely(field, config, type))) , (field) -> field.getType() == SyntaxHighlightingMode.class, ConfigObjectImpl.UseSpecialSearchFilterSyntaxHighlightingScreen.class); - guiRegistry.registerAnnotationProvider((i13n, field, config, defaults, guiProvider) -> - REIRuntime.getInstance().getPreviousContainerScreen() == null || Minecraft.getInstance().getConnection() == null || Minecraft.getInstance().getConnection().getRecipeManager() == null ? - Collections.singletonList(new NoFilteringEntry(220, getUnsafely(field, config, new ArrayList<>()), getUnsafely(field, defaults), list -> setUnsafely(field, config, list))) - : - Collections.singletonList(new FilteringEntry(220, getUnsafely(field, config, new ArrayList<>()), ((ConfigObjectImpl.Advanced.Filtering) config).filteringRules, getUnsafely(field, defaults), list -> setUnsafely(field, config, list), list -> ((ConfigObjectImpl.Advanced.Filtering) config).filteringRules = Lists.newArrayList(list))) + guiRegistry.registerAnnotationProvider((i13n, field, config, defaults, guiProvider) -> { + List<EntryStack<?>> value = CollectionUtils.map(Utils.<List<EntryStackProvider<?>>>getUnsafely(field, config, new ArrayList<>()), EntryStackProvider::provide); + List<EntryStack<?>> defaultValue = CollectionUtils.map(Utils.<List<EntryStackProvider<?>>>getUnsafely(field, defaults), EntryStackProvider::provide); + Consumer<List<EntryStack<?>>> saveConsumer = (newValue) -> { + setUnsafely(field, config, CollectionUtils.map(newValue, EntryStackProvider::ofStack)); + }; + return REIRuntime.getInstance().getPreviousContainerScreen() == null || Minecraft.getInstance().getConnection() == null || Minecraft.getInstance().getConnection().getRecipeManager() == null ? + Collections.singletonList(new NoFilteringEntry(220, value, defaultValue, saveConsumer)) + : + Collections.singletonList(new FilteringEntry(220, value, ((ConfigObjectImpl.Advanced.Filtering) config).filteringRules, defaultValue, saveConsumer, list -> ((ConfigObjectImpl.Advanced.Filtering) config).filteringRules = Lists.newArrayList(list))); + } , (field) -> field.getType() == List.class, ConfigObjectImpl.UseFilteringScreen.class); saveConfig(); RoughlyEnoughItemsCore.LOGGER.info("Config loaded."); @@ -165,8 +173,8 @@ public class ConfigManagerImpl implements ConfigManager { } }); - // EntryStack - builder.registerSerializer(EntryStack.class, (stack, marshaller) -> { + // EntryStackProvider + builder.registerSerializer(EntryStackProvider.class, (stack, marshaller) -> { try { return marshaller.serialize(stack.save()); } catch (Exception e) { @@ -174,20 +182,15 @@ public class ConfigManagerImpl implements ConfigManager { return JsonNull.INSTANCE; } }); - builder.registerDeserializer(Tag.class, EntryStack.class, (value, marshaller) -> { - try { - return EntryStack.read((CompoundTag) value); - } catch (Exception e) { - e.printStackTrace(); - return EntryStack.empty(); - } + builder.registerDeserializer(Tag.class, EntryStackProvider.class, (value, marshaller) -> { + return EntryStackProvider.defer((CompoundTag) value); }); - builder.registerDeserializer(String.class, EntryStack.class, (value, marshaller) -> { + builder.registerDeserializer(String.class, EntryStackProvider.class, (value, marshaller) -> { try { - return EntryStack.read(TagParser.parseTag(value)); - } catch (Exception e) { + return EntryStackProvider.defer(TagParser.parseTag(value)); + } catch (CommandSyntaxException e) { e.printStackTrace(); - return EntryStack.empty(); + return EntryStackProvider.ofStack(EntryStack.empty()); } }); @@ -255,12 +258,6 @@ public class ConfigManagerImpl implements ConfigManager { if (getConfig().getFavoriteEntries() != null) { getConfig().getFavoriteEntries().removeIf(Objects::isNull); } - if (getConfig().getFilteredStacks() != null) { - getConfig().getFilteredStacks().removeIf(EntryStack::isEmpty); - List<EntryStack<?>> normalizedFilteredStacks = CollectionUtils.map(getConfig().getFilteredStacks(), EntryStack::normalize); - getConfig().getFilteredStacks().clear(); - getConfig().getFilteredStacks().addAll(normalizedFilteredStacks); - } if (getConfig().getFilteringRules().stream().noneMatch(filteringRule -> filteringRule instanceof ManualFilteringRule)) { getConfig().getFilteringRules().add(new ManualFilteringRule()); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java index 3895bc4fc..73521ae30 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java @@ -32,9 +32,11 @@ import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.Comment; import me.shedaniel.clothconfig2.api.Modifier; import me.shedaniel.clothconfig2.api.ModifierKeyCode; import me.shedaniel.rei.api.client.config.ConfigObject; +import me.shedaniel.rei.api.client.config.entry.EntryStackProvider; import me.shedaniel.rei.api.client.favorites.FavoriteEntry; import me.shedaniel.rei.api.client.gui.config.*; import me.shedaniel.rei.api.common.entry.EntryStack; +import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.impl.client.entry.filtering.FilteringRule; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -46,6 +48,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.util.ArrayList; +import java.util.Collections; import java.util.List; @ApiStatus.Internal @@ -167,6 +170,11 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { } @Override + public int getMaxRecipesPageHeight() { + return advanced.layout.maxRecipesPageHeight; + } + + @Override public boolean doesDisableRecipeBook() { return functionality.disableRecipeBook; } @@ -303,6 +311,11 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { @Override public List<EntryStack<?>> getFilteredStacks() { + return Collections.unmodifiableList(CollectionUtils.map(advanced.filtering.filteredStacks, EntryStackProvider::provide)); + } + + @Override + public List<EntryStackProvider<?>> getFilteredStackProviders() { return advanced.filtering.filteredStacks; } @@ -341,16 +354,39 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { @ApiStatus.Experimental @Override - public double getHorizontalEntriesBoundaries() { + public double getHorizontalEntriesBoundariesPercentage() { return Mth.clamp(appearance.horizontalEntriesBoundaries, 0.1, 1); } @ApiStatus.Experimental @Override - public double getVerticalEntriesBoundaries() { + public double getVerticalEntriesBoundariesPercentage() { return Mth.clamp(appearance.verticalEntriesBoundaries, 0.1, 1); } + @ApiStatus.Experimental + @Override + public double getHorizontalEntriesBoundariesColumns() { + return Mth.clamp(appearance.horizontalEntriesBoundariesColumns, 1, 1000); + } + + @ApiStatus.Experimental + @Override + public double getVerticalEntriesBoundariesRows() { + return Mth.clamp(appearance.verticalEntriesBoundariesRows, 1, 1000); + } + + @ApiStatus.Experimental + @Override + public double getFavoritesHorizontalEntriesBoundariesPercentage() { + return Mth.clamp(appearance.favoritesHorizontalEntriesBoundaries, 0.1, 1); + } + + @Override + public double getFavoritesHorizontalEntriesBoundariesColumns() { + return Mth.clamp(appearance.favoritesHorizontalEntriesBoundariesColumns, 1, 1000); + } + @Override public SyntaxHighlightingMode getSyntaxHighlightingMode() { return appearance.syntaxHighlightingMode; @@ -461,6 +497,10 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { @UsePercentage(min = 0.1, max = 1.0, prefix = "Limit: ") private double horizontalEntriesBoundaries = 1.0; @UsePercentage(min = 0.1, max = 1.0, prefix = "Limit: ") private double verticalEntriesBoundaries = 1.0; + private int horizontalEntriesBoundariesColumns = 50; + private int verticalEntriesBoundariesRows = 1000; + @UsePercentage(min = 0.1, max = 1.0, prefix = "Limit: ") private double favoritesHorizontalEntriesBoundaries = 1.0; + private int favoritesHorizontalEntriesBoundariesColumns = 50; @UseSpecialSearchFilterSyntaxHighlightingScreen private SyntaxHighlightingMode syntaxHighlightingMode = SyntaxHighlightingMode.COLORFUL; } @@ -498,7 +538,9 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) private EntryPanelOrderingConfig entryPanelOrdering = EntryPanelOrderingConfig.REGISTRY_ASCENDING; @Comment("Declares the maximum amount of recipes displayed in a page if possible.") @ConfigEntry.BoundedDiscrete(min = 2, max = 99) - private int maxRecipesPerPage = 3; + private int maxRecipesPerPage = 8; + @Comment("Declares the maximum amount of recipes displayed in a page if possible.") @ConfigEntry.BoundedDiscrete(min = 100, max = 1000) + private int maxRecipesPageHeight = 300; @Comment("Declares whether entry rendering time should be debugged.") private boolean debugRenderTimeRequired = false; @Comment("Merges displays with equal contents under 1 display.") private boolean mergeDisplayUnderOne = true; } @@ -541,7 +583,7 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { } public static class Filtering { - @UseFilteringScreen private List<EntryStack<?>> filteredStacks = new ArrayList<>(); + @UseFilteringScreen private List<EntryStackProvider<?>> filteredStacks = new ArrayList<>(); @ConfigEntry.Gui.Excluded public List<FilteringRule<?>> filteringRules = new ArrayList<>(); } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/ManualFilteringRule.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/ManualFilteringRule.java index 480235778..c8fb61998 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/ManualFilteringRule.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/ManualFilteringRule.java @@ -26,6 +26,7 @@ package me.shedaniel.rei.impl.client.entry.filtering.rules; import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import it.unimi.dsi.fastutil.longs.LongSet; import me.shedaniel.rei.api.client.config.ConfigObject; +import me.shedaniel.rei.api.client.config.entry.EntryStackProvider; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.api.common.util.EntryStacks; @@ -59,7 +60,7 @@ public class ManualFilteringRule extends AbstractFilteringRule<ManualFilteringRu } private void processList(Collection<EntryStack<?>> stacks, FilteringResult result) { - LongSet filteredStacks = CollectionUtils.mapParallel(ConfigObject.getInstance().getFilteredStacks(), EntryStacks::hashExact, LongOpenHashSet::new); + LongSet filteredStacks = CollectionUtils.filterAndMapParallel(ConfigObject.getInstance().getFilteredStackProviders(), EntryStackProvider::isValid, provider -> EntryStacks.hashExact(provider.provide()), LongOpenHashSet::new); result.hide(stacks.parallelStream().filter(stack -> filteredStacks.contains(EntryStacks.hashExact(stack))).collect(Collectors.toList())); } |
