Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/11.x-1.19.4' into 12.x-1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
shedaniel committed Apr 25, 2024
2 parents 90fd49a + 81e9c38 commit 9cb2883
Show file tree
Hide file tree
Showing 14 changed files with 335 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ public static class Appearance {
public boolean scrollingEntryListWidget = false;
@Comment("Declares whether entry panel should be invisible when not searching")
public boolean hideEntryPanelIfIdle = false;
public boolean rainbow = false;

public static class Layout {
@Comment("Declares the position of the search field.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import me.shedaniel.rei.api.client.gui.widgets.Widgets;
import me.shedaniel.rei.api.client.util.MatrixUtils;
import me.shedaniel.rei.impl.client.gui.config.ConfigAccess;
import me.shedaniel.rei.impl.client.gui.config.options.AllREIConfigOptions;
import me.shedaniel.rei.impl.client.gui.config.options.CompositeOption;
import me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils;
import me.shedaniel.rei.impl.client.gui.text.TextTransformations;
Expand All @@ -48,6 +49,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import static me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils.literal;
import static me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils.translatable;
Expand All @@ -59,7 +61,8 @@ public static <T> WidgetWithBounds create(ConfigAccess access, CompositeOption<T
int[] height = {12};
Label fieldNameLabel;
widgets.add(fieldNameLabel = Widgets.createLabel(new Point(0, 0), TextTransformations.highlightText(option.getName().copy(), option.getOptionNameHighlight(), style -> style.withColor(0xFFC0C0C0)))
.leftAligned());
.leftAligned()
.rainbow(Objects.equals(option.getId(), AllREIConfigOptions.RAINBOW.getId())));
WidgetWithBounds optionValue = ConfigOptionValueWidget.create(access, option, width - 10 - fieldNameLabel.getBounds().width);
widgets.add(Widgets.withTranslate(optionValue, () -> new Matrix4f().translate(width - optionValue.getBounds().width - optionValue.getBounds().x, 0, 0)));
widgets.add(new WidgetWithBounds() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ static OptionCategory make(String key) {

OptionCategory APPEARANCE = make("appearance")
.add(APPEARANCE_INTERFACE)
.add(APPEARANCE_TOOLTIPS);
.add(APPEARANCE_TOOLTIPS)
.add(APPEARANCE_ADVANCED);
OptionCategory INPUT = make("input")
.add(INPUT_KEYBINDS)
/*.add(KEYBINDS_ADVANCED)*/;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ static <T> OptionGroup make(String id) {
OptionGroup APPEARANCE_TOOLTIPS = make("appearance.tooltips")
.add(APPEND_MOD_NAMES)
.add(APPEND_FAVORITES_HINT);
OptionGroup APPEARANCE_ADVANCED = make("appearance.advanced")
.add(RAINBOW);
OptionGroup INPUT_KEYBINDS = make("input.keybinds")
.add(RECIPE_KEYBIND)
.add(USAGE_KEYBIND)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ static <T> CompositeOption<T> make(String id, Function<ConfigObjectImpl, T> bind
CompositeOption<DisplayScreenType> RECIPE_LOOKUP_STYLE = make("appearance.recipe_lookup_style", i -> i.appearance.recipeScreenType, (i, v) -> i.appearance.recipeScreenType = v)
.options(DisplayScreenType.ORIGINAL, DisplayScreenType.COMPOSITE)
.defaultValue(() -> DisplayScreenType.ORIGINAL);
CompositeOption<Boolean> RAINBOW = make("appearance.rainbow", i -> i.appearance.rainbow, (i, v) -> i.appearance.rainbow = v)
.enabledDisabled();
CompositeOption<Boolean> APPEND_MOD_NAMES = make("appearance.append_mod_names", i -> i.advanced.tooltips.appendModNames, (i, v) -> i.advanced.tooltips.appendModNames = v)
.enabledDisabled();
CompositeOption<Boolean> APPEND_FAVORITES_HINT = make("appearance.append_favorites_hint", i -> i.advanced.tooltips.displayFavoritesTooltip, (i, v) -> i.advanced.tooltips.displayFavoritesTooltip = v)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ private TransferHandler _getTransferHandler() {
Map<CategoryIdentifier<?>, Boolean> filteringQuickCraftCategories = ConfigObject.getInstance().getFilteringQuickCraftCategories();
boolean shouldFilterDisplays = ConfigObject.getInstance().shouldFilterDisplays();

for (Display display : displaysHolder.getAllDisplaysByOutputs(getEntries())) {
for (Display display : displaysHolder.cache().getAllDisplaysByOutputs(getEntries())) {
CategoryIdentifier<?> categoryIdentifier = display.getCategoryIdentifier();
Optional<? extends CategoryRegistry.CategoryConfiguration<?>> configuration;
if ((configuration = categoryRegistry.tryGet(categoryIdentifier)).isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.util.CollectionUtils;
import me.shedaniel.rei.impl.client.ClientHelperImpl;
import me.shedaniel.rei.impl.client.config.ConfigManagerImpl;
import me.shedaniel.rei.impl.client.gui.InternalTextures;
import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl;
import me.shedaniel.rei.impl.client.gui.widget.BatchedEntryRendererManager;
Expand Down Expand Up @@ -242,7 +243,7 @@ public void init(ScreenOverlayImpl overlay) {
}).tooltip(Component.translatable("text.rei.go_back_first_page"), Component.literal(" "), Component.translatable("text.rei.shift_click_to", Component.translatable("text.rei.choose_page")).withStyle(ChatFormatting.GRAY)).focusable(false).onRender((matrices, label) -> {
label.setClickable(getTotalPages() > 1);
label.setMessage(Component.literal(String.format("%s/%s", getPage() + 1, Math.max(getTotalPages(), 1))));
}).rainbow(new Random().nextFloat() < 1.0E-4D || ClientHelperImpl.getInstance().isAprilFools.get()));
}).rainbow(new Random().nextFloat() < 1.0E-4D || ClientHelperImpl.getInstance().isAprilFools.get() || ConfigManagerImpl.getInstance().getConfig().appearance.rainbow));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* This file is licensed under the MIT License, part of Roughly Enough Items.
* Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 shedaniel
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package me.shedaniel.rei.impl.client.registry.display;

import com.google.common.collect.Iterables;
import me.shedaniel.rei.api.common.display.Display;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.util.CollectionUtils;
import me.shedaniel.rei.impl.client.view.ViewsImpl;

import java.util.Collection;
import java.util.List;
import java.util.Set;

public interface DisplayCache {
boolean doesCache();

boolean isCached(Display display);

void add(Display display);

boolean remove(Display display);

void endReload();

Set<Display> getDisplaysNotCached();

Set<Display> getDisplaysByInput(EntryStack<?> stack);

Set<Display> getDisplaysByOutput(EntryStack<?> stack);

default Iterable<Display> getAllDisplaysByInputs(List<EntryStack<?>> stacks) {
if (stacks.isEmpty()) return List.of();
Iterable<Display> inputCached = null;
if (doesCache()) {
for (EntryStack<?> stack : stacks) {
Set<Display> set = getDisplaysByInput(stack);
inputCached = inputCached == null ? set : Iterables.concat(inputCached, set);
}
if (stacks.size() > 1) inputCached = CollectionUtils.distinctReferenceOf(inputCached);
}
Collection<Display> notCached = this.getDisplaysNotCached();
if (notCached.isEmpty()) return inputCached == null ? List.of() : inputCached;
Iterable<Display> filteredNotCached = Iterables.filter(notCached, display ->
ViewsImpl.isUsagesFor(null, stacks, display));
if (inputCached == null) return filteredNotCached;
return Iterables.concat(inputCached, filteredNotCached);
}

default Iterable<Display> getAllDisplaysByOutputs(List<EntryStack<?>> stacks) {
if (stacks.isEmpty()) return List.of();
Iterable<Display> outputCached = null;
if (doesCache()) {
for (EntryStack<?> stack : stacks) {
Set<Display> set = getDisplaysByOutput(stack);
outputCached = outputCached == null ? set : Iterables.concat(outputCached, set);
}
if (stacks.size() > 1) outputCached = CollectionUtils.distinctReferenceOf(outputCached);
}
Collection<Display> notCached = this.getDisplaysNotCached();
if (notCached.isEmpty()) return outputCached == null ? List.of() : outputCached;
Iterable<Display> filteredNotCached = Iterables.filter(notCached, display ->
ViewsImpl.isRecipesFor(null, stacks, display));
if (outputCached == null) return filteredNotCached;
return Iterables.concat(outputCached, filteredNotCached);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/*
* This file is licensed under the MIT License, part of Roughly Enough Items.
* Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 shedaniel
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package me.shedaniel.rei.impl.client.registry.display;

import com.google.common.base.Stopwatch;
import com.google.common.collect.Multimaps;
import com.google.common.collect.SetMultimap;
import it.unimi.dsi.fastutil.Hash;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap;
import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet;
import me.shedaniel.rei.api.client.config.ConfigObject;
import me.shedaniel.rei.api.common.display.Display;
import me.shedaniel.rei.api.common.entry.EntryIngredient;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.util.EntryStacks;
import me.shedaniel.rei.impl.common.InternalLogger;

import java.util.Collections;
import java.util.Set;

public class DisplayCacheImpl implements DisplayCache {
private final boolean cache;
private Set<Display> displaysCached = new ReferenceOpenHashSet<>();
private Set<Display> displaysNotCached = Collections.synchronizedSet(new ReferenceOpenHashSet<>());
private SetMultimap<EntryStack<?>, Display> displaysByInput;
private SetMultimap<EntryStack<?>, Display> displaysByOutput;
private boolean preprocessed = false;

public DisplayCacheImpl(boolean init) {
this.cache = init && ConfigObject.getInstance().doesCacheDisplayLookup();
this.displaysByInput = createSetMultimap();
this.displaysByOutput = createSetMultimap();
}

@Override
public boolean doesCache() {
return this.cache;
}

@Override
public boolean isCached(Display display) {
return this.cache && this.displaysCached.contains(display);
}

@Override
public void add(Display display) {
if (this.cache) {
if (!preprocessed) {
this.displaysNotCached.add(display);
} else {
this.process(display);
this.displaysCached.add(display);
}
} else {
this.displaysNotCached.add(display);
}
}

@Override
public boolean remove(Display display) {
if (this.cache) {
if (!preprocessed) {
return this.displaysNotCached.remove(display);
} else {
boolean removed = this.displaysCached.remove(display);
if (removed) {
for (EntryIngredient input : display.getInputEntries()) {
for (EntryStack<?> stack : input) {
this.displaysByInput.remove(stack, display);
}
}
for (EntryIngredient output : display.getOutputEntries()) {
for (EntryStack<?> stack : output) {
this.displaysByOutput.remove(stack, display);
}
}
}
return removed;
}
} else {
return this.displaysNotCached.remove(display);
}
}

@Override
public void endReload() {
if (this.cache) {
if (preprocessed) {
InternalLogger.getInstance().error("DisplayCache#endReload called after preprocessed!");
}

InternalLogger.getInstance().debug("Processing %d displays for optimal lookup performance...", this.displaysNotCached.size());
Stopwatch stopwatch = Stopwatch.createStarted();
this.displaysCached = new ReferenceOpenHashSet<>(this.displaysNotCached.size());
this.displaysByInput = createSetMultimap();
this.displaysByOutput = createSetMultimap();
for (Display display : this.displaysNotCached) {
this.process(display);
}
this.displaysCached.addAll(this.displaysNotCached);
this.displaysNotCached = Set.of();
this.preprocessed = true;
InternalLogger.getInstance().debug("Processed displays for optimal lookup performance in %s.", stopwatch.stop());
}
}

@Override
public Set<Display> getDisplaysNotCached() {
return this.displaysNotCached;
}

@Override
public Set<Display> getDisplaysByInput(EntryStack<?> stack) {
return this.displaysByInput.get(stack);
}

@Override
public Set<Display> getDisplaysByOutput(EntryStack<?> stack) {
return this.displaysByOutput.get(stack);
}

private void process(Display display) {
for (EntryIngredient input : display.getInputEntries()) {
for (EntryStack<?> stack : input) {
this.displaysByInput.put(stack, display);
}
}
for (EntryIngredient output : display.getOutputEntries()) {
for (EntryStack<?> stack : output) {
this.displaysByOutput.put(stack, display);
}
}
}

private static SetMultimap<EntryStack<?>, Display> createSetMultimap() {
return Multimaps.newSetMultimap(
new Object2ObjectOpenCustomHashMap<>(5000, new Hash.Strategy<>() {
@Override
public int hashCode(EntryStack<?> stack) {
return Long.hashCode(EntryStacks.hashFuzzy(stack));
}

@Override
public boolean equals(EntryStack<?> o1, EntryStack<?> o2) {
return EntryStacks.equalsFuzzy(o1, o2);
}
}),
ReferenceOpenHashSet::new
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void add(Display display, @Nullable Object origin) {

@Override
public Map<CategoryIdentifier<?>, List<Display>> getAll() {
return this.displaysHolder.get();
return this.displaysHolder.getUnmodifiable();
}

@Override
Expand Down Expand Up @@ -201,8 +201,16 @@ public void endReload() {
}
}

List<Display> failedDisplays = new ArrayList<>();
for (List<Display> displays : getAll().values()) {
displays.removeIf(display -> !DisplayValidator.validate(display));
for (Display display : displays) {
if (!DisplayValidator.validate(display)) {
failedDisplays.add(display);
}
}
}
for (Display display : failedDisplays) {
this.displaysHolder.remove(display);
}

this.displaysHolder.endReload();
Expand Down
Loading

0 comments on commit 9cb2883

Please sign in to comment.