Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/9.x-1.19' into 11.x-1.19.4
Browse files Browse the repository at this point in the history
# Conflicts:
#	runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/CraftableFilterButtonWidget.java
#	runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListImpl.java
  • Loading branch information
shedaniel committed Oct 23, 2023
2 parents b1e8b40 + 032a0ff commit 11278f4
Show file tree
Hide file tree
Showing 19 changed files with 184 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public DisplayMerger<DefaultCraftingDisplay<?>> getDisplayMerger() {
@Override
public boolean canMerge(DefaultCraftingDisplay<?> first, DefaultCraftingDisplay<?> second) {
if (!first.getCategoryIdentifier().equals(second.getCategoryIdentifier())) return false;
if (!equals(first.getOrganisedInputEntries(3, 3), second.getInputEntries())) return false;
if (!equals(first.getOrganisedInputEntries(3, 3), second.getOrganisedInputEntries(3, 3))) return false;
if (!equals(first.getOutputEntries(), second.getOutputEntries())) return false;
if (first.isShapeless() != second.isShapeless()) return false;
if (first.getWidth() != second.getWidth()) return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ public static void reloadPlugins(MutableLong lastReload, @Nullable ReloadStage s
}
lastReload.setValue(System.currentTimeMillis());
}
InternalLogger.getInstance().debug("Starting Reload Plugins of stage " + start, new Throwable());
if (ConfigObject.getInstance().doesRegisterRecipesInAnotherThread()) {
Future<?>[] futures = new Future<?>[1];
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> RoughlyEnoughItemsCore._reloadPlugins(start), RELOAD_PLUGINS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
scrolling.renderScrollBar(0, 1.0F, REIRuntime.getInstance().isDarkThemeEnabled() ? 0.8F : 1F);
matrices.pushPose();
matrices.translate(0, 0, 300);
this.searchField.laterRender(matrices, mouseX, mouseY, delta);
this.searchField.render(matrices, mouseX, mouseY, delta);
this.selectAllButton.render(matrices, mouseX, mouseY, delta);
this.selectNoneButton.render(matrices, mouseX, mouseY, delta);
this.hideButton.render(matrices, mouseX, mouseY, delta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class ReloadPluginsEntry extends AbstractConfigListEntry<Unit> {
public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
if (PluginManager.areAnyReloading()) {
Screen screen = Minecraft.getInstance().screen;
Minecraft.getInstance().setScreen(new ConfigReloadingScreen(Component.translatable("text.rei.config.is.reloading"), PluginManager::areAnyReloading, () -> Minecraft.getInstance().setScreen(screen)));
Minecraft.getInstance().setScreen(new ConfigReloadingScreen(Component.translatable("text.rei.config.is.reloading"), PluginManager::areAnyReloading, () -> Minecraft.getInstance().setScreen(screen), null));
} else {
super.render(matrices, mouseX, mouseY, delta);
}
Expand Down Expand Up @@ -87,7 +87,7 @@ public Optional<Unit> getDefaultValue() {

@Override
public void save() {

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.Util;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
Expand All @@ -39,12 +41,14 @@ public class ConfigReloadingScreen extends Screen {
private final BooleanSupplier predicate;
private Supplier<@Nullable Component> subtitle = () -> null;
private final Runnable parent;
private final Runnable cancel;

public ConfigReloadingScreen(Component title, BooleanSupplier predicate, Runnable parent) {
public ConfigReloadingScreen(Component title, BooleanSupplier predicate, Runnable parent, Runnable cancel) {
super(Component.empty());
this.title = title;
this.predicate = predicate;
this.parent = parent;
this.cancel = cancel;
}

public void setSubtitle(Supplier<@Nullable Component> subtitle) {
Expand All @@ -56,6 +60,15 @@ public boolean shouldCloseOnEsc() {
return false;
}

@Override
public void init() {
super.init();
if (cancel == null) return;
this.addRenderableWidget(Button.builder(CommonComponents.GUI_CANCEL, button -> {
cancel.run();
}).bounds(this.width / 2 - 100, this.height / 4 + 120 + 12, 200, 20).build());
}

@Override
public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
this.renderDirtBackground(matrices);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

package me.shedaniel.rei.impl.client.gui.widget;

import dev.architectury.platform.Platform;
import dev.architectury.utils.value.BooleanValue;
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
Expand Down Expand Up @@ -148,15 +149,22 @@ public static List<FavoriteMenuEntry> createInputMethodEntries(MenuAccess access
ConfigReloadingScreen reloadingScreen = new ConfigReloadingScreen(Component.translatable("text.rei.input.methods.initializing"),
() -> !future.isDone(), () -> {
Minecraft.getInstance().setScreen(screen);
}, () -> {
Minecraft.getInstance().setScreen(screen);
InternalLogger.getInstance().error("Failed to prepare input method: cancelled");
ConfigManagerImpl.getInstance().getConfig().setInputMethodId(new ResourceLocation("rei:default"));
future.cancel(Platform.isFabric());
service.shutdown();
});
reloadingScreen.setSubtitle(() -> Component.translatable("text.rei.input.methods.reload.progress", String.format("%.2f", progress[0] * 100)));
Minecraft.getInstance().setScreen(reloadingScreen);
access.close();
future.whenComplete((unused, throwable) -> {
service.shutdown();
if (throwable != null) return;
ScreenOverlayImpl.getInstance().getHintsContainer().addHint(12, () -> new Point(getCraftableFilterBounds().getCenterX(), getCraftableFilterBounds().getCenterY()),
"text.rei.hint.input.methods", List.of(Component.translatable("text.rei.hint.input.methods")));
});
ScreenOverlayImpl.getInstance().getHintsContainer().addHint(12, () -> new Point(getCraftableFilterBounds().getCenterX(), getCraftableFilterBounds().getCenterY()),
"text.rei.hint.input.methods", List.of(Component.translatable("text.rei.hint.input.methods")));
})
.withActive(() -> !Objects.equals(config.getInputMethodId(), pair.getKey()))
.withTooltip(() -> Tooltip.create(Widget.mouse(), pair.getValue().getDescription()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,58 @@
import me.shedaniel.rei.api.client.registry.screen.OverlayRendererProvider;
import me.shedaniel.rei.impl.common.InternalLogger;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;

import java.util.ArrayList;
import java.util.List;
import org.jetbrains.annotations.Nullable;

import static me.shedaniel.rei.RoughlyEnoughItemsCoreClient.resetFocused;
import static me.shedaniel.rei.RoughlyEnoughItemsCoreClient.shouldReturn;

public enum DefaultScreenOverlayRenderer implements OverlayRendererProvider {
INSTANCE;

private final List<Runnable> onRemoved = new ArrayList<>();
@Nullable
private ClientGuiEvent.ScreenRenderPre renderPre;
@Nullable
private ClientGuiEvent.ContainerScreenRenderBackground renderContainerBg;
@Nullable
private ClientGuiEvent.ContainerScreenRenderForeground renderContainerFg;
@Nullable
private ClientGuiEvent.ScreenRenderPost renderPost;

{
ClientGuiEvent.RENDER_PRE.register((screen, graphics, mouseX, mouseY, delta) -> {
if (renderPre != null) {
return renderPre.render(screen, graphics, mouseX, mouseY, delta);
} else {
return EventResult.pass();
}
});
ClientGuiEvent.RENDER_CONTAINER_BACKGROUND.register((screen, graphics, mouseX, mouseY, delta) -> {
if (renderContainerBg != null) {
renderContainerBg.render(screen, graphics, mouseX, mouseY, delta);
}
});
ClientGuiEvent.RENDER_CONTAINER_FOREGROUND.register((screen, graphics, mouseX, mouseY, delta) -> {
if (renderContainerFg != null) {
renderContainerFg.render(screen, graphics, mouseX, mouseY, delta);
}
});
ClientGuiEvent.RENDER_POST.register((screen, graphics, mouseX, mouseY, delta) -> {
if (renderPost != null) {
renderPost.render(screen, graphics, mouseX, mouseY, delta);
}
});
}

@Override
public void onApplied(Sink sink) {
int[] rendered = {0};
ClientGuiEvent.ScreenRenderPre renderPre;
ClientGuiEvent.ContainerScreenRenderBackground renderContainerBg;
ClientGuiEvent.ContainerScreenRenderForeground renderContainerFg;
ClientGuiEvent.ScreenRenderPost renderPost;
ClientGuiEvent.RENDER_PRE.register(renderPre = (screen, matrices, mouseX, mouseY, delta) -> {
this.renderPre = (screen, matrices, mouseX, mouseY, delta) -> {
if (shouldReturn(screen))
return EventResult.pass();
rendered[0] = 0;
return EventResult.pass();
});
ClientGuiEvent.RENDER_CONTAINER_BACKGROUND.register(renderContainerBg = (screen, matrices, mouseX, mouseY, delta) -> {
};
this.renderContainerBg = (screen, matrices, mouseX, mouseY, delta) -> {
if (shouldReturn(screen))
return;
rendered[0] = 1;
Expand All @@ -65,8 +91,8 @@ public void onApplied(Sink sink) {
sink.render(matrices, mouseX, mouseY, delta);
}
resetFocused(screen);
});
ClientGuiEvent.RENDER_CONTAINER_FOREGROUND.register(renderContainerFg = (screen, matrices, mouseX, mouseY, delta) -> {
};
this.renderContainerFg = (screen, matrices, mouseX, mouseY, delta) -> {
if (shouldReturn(screen))
return;
rendered[0] = 2;
Expand All @@ -79,8 +105,8 @@ public void onApplied(Sink sink) {
poseStack.popPose();
RenderSystem.applyModelViewMatrix();
resetFocused(screen);
});
ClientGuiEvent.RENDER_POST.register(renderPost = (screen, matrices, mouseX, mouseY, delta) -> {
};
this.renderPost = (screen, matrices, mouseX, mouseY, delta) -> {
if (shouldReturn(screen) || rendered[0] == 2)
return;
if (screen instanceof AbstractContainerScreen) {
Expand All @@ -95,18 +121,14 @@ public void onApplied(Sink sink) {
sink.lateRender(matrices, mouseX, mouseY, delta);
}
resetFocused(screen);
});
this.onRemoved.add(() -> {
ClientGuiEvent.RENDER_PRE.unregister(renderPre);
ClientGuiEvent.RENDER_CONTAINER_BACKGROUND.unregister(renderContainerBg);
ClientGuiEvent.RENDER_CONTAINER_FOREGROUND.unregister(renderContainerFg);
ClientGuiEvent.RENDER_POST.unregister(renderPost);
});
};
}

@Override
public void onRemoved() {
this.onRemoved.forEach(Runnable::run);
this.onRemoved.clear();
this.renderPre = null;
this.renderContainerBg = null;
this.renderContainerFg = null;
this.renderPost = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@

public class AsyncSearchManager {
private static final ExecutorService EXECUTOR_SERVICE = new ThreadCreator("REI-AsyncSearchManager").asService(Math.min(3, Runtime.getRuntime().availableProcessors()));
private final Supplier<List<HashedEntryStackWrapper>> stacksProvider;
private final Supplier<List<? extends HashedEntryStackWrapper>> stacksProvider;
private final Supplier<Predicate<HashedEntryStackWrapper>> additionalPredicateSupplier;
private final UnaryOperator<HashedEntryStackWrapper> transformer;
private volatile Map.Entry<List<HashedEntryStackWrapper>, SearchFilter> last;
public volatile ExecutorTuple executor;
public volatile SearchFilter filter;

public AsyncSearchManager(Supplier<List<HashedEntryStackWrapper>> stacksProvider, Supplier<Predicate<HashedEntryStackWrapper>> additionalPredicateSupplier, UnaryOperator<HashedEntryStackWrapper> transformer) {
public AsyncSearchManager(Supplier<List<? extends HashedEntryStackWrapper>> stacksProvider, Supplier<Predicate<HashedEntryStackWrapper>> additionalPredicateSupplier, UnaryOperator<HashedEntryStackWrapper> transformer) {
this.stacksProvider = stacksProvider;
this.additionalPredicateSupplier = additionalPredicateSupplier;
this.transformer = transformer;
Expand Down Expand Up @@ -134,7 +134,7 @@ public CompletableFuture<Map.Entry<List<HashedEntryStackWrapper>, SearchFilter>>
}

public static CompletableFuture<Map.Entry<List<HashedEntryStackWrapper>, SearchFilter>> get(SearchFilter filter, Predicate<HashedEntryStackWrapper> additionalPredicate,
UnaryOperator<HashedEntryStackWrapper> transformer, List<HashedEntryStackWrapper> stacks, Map.Entry<List<HashedEntryStackWrapper>, SearchFilter> last,
UnaryOperator<HashedEntryStackWrapper> transformer, List<? extends HashedEntryStackWrapper> stacks, Map.Entry<List<HashedEntryStackWrapper>, SearchFilter> last,
AsyncSearchManager manager, Executor executor, Steps steps) {
int searchPartitionSize = ConfigObject.getInstance().getAsyncSearchPartitionSize();
boolean shouldAsync = ConfigObject.getInstance().shouldAsyncSearch() && stacks.size() > searchPartitionSize * 4;
Expand All @@ -144,7 +144,7 @@ public static CompletableFuture<Map.Entry<List<HashedEntryStackWrapper>, SearchF
if (shouldAsync) {
List<CompletableFuture<List<HashedEntryStackWrapper>>> futures = Lists.newArrayList();
int partitions = 0;
for (Iterable<HashedEntryStackWrapper> partitionStacks : CollectionUtils.partition(stacks, searchPartitionSize * 4)) {
for (Iterable<? extends HashedEntryStackWrapper> partitionStacks : CollectionUtils.partition(stacks, searchPartitionSize * 4)) {
final int finalPartitions = partitions;
futures.add(CompletableFuture.supplyAsync(() -> {
List<HashedEntryStackWrapper> filtered = Lists.newArrayList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
package me.shedaniel.rei.impl.client.search.argument;

import com.google.common.base.MoreObjects;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import it.unimi.dsi.fastutil.ints.IntList;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
Expand All @@ -33,12 +32,14 @@
import me.shedaniel.rei.api.client.search.method.CharacterUnpackingInputMethod;
import me.shedaniel.rei.api.client.search.method.InputMethod;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.util.CollectionUtils;
import me.shedaniel.rei.impl.client.search.IntRange;
import me.shedaniel.rei.impl.client.search.argument.type.ArgumentType;
import me.shedaniel.rei.impl.client.search.argument.type.ArgumentTypesRegistry;
import me.shedaniel.rei.impl.client.search.collapsed.CollapsedEntriesCache;
import me.shedaniel.rei.impl.client.search.result.ArgumentApplicableResult;
import me.shedaniel.rei.impl.common.entry.type.EntryRegistryImpl;
import me.shedaniel.rei.impl.common.util.HNEntryStackWrapper;
import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand Down Expand Up @@ -78,18 +79,8 @@ public Argument(ArgumentType<T, R> argumentType, String text, boolean regular, T
public static void resetCache(boolean cache) {
Argument.cache = new ArgumentCache();
CollapsedEntriesCache.reset();
Collection<HashedEntryStackWrapper> stacks = new AbstractCollection<>() {
@Override
public Iterator<HashedEntryStackWrapper> iterator() {
return Iterators.transform(((EntryRegistryImpl) EntryRegistry.getInstance()).getComplexList().iterator(),
HashedEntryStackWrapper::normalize);
}

@Override
public int size() {
return ((EntryRegistryImpl) EntryRegistry.getInstance()).getComplexList().size();
}
};
List<HashedEntryStackWrapper> stacks = CollectionUtils.map(((EntryRegistryImpl) EntryRegistry.getInstance()).getComplexList(),
HNEntryStackWrapper::normalize);
if (cache) {
Argument.cache.prepareFilter(stacks, ArgumentTypesRegistry.ARGUMENT_TYPE_LIST, ArgumentCache.EXECUTOR_SERVICE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static CollapsedEntriesCache getInstance() {
return instance;
}

public void prepare(Collection<HashedEntryStackWrapper> stacks) {
public void prepare(Collection<? extends HashedEntryStackWrapper> stacks) {
Collection<CollapsibleEntryRegistryImpl.Entry> entries = ((CollapsibleEntryRegistryImpl) CollapsibleEntryRegistry.getInstance()).getEntries();
InternalLogger.getInstance().debug("Preparing collapsed entry groups cache with %d entries and %d stacks", entries.size(), stacks.size());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import me.shedaniel.rei.api.common.util.CollectionUtils;
import me.shedaniel.rei.api.common.util.EntryStacks;
import me.shedaniel.rei.impl.common.InternalLogger;
import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper;
import me.shedaniel.rei.impl.common.util.HNEntryStackWrapper;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.world.item.Item;
Expand Down Expand Up @@ -76,7 +76,7 @@ public ReloadStage getStage() {
@Override
public void startReload() {
this.listeners.clear();
this.registryList.collectHashed().clear();
this.registryList.collectHN().clear();
this.entriesHash = new LongOpenHashSet();
this.filteredList = new PreFilteredEntryList(this, this.registryList);
this.listeners.add(filteredList);
Expand Down Expand Up @@ -116,17 +116,17 @@ public List<EntryStack<?>> getPreFilteredList() {
return Collections.unmodifiableList(filteredList.getList());
}

public List<HashedEntryStackWrapper> getPreFilteredComplexList() {
public List<HNEntryStackWrapper> getPreFilteredComplexList() {
return Collections.unmodifiableList(filteredList.getComplexList());
}

public List<HashedEntryStackWrapper> getComplexList() {
return Collections.unmodifiableList(registryList.collectHashed());
public List<HNEntryStackWrapper> getComplexList() {
return Collections.unmodifiableList(registryList.collectHN());
}

@Override
public void refilter() {
List<HashedEntryStackWrapper> stacks = registryList.collectHashed();
List<HNEntryStackWrapper> stacks = registryList.collectHN();

for (EntryRegistryListener listener : listeners) {
listener.onReFilter(stacks);
Expand Down
Loading

0 comments on commit 11278f4

Please sign in to comment.