From 3cf5f00ce532cd3be7f8b5dc44c2515085ccf988 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Thu, 14 Oct 2021 19:54:52 +0800 Subject: Add parchment --- build.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.gradle b/build.gradle index 4d9d09784..9cc28a806 100755 --- a/build.gradle +++ b/build.gradle @@ -32,6 +32,7 @@ subprojects { minecraft("com.mojang:minecraft:${rootProject.minecraft_version}") mappings(loom.layered { officialMojangMappings() + parchment("org.parchmentmc.data:parchment-1.17.1:2021.10.10@zip") crane("dev.architectury:crane:1.17+build.11") }) } @@ -46,6 +47,7 @@ allprojects { repositories { maven { url "https://maven.shedaniel.me" } + maven { url "https://maven.parchmentmc.org" } maven { url "https://maven.terraformersmc.com/releases" } } -- cgit From c65b2a347b38724ccb777114f5353e7f18b978b5 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Thu, 14 Oct 2021 20:50:18 +0800 Subject: Make search report better errors, and cache more --- .../java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java | 3 +++ .../me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java | 9 --------- .../shedaniel/rei/impl/client/search/argument/Argument.java | 11 ++++++++++- .../me/shedaniel/rei/impl/client/util/CrashReportUtils.java | 7 +++++++ 4 files changed, 20 insertions(+), 10 deletions(-) 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 07a94a0b3..e80e5f572 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 @@ -43,6 +43,7 @@ import me.shedaniel.rei.api.common.registry.ReloadStage; import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl; import me.shedaniel.rei.impl.client.gui.hints.HintProvider; import me.shedaniel.rei.impl.client.gui.widget.search.OverlaySearchField; +import me.shedaniel.rei.impl.client.search.argument.Argument; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; @@ -216,6 +217,7 @@ public class REIRuntimeImpl implements REIRuntime { @Override public void startReload() { + Argument.SEARCH_CACHE.clear(); getOverlay().ifPresent(ScreenOverlay::queueReloadOverlay); lastDisplayScreen.clear(); } @@ -227,6 +229,7 @@ public class REIRuntimeImpl implements REIRuntime { @Override public void endReload(ReloadStage stage) { + Argument.SEARCH_CACHE.clear(); getOverlay().ifPresent(ScreenOverlay::queueReloadOverlay); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java index b8525b6dc..04901ba45 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java @@ -58,7 +58,6 @@ import me.shedaniel.rei.api.common.plugins.PluginManager; import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.api.common.util.EntryStacks; import me.shedaniel.rei.api.common.util.ImmutableTextComponent; -import me.shedaniel.rei.impl.ClientInternals; import me.shedaniel.rei.impl.client.ClientHelperImpl; import me.shedaniel.rei.impl.client.REIRuntimeImpl; import me.shedaniel.rei.impl.client.gui.craftable.CraftableFilter; @@ -70,29 +69,24 @@ import me.shedaniel.rei.impl.client.gui.widget.FavoritesListWidget; import me.shedaniel.rei.impl.client.gui.widget.InternalWidgets; import me.shedaniel.rei.impl.client.gui.widget.LateRenderable; import me.shedaniel.rei.impl.client.gui.widget.search.OverlaySearchField; -import me.shedaniel.rei.impl.client.search.argument.Argument; import me.shedaniel.rei.impl.common.util.Weather; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.chat.NarratorChatListener; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; -import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.PlayerInfo; import net.minecraft.client.renderer.entity.ItemRenderer; import net.minecraft.client.resources.language.I18n; import net.minecraft.client.resources.sounds.SimpleSoundInstance; -import net.minecraft.locale.Language; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.Style; import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvents; import net.minecraft.world.InteractionResult; import net.minecraft.world.inventory.Slot; -import net.minecraft.world.inventory.tooltip.TooltipComponent; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.GameType; import net.minecraft.world.level.block.Blocks; @@ -102,8 +96,6 @@ import org.jetbrains.annotations.Nullable; import java.util.*; import java.util.function.Consumer; import java.util.function.Predicate; -import java.util.stream.Collectors; -import java.util.stream.Stream; @ApiStatus.Internal public class ScreenOverlayImpl extends ScreenOverlay { @@ -225,7 +217,6 @@ public class ScreenOverlayImpl extends ScreenOverlay { } public void init() { - Argument.SEARCH_CACHE.clear(); draggingStack.set(DraggableStackProvider.from(() -> ScreenRegistry.getInstance().getDraggableProviders()), DraggableStackVisitor.from(() -> ScreenRegistry.getInstance().getDraggableVisitors())); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/Argument.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/Argument.java index b7e733321..0d1ba77b4 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/Argument.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/Argument.java @@ -29,6 +29,7 @@ import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectMaps; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import it.unimi.dsi.fastutil.shorts.Short2ObjectMap; +import it.unimi.dsi.fastutil.shorts.Short2ObjectMaps; import it.unimi.dsi.fastutil.shorts.Short2ObjectOpenHashMap; import me.shedaniel.rei.api.client.gui.config.SearchMode; import me.shedaniel.rei.api.common.entry.EntryStack; @@ -40,6 +41,7 @@ import me.shedaniel.rei.impl.client.search.argument.type.ArgumentTypesRegistry; import me.shedaniel.rei.impl.client.search.result.ArgumentApplicableResult; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.Minecraft; import net.minecraft.util.Unit; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.mutable.Mutable; @@ -50,6 +52,8 @@ import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.List; import java.util.Locale; +import java.util.Objects; +import java.util.concurrent.atomic.AtomicReference; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -57,7 +61,8 @@ import java.util.regex.Pattern; @Environment(EnvType.CLIENT) public class Argument { public static final String SPACE = " ", EMPTY = ""; - public static final Short2ObjectMap> SEARCH_CACHE = new Short2ObjectOpenHashMap<>(); + public static final Short2ObjectMap> SEARCH_CACHE = Short2ObjectMaps.synchronize(new Short2ObjectOpenHashMap<>()); + private static final AtomicReference lastLanguage = new AtomicReference<>(); static final Argument ALWAYS = new Argument<>(AlwaysMatchingArgumentType.INSTANCE, EMPTY, true, -1, -1, true); private ArgumentType argumentType; private String text; @@ -169,6 +174,10 @@ public class Argument { @ApiStatus.Internal public static boolean matches(EntryStack stack, List compoundArguments) { if (compoundArguments.isEmpty()) return true; + String newLanguage = Minecraft.getInstance().options.languageCode; + if (!Objects.equals(lastLanguage.getAndSet(newLanguage), newLanguage)) { + SEARCH_CACHE.clear(); + } Mutable mutable = new MutableObject<>(); a: diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/util/CrashReportUtils.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/util/CrashReportUtils.java index d55567909..ac7cc3777 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/util/CrashReportUtils.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/util/CrashReportUtils.java @@ -32,6 +32,13 @@ import net.minecraft.client.gui.screens.Screen; public class CrashReportUtils { public static CrashReport essential(Throwable throwable, String task) { + Throwable temp = throwable; + while (temp != null) { + temp = temp.getCause(); + if (temp instanceof ReportedException reportedException) { + return essential(reportedException, task); + } + } CrashReport report = CrashReport.forThrowable(throwable, task); screen(report, Minecraft.getInstance().screen); return report; -- cgit From a7b0a0dd4b305eb8655b008ebcfdcd2f7b70079a Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 15 Oct 2021 02:43:07 +0800 Subject: Fix merge conflicts --- .../shedaniel/rei/impl/common/compat/FabricFluidAPISupportPlugin.java | 3 ++- forge/build.gradle | 4 +++- .../main/java/me/shedaniel/rei/impl/client/util/CrashReportUtils.java | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/fabric/src/main/java/me/shedaniel/rei/impl/common/compat/FabricFluidAPISupportPlugin.java b/fabric/src/main/java/me/shedaniel/rei/impl/common/compat/FabricFluidAPISupportPlugin.java index 651ff2821..01b5f2a47 100644 --- a/fabric/src/main/java/me/shedaniel/rei/impl/common/compat/FabricFluidAPISupportPlugin.java +++ b/fabric/src/main/java/me/shedaniel/rei/impl/common/compat/FabricFluidAPISupportPlugin.java @@ -30,6 +30,7 @@ import me.shedaniel.rei.api.common.fluid.FluidSupportProvider; import me.shedaniel.rei.api.common.plugins.REIServerPlugin; import me.shedaniel.rei.api.common.util.EntryStacks; import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidConstants; import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage; import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; import net.fabricmc.fabric.api.transfer.v1.storage.Storage; @@ -50,7 +51,7 @@ public class FabricFluidAPISupportPlugin implements REIServerPlugin { try (Transaction transaction = Transaction.openOuter()) { result = StreamSupport.stream(storage.iterable(transaction).spliterator(), false) .filter(view -> !view.isResourceBlank() && !view.getResource().isBlank()) - .map(view -> EntryStacks.of(FluidStack.create(view.getResource().getFluid(), view.getAmount(), view.getResource().getNbt()))) + .map(view -> EntryStacks.of(FluidStack.create(view.getResource().getFluid(), Fraction.of(view.getAmount(), FluidConstants.BUCKET), view.getResource().getNbt()))) .collect(Collectors.toList()); } if (!result.isEmpty()) { diff --git a/forge/build.gradle b/forge/build.gradle index 94be9b025..1accad167 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -57,7 +57,7 @@ dependencies { common(project(path: ":jei-compatibility-layer", configuration: "dev")) { transitive false } shadowCommon(project(path: ":jei-compatibility-layer", configuration: "dev")) { transitive false } - // common(project(path: ":jei-internals-workaround")) { transitive = false } + // runtimeClasspath(project(path: ":jei-internals-workaround", configuration: "dev")) { transitive = false } depProjects.forEach { common(project(path: it, configuration: "dev")) { transitive false } @@ -82,6 +82,8 @@ dependencies { // modRuntime("curse.maven:jep-417645:3198370") // modRuntime("curse.maven:simple-storage-network-268495:3257204") // modRuntime("curse.maven:create-328085:3278516") + modRuntime("curse.maven:industrial-foregoing-266515:3446262") + modRuntime("curse.maven:titanium-287342:3346366") } shadowJar { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/util/CrashReportUtils.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/util/CrashReportUtils.java index ac7cc3777..d3159a9ca 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/util/CrashReportUtils.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/util/CrashReportUtils.java @@ -35,8 +35,8 @@ public class CrashReportUtils { Throwable temp = throwable; while (temp != null) { temp = temp.getCause(); - if (temp instanceof ReportedException reportedException) { - return essential(reportedException, task); + if (temp instanceof ReportedException) { + return essential(temp, task); } } CrashReport report = CrashReport.forThrowable(throwable, task); -- cgit From 3a84bfa28bb233b3a6f0a14f2e90956a98512453 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 15 Oct 2021 02:43:32 +0800 Subject: Add tag match & JEI recipe ids --- .../gui/screen/DefaultDisplayViewingScreen.java | 43 ++++++++++++++++++++++ .../rei/impl/client/gui/widget/EntryWidget.java | 9 +++++ .../impl/client/gui/widget/InternalWidgets.java | 3 +- .../assets/roughlyenoughitems/lang/en_us.json | 1 + 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java index 08fa19f81..c190033b2 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java @@ -29,6 +29,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.math.Matrix4f; +import me.shedaniel.architectury.fluid.FluidStack; import me.shedaniel.clothconfig2.api.ModifierKeyCode; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; @@ -46,6 +47,9 @@ import me.shedaniel.rei.api.client.view.ViewSearchBuilder; import me.shedaniel.rei.api.common.category.CategoryIdentifier; 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.entry.type.EntryType; +import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.api.common.util.ImmutableTextComponent; import me.shedaniel.rei.impl.client.ClientHelperImpl; @@ -67,7 +71,11 @@ import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvents; +import net.minecraft.tags.Tag; +import net.minecraft.tags.TagCollection; +import net.minecraft.tags.TagContainer; import net.minecraft.util.Mth; +import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; @@ -246,8 +254,12 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { int displayWidth = getCurrentCategory().getDisplayWidth(displaySupplier.get()); final Rectangle displayBounds = new Rectangle(getBounds().getCenterX() - displayWidth / 2, getBounds().getCenterY() + 16 - recipeHeight * (getRecipesPerPage() + 1) / 2 - 2 * (getRecipesPerPage() + 1) + recipeHeight * i + 4 * i, displayWidth, recipeHeight); List setupDisplay = getCurrentCategory().setupDisplay(display, displayBounds); + setupTags(setupDisplay); transformIngredientNotice(setupDisplay, ingredientStackToNotice); transformResultNotice(setupDisplay, resultStackToNotice); + for (EntryWidget widget : Widgets.walk(widgets, EntryWidget.class::isInstance)) { + widget.removeTagMatch = true; + } recipeBounds.put(displayBounds, setupDisplay); this.widgets.addAll(setupDisplay); if (supplier.isPresent() && supplier.get().get(displayBounds) != null) @@ -287,6 +299,37 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { _children().addAll(preWidgets); } + private void setupTags(List widgets) { + TagContainer tags = Minecraft.getInstance().getConnection().getTags(); + outer: + for (EntryWidget widget : Widgets.walk(widgets, EntryWidget.class::isInstance)) { + widget.removeTagMatch = false; + if (widget.getEntries().size() <= 1) continue; + EntryType type = null; + for (EntryStack entry : widget.getEntries()) { + if (type == null) { + type = entry.getType(); + } else if (type != entry.getType()) { + continue outer; + } + } + // TODO: Don't hardcode + TagCollection collection; + List objects; + if (type == VanillaEntryTypes.ITEM) { + collection = tags.getItems(); + objects = CollectionUtils.map(widget.getEntries(), stack -> stack.castValue().getItem()); + } else if (type == VanillaEntryTypes.FLUID) { + collection = tags.getFluids(); + objects = CollectionUtils.map(widget.getEntries(), stack -> stack.castValue().getFluid()); + } else continue; + Map.Entry> firstOrNull = CollectionUtils.findFirstOrNull(collection.getAllTags().entrySet(), entry -> entry.getValue().getValues().equals(objects)); + if (firstOrNull != null) { + widget.tagMatch = firstOrNull.getKey(); + } + } + } + public List getWidgets() { return widgets; } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java index 053186a50..f1693459b 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java @@ -43,12 +43,14 @@ import me.shedaniel.rei.api.client.view.ViewSearchBuilder; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.impl.client.REIRuntimeImpl; import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl; +import net.minecraft.ChatFormatting; import net.minecraft.CrashReport; import net.minecraft.CrashReportCategory; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.resources.language.I18n; import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; import org.jetbrains.annotations.ApiStatus; @@ -77,6 +79,8 @@ public class EntryWidget extends Slot implements DraggableStackProviderWidget { protected boolean wasClicked = false; private Rectangle bounds; private List> entryStacks; + public ResourceLocation tagMatch; + public boolean removeTagMatch = true; public EntryWidget(Point point) { this(new Rectangle(point.x - 1, point.y - 1, 18, 18)); @@ -231,6 +235,7 @@ public class EntryWidget extends Slot implements DraggableStackProviderWidget { } entryStacks.add(stack); } + if (removeTagMatch) tagMatch = null; return this; } @@ -241,6 +246,7 @@ public class EntryWidget extends Slot implements DraggableStackProviderWidget { entryStacks = new ArrayList<>(entryStacks); } entryStacks.addAll(stacks); + if (removeTagMatch) tagMatch = null; } return this; } @@ -318,6 +324,9 @@ public class EntryWidget extends Slot implements DraggableStackProviderWidget { tooltip.addAllTexts(Stream.of(I18n.get("text.rei.favorites_tooltip", name).split("\n")) .map(TextComponent::new).collect(Collectors.toList())); } + if (tagMatch != null) { + tooltip.add(new TranslatableComponent("text.rei.tag_match", tagMatch.toString()).withStyle(ChatFormatting.GRAY)); + } tooltip.queue(); } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java index 8df053102..1529a9e4b 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java @@ -48,6 +48,7 @@ import net.fabricmc.api.Environment; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.resources.language.I18n; import net.minecraft.network.chat.Component; @@ -176,7 +177,7 @@ public final class InternalWidgets { str.add(errorTooltip[0].get(0).copy().withStyle(ChatFormatting.RED)); } } - if (Minecraft.getInstance().options.advancedItemTooltips && displaySupplier.get().getDisplayLocation().isPresent()) { + if ((Minecraft.getInstance().options.advancedItemTooltips || Screen.hasShiftDown()) && displaySupplier.get().getDisplayLocation().isPresent()) { str.add(new TranslatableComponent("text.rei.recipe_id", "", new TextComponent(displaySupplier.get().getDisplayLocation().get().toString()).withStyle(ChatFormatting.GRAY)).withStyle(ChatFormatting.GRAY)); } return str.toArray(new Component[0]); diff --git a/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json b/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json index bd3b05295..beddd9239 100755 --- a/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json +++ b/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json @@ -47,6 +47,7 @@ "text.rei.cheat_items": "Gave [{item_name}§f] x{item_count} to {player_name}.", "text.rei.failed_cheat_items": "§cFailed to give items.", "text.rei.too_long_nbt": "§cItem NBT is too long to be applied in multiplayer.", + "text.rei.tag_match": "Tag: %s", "ordering.rei.ascending": "Ascending", "ordering.rei.descending": "Descending", "ordering.rei.registry": "Registry", -- cgit From 6e7a641926d8b0ea2d0a1caddbf348fe24b669ce Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 16 Oct 2021 00:37:19 +0800 Subject: Fix JEI recipes duplicating and going to the wrong category, Fix JER's insane resource reload during plugin application, Add DisplayAdditionReason, Safeguard DisplayCategory#setupDisplay --- .../client/registry/display/DisplayRegistry.java | 45 +++++++++++++- .../display/reason/DisplayAdditionReason.java | 21 +++++++ .../display/reason/DisplayAdditionReasons.java | 68 ++++++++++++++++++++++ .../rei/api/common/plugins/REIPlugin.java | 7 +++ forge/build.gradle | 2 + forge/src/main/resources/META-INF/mods.toml | 2 +- .../gui/screen/AbstractDisplayViewingScreen.java | 40 +++++++++++++ .../gui/screen/CompositeDisplayViewingScreen.java | 17 +++++- .../gui/screen/DefaultDisplayViewingScreen.java | 55 ++++------------- .../registry/display/DisplayRegistryImpl.java | 23 +++++--- .../rei/impl/common/plugins/PluginManagerImpl.java | 49 ++++++++++++---- 11 files changed, 264 insertions(+), 65 deletions(-) create mode 100644 api/src/main/java/me/shedaniel/rei/api/client/registry/display/reason/DisplayAdditionReason.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/client/registry/display/reason/DisplayAdditionReasons.java diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java index 2ecb40967..ad3a2aa18 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java @@ -25,6 +25,8 @@ package me.shedaniel.rei.api.client.registry.display; import com.google.common.base.Predicates; import me.shedaniel.rei.api.client.plugins.REIClientPlugin; +import me.shedaniel.rei.api.client.registry.display.reason.DisplayAdditionReason; +import me.shedaniel.rei.api.client.registry.display.reason.DisplayAdditionReasons; import me.shedaniel.rei.api.client.registry.display.visibility.DisplayVisibilityPredicate; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.Display; @@ -34,9 +36,11 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeType; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import java.util.*; +import java.util.function.BiPredicate; import java.util.function.Function; import java.util.function.Predicate; @@ -100,10 +104,20 @@ public interface DisplayRegistry extends RecipeManagerContext { * @param object the object to be filled */ default void add(Object object) { + addWithReason(object, DisplayAdditionReason.NONE); + } + + /** + * Registers a display by the object provided, to be filled during {@link #tryFillDisplay(Object)}. + * + * @param object the object to be filled + */ + @ApiStatus.Experimental + default void addWithReason(Object object, DisplayAdditionReason... reasons) { if (object instanceof Display) { add((Display) object, null); } else { - for (Display display : tryFillDisplay(object)) { + for (Display display : tryFillDisplay(object, reasons)) { add(display, object); } } @@ -269,6 +283,21 @@ public interface DisplayRegistry extends RecipeManagerContext { */ void registerFiller(Class typeClass, Predicate predicate, Function filler); + /** + * Registers a display filler, to be filled during {@link #tryFillDisplay(Object)}. + *

+ * Vanilla {@link Recipe} are by default filled, display filters + * can be used to automatically generate displaies for vanilla {@link Recipe}. + * + * @param typeClass the type of {@code T} + * @param predicate the predicate of {@code T} and reason + * @param filler the filler, taking a {@code T} and returning a {@code D} + * @param the type of object + * @param the type of display + */ + @ApiStatus.Experimental + void registerFiller(Class typeClass, BiPredicate predicate, Function filler); + /** * Registers a display filler, to be filled during {@link #tryFillDisplay(Object)}. *

@@ -288,7 +317,19 @@ public interface DisplayRegistry extends RecipeManagerContext { * @param the type of object * @return the collection of displays */ - Collection tryFillDisplay(T value); + default Collection tryFillDisplay(T value) { + return tryFillDisplay(value, DisplayAdditionReason.NONE); + } + + /** + * Tries to fill displays from {@code T}. + * + * @param value the object + * @param the type of object + * @return the collection of displays + */ + @ApiStatus.Experimental + Collection tryFillDisplay(T value, DisplayAdditionReason... reasons); @Nullable Object getDisplayOrigin(Display display); diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/display/reason/DisplayAdditionReason.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/reason/DisplayAdditionReason.java new file mode 100644 index 000000000..aae5244f2 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/reason/DisplayAdditionReason.java @@ -0,0 +1,21 @@ +package me.shedaniel.rei.api.client.registry.display.reason; + +import org.jetbrains.annotations.ApiStatus; + +/** + * Reason for adding a display, used for {@link me.shedaniel.rei.api.client.registry.display.DisplayRegistry#tryFillDisplay(Object, DisplayAdditionReason...)} + * Plugins may filter their filler with reasons, this class can be implemented to provide additional context to fillers. + */ +@ApiStatus.Experimental +public interface DisplayAdditionReason { + DisplayAdditionReason[] NONE = new DisplayAdditionReason[0]; + /** + * Denotes that the display is added automatically by REI's RecipeManager, + * fillers which do not wish to be added with this should filter with this. + */ + DisplayAdditionReason RECIPE_MANAGER = simple(); + + static DisplayAdditionReason simple() { + return new DisplayAdditionReason() {}; + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/display/reason/DisplayAdditionReasons.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/reason/DisplayAdditionReasons.java new file mode 100644 index 000000000..ed3e43126 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/reason/DisplayAdditionReasons.java @@ -0,0 +1,68 @@ +package me.shedaniel.rei.api.client.registry.display.reason; + +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; + +import java.util.Objects; + +@ApiStatus.Experimental +public interface DisplayAdditionReasons { + @Nullable T get(Class c); + + @Nullable T get(T c); + + boolean has(Class c); + + boolean has(T c); + + @ApiStatus.Internal + class Impl implements DisplayAdditionReasons { + public static final Impl EMPTY = new Impl(DisplayAdditionReason.NONE); + private final DisplayAdditionReason[] reasons; + + public Impl(DisplayAdditionReason[] reasons) { + this.reasons = reasons; + } + + @Override + @Nullable + public T get(Class c) { + for (DisplayAdditionReason reason : reasons) { + if (Objects.equals(reason.getClass(), c)) { + return (T) reason; + } + } + return null; + } + + @Override + public @Nullable T get(T c) { + for (DisplayAdditionReason reason : reasons) { + if (Objects.equals(reason, c)) { + return (T) reason; + } + } + return null; + } + + @Override + public boolean has(Class c) { + for (DisplayAdditionReason reason : reasons) { + if (Objects.equals(reason.getClass(), c)) { + return true; + } + } + return false; + } + + @Override + public boolean has(T c) { + for (DisplayAdditionReason reason : reasons) { + if (Objects.equals(reason, c)) { + return true; + } + } + return false; + } + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/common/plugins/REIPlugin.java b/api/src/main/java/me/shedaniel/rei/api/common/plugins/REIPlugin.java index 724dc0fed..2599281e8 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/plugins/REIPlugin.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/plugins/REIPlugin.java @@ -29,6 +29,7 @@ import me.shedaniel.rei.api.common.entry.comparison.FluidComparatorRegistry; import me.shedaniel.rei.api.common.entry.comparison.ItemComparatorRegistry; import me.shedaniel.rei.api.common.entry.type.EntryTypeRegistry; import me.shedaniel.rei.api.common.fluid.FluidSupportProvider; +import me.shedaniel.rei.api.common.registry.Reloadable; import org.jetbrains.annotations.ApiStatus; import java.util.Collection; @@ -107,4 +108,10 @@ public interface REIPlugin

> extends Comparable provide() { return Collections.singletonList((P) this); } + + @ApiStatus.Internal + @ApiStatus.Experimental + default boolean shouldBeForcefullyDoneOnMainThread(Reloadable reloadable) { + return false; + } } diff --git a/forge/build.gradle b/forge/build.gradle index 1accad167..eca05ac20 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -84,6 +84,8 @@ dependencies { // modRuntime("curse.maven:create-328085:3278516") modRuntime("curse.maven:industrial-foregoing-266515:3446262") modRuntime("curse.maven:titanium-287342:3346366") + modRuntime("curse.maven:extended-crafting-268387:3470453") + modRuntime("curse.maven:cucumber-272335:3349690") } shadowJar { diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index 1a89466fd..f35aba857 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -8,7 +8,7 @@ license = "MIT" [[mods]] modId = "roughlyenoughitems" version = "${version}" -displayName = "Roughly Enough Items" +displayName = "Roughly Enough Items (REI)" description = ''' To allow players to view items and recipes. ''' diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java index 0d69d3fce..48aea3c1a 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java @@ -24,6 +24,7 @@ package me.shedaniel.rei.impl.client.gui.screen; import com.google.common.collect.Lists; +import me.shedaniel.architectury.fluid.FluidStack; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.gui.screen.DisplayScreen; import me.shedaniel.rei.api.client.gui.widgets.Slot; @@ -33,12 +34,20 @@ import me.shedaniel.rei.api.client.registry.display.DisplayCategory; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.Display; import me.shedaniel.rei.api.common.entry.EntryStack; +import me.shedaniel.rei.api.common.entry.type.EntryType; +import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.impl.client.ClientHelperImpl; import me.shedaniel.rei.impl.client.gui.widget.EntryWidget; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.chat.NarratorChatListener; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.screens.Screen; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.Tag; +import net.minecraft.tags.TagCollection; +import net.minecraft.tags.TagContainer; +import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -151,4 +160,35 @@ public abstract class AbstractDisplayViewingScreen extends Screen implements Dis } } } + + protected void setupTags(List widgets) { + TagContainer tags = Minecraft.getInstance().getConnection().getTags(); + outer: + for (EntryWidget widget : Widgets.walk(widgets, EntryWidget.class::isInstance)) { + widget.removeTagMatch = false; + if (widget.getEntries().size() <= 1) continue; + EntryType type = null; + for (EntryStack entry : widget.getEntries()) { + if (type == null) { + type = entry.getType(); + } else if (type != entry.getType()) { + continue outer; + } + } + // TODO: Don't hardcode + TagCollection collection; + List objects; + if (type == VanillaEntryTypes.ITEM) { + collection = tags.getItems(); + objects = CollectionUtils.map(widget.getEntries(), stack -> stack.castValue().getItem()); + } else if (type == VanillaEntryTypes.FLUID) { + collection = tags.getFluids(); + objects = CollectionUtils.map(widget.getEntries(), stack -> stack.castValue().getFluid()); + } else continue; + Map.Entry> firstOrNull = CollectionUtils.findFirstOrNull(collection.getAllTags().entrySet(), entry -> entry.getValue().getValues().equals(objects)); + if (firstOrNull != null) { + widget.tagMatch = firstOrNull.getKey(); + } + } + } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java index b2b86fb47..5d1d66a98 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java @@ -47,6 +47,7 @@ import me.shedaniel.rei.api.common.display.Display; import me.shedaniel.rei.api.common.entry.EntryIngredient; import me.shedaniel.rei.impl.client.ClientHelperImpl; import me.shedaniel.rei.impl.client.REIRuntimeImpl; +import me.shedaniel.rei.impl.client.gui.widget.EntryWidget; import me.shedaniel.rei.impl.client.gui.widget.InternalWidgets; import me.shedaniel.rei.impl.client.gui.widget.TabWidget; import net.minecraft.client.Minecraft; @@ -61,6 +62,7 @@ import net.minecraft.util.Mth; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Optional; @@ -152,9 +154,22 @@ public class CompositeDisplayViewingScreen extends AbstractDisplayViewingScreen this.widgets.add(Widgets.createSlotBase(scrollListBounds)); Rectangle recipeBounds = new Rectangle(bounds.x + 100 + (guiWidth - 100) / 2 - category.getDisplayWidth(display) / 2, bounds.y + bounds.height / 2 - category.getDisplayHeight() / 2, category.getDisplayWidth(display), category.getDisplayHeight()); - List setupDisplay = category.setupDisplay(display, recipeBounds); + List setupDisplay; + try { + setupDisplay = category.setupDisplay(display, recipeBounds); + } catch (Throwable throwable) { + throwable.printStackTrace(); + setupDisplay = new ArrayList<>(); + setupDisplay.add(Widgets.createRecipeBase(bounds).color(0xFFBB0000)); + setupDisplay.add(Widgets.createLabel(new Point(bounds.getCenterX(), bounds.getCenterY() - 8), new TextComponent("Failed to initiate setupDisplay"))); + setupDisplay.add(Widgets.createLabel(new Point(bounds.getCenterX(), bounds.getCenterY() + 1), new TextComponent("Check console for error"))); + } + setupTags(setupDisplay); transformIngredientNotice(setupDisplay, ingredientStackToNotice); transformResultNotice(setupDisplay, resultStackToNotice); + for (EntryWidget widget : Widgets.walk(widgets, EntryWidget.class::isInstance)) { + widget.removeTagMatch = true; + } this.widgets.addAll(setupDisplay); Optional supplier = CategoryRegistry.getInstance().get(category.getCategoryIdentifier()).getPlusButtonArea(); if (supplier.isPresent() && supplier.get().get(recipeBounds) != null) diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java index c190033b2..52e5b3a67 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java @@ -29,7 +29,6 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.math.Matrix4f; -import me.shedaniel.architectury.fluid.FluidStack; import me.shedaniel.clothconfig2.api.ModifierKeyCode; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; @@ -47,9 +46,6 @@ import me.shedaniel.rei.api.client.view.ViewSearchBuilder; import me.shedaniel.rei.api.common.category.CategoryIdentifier; 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.entry.type.EntryType; -import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.api.common.util.ImmutableTextComponent; import me.shedaniel.rei.impl.client.ClientHelperImpl; @@ -71,18 +67,11 @@ import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvents; -import net.minecraft.tags.Tag; -import net.minecraft.tags.TagCollection; -import net.minecraft.tags.TagContainer; import net.minecraft.util.Mth; -import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.function.Supplier; @ApiStatus.Internal @@ -253,7 +242,16 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { final Supplier displaySupplier = () -> display; int displayWidth = getCurrentCategory().getDisplayWidth(displaySupplier.get()); final Rectangle displayBounds = new Rectangle(getBounds().getCenterX() - displayWidth / 2, getBounds().getCenterY() + 16 - recipeHeight * (getRecipesPerPage() + 1) / 2 - 2 * (getRecipesPerPage() + 1) + recipeHeight * i + 4 * i, displayWidth, recipeHeight); - List setupDisplay = getCurrentCategory().setupDisplay(display, displayBounds); + List setupDisplay; + try { + setupDisplay = getCurrentCategory().setupDisplay(display, displayBounds); + } catch (Throwable throwable) { + throwable.printStackTrace(); + setupDisplay = new ArrayList<>(); + setupDisplay.add(Widgets.createRecipeBase(bounds).color(0xFFBB0000)); + setupDisplay.add(Widgets.createLabel(new Point(bounds.getCenterX(), bounds.getCenterY() - 8), new TextComponent("Failed to initiate setupDisplay"))); + setupDisplay.add(Widgets.createLabel(new Point(bounds.getCenterX(), bounds.getCenterY() + 1), new TextComponent("Check console for error"))); + } setupTags(setupDisplay); transformIngredientNotice(setupDisplay, ingredientStackToNotice); transformResultNotice(setupDisplay, resultStackToNotice); @@ -299,37 +297,6 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { _children().addAll(preWidgets); } - private void setupTags(List widgets) { - TagContainer tags = Minecraft.getInstance().getConnection().getTags(); - outer: - for (EntryWidget widget : Widgets.walk(widgets, EntryWidget.class::isInstance)) { - widget.removeTagMatch = false; - if (widget.getEntries().size() <= 1) continue; - EntryType type = null; - for (EntryStack entry : widget.getEntries()) { - if (type == null) { - type = entry.getType(); - } else if (type != entry.getType()) { - continue outer; - } - } - // TODO: Don't hardcode - TagCollection collection; - List objects; - if (type == VanillaEntryTypes.ITEM) { - collection = tags.getItems(); - objects = CollectionUtils.map(widget.getEntries(), stack -> stack.castValue().getItem()); - } else if (type == VanillaEntryTypes.FLUID) { - collection = tags.getFluids(); - objects = CollectionUtils.map(widget.getEntries(), stack -> stack.castValue().getFluid()); - } else continue; - Map.Entry> firstOrNull = CollectionUtils.findFirstOrNull(collection.getAllTags().entrySet(), entry -> entry.getValue().getValues().equals(objects)); - if (firstOrNull != null) { - widget.tagMatch = firstOrNull.getKey(); - } - } - } - public List getWidgets() { return widgets; } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java index e638f14fd..bfc975188 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java @@ -31,6 +31,8 @@ import me.shedaniel.rei.api.client.registry.category.CategoryRegistry; import me.shedaniel.rei.api.client.registry.display.DisplayCategory; import me.shedaniel.rei.api.client.registry.display.DisplayRegistry; import me.shedaniel.rei.api.client.registry.display.DynamicDisplayGenerator; +import me.shedaniel.rei.api.client.registry.display.reason.DisplayAdditionReason; +import me.shedaniel.rei.api.client.registry.display.reason.DisplayAdditionReasons; import me.shedaniel.rei.api.client.registry.display.visibility.DisplayVisibilityPredicate; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.Display; @@ -41,6 +43,7 @@ import org.jetbrains.annotations.Nullable; import java.util.*; import java.util.concurrent.ConcurrentHashMap; +import java.util.function.BiPredicate; import java.util.function.Function; import java.util.function.Predicate; @@ -139,9 +142,14 @@ public class DisplayRegistryImpl extends RecipeManagerContextImpl typeClass.isInstance(o) && ((Predicate) predicate).test((T) o), o -> ((Function) filler).apply((T) o)); } + @Override + public void registerFiller(Class typeClass, BiPredicate predicate, Function filler) { + fillers.add(new DisplayFiller<>((o, s) -> typeClass.isInstance(o) && ((BiPredicate) predicate).test(o, s), (Function) filler)); + } + @Override public void registerFiller(Predicate predicate, Function filler) { - fillers.add(new DisplayFiller<>((Predicate) predicate, (Function) filler)); + fillers.add(new DisplayFiller<>((o, s) -> ((Predicate) predicate).test(o), (Function) filler)); } @Override @@ -160,17 +168,18 @@ public class DisplayRegistryImpl extends RecipeManagerContextImpl> allSortedRecipes = getAllSortedRecipes(); for (int i = allSortedRecipes.size() - 1; i >= 0; i--) { Recipe recipe = allSortedRecipes.get(i); - add(recipe); + addWithReason(recipe, DisplayAdditionReason.RECIPE_MANAGER); } } } @Override - public Collection tryFillDisplay(T value) { + public Collection tryFillDisplay(T value, DisplayAdditionReason... reason) { if (value instanceof Display) return Collections.singleton((Display) value); List displays = null; + DisplayAdditionReasons reasons = reason.length == 0 ? DisplayAdditionReasons.Impl.EMPTY : new DisplayAdditionReasons.Impl(reason); for (DisplayFiller filler : fillers) { - Display display = tryFillDisplayGenerics(filler, value); + Display display = tryFillDisplayGenerics(filler, value, reasons); if (display != null) { if (displays == null) displays = Collections.singletonList(display); else { @@ -185,9 +194,9 @@ public class DisplayRegistryImpl extends RecipeManagerContextImpl D tryFillDisplayGenerics(DisplayFiller filler, Object value) { + private D tryFillDisplayGenerics(DisplayFiller filler, Object value, DisplayAdditionReasons reasons) { try { - if (filler.predicate.test(value)) { + if (filler.predicate.test(value, reasons)) { return filler.mappingFunction.apply(value); } } catch (Throwable e) { @@ -204,7 +213,7 @@ public class DisplayRegistryImpl extends RecipeManagerContextImpl( - Predicate predicate, + BiPredicate predicate, Function mappingFunction ) {} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java index 82bc8f518..f3421e76e 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java @@ -23,10 +23,13 @@ package me.shedaniel.rei.impl.common.plugins; -import com.google.common.base.MoreObjects; import com.google.common.base.Stopwatch; import com.google.common.collect.FluentIterable; import com.google.common.collect.Iterables; +import me.shedaniel.architectury.platform.Platform; +import me.shedaniel.architectury.utils.Env; +import me.shedaniel.architectury.utils.EnvExecutor; +import me.shedaniel.architectury.utils.GameInstance; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.common.plugins.PluginManager; import me.shedaniel.rei.api.common.plugins.PluginView; @@ -36,8 +39,11 @@ import me.shedaniel.rei.api.common.registry.ReloadStage; import me.shedaniel.rei.api.common.registry.Reloadable; import me.shedaniel.rei.api.common.util.CollectionUtils; import net.minecraft.Util; +import net.minecraft.client.Minecraft; +import net.minecraft.server.MinecraftServer; import org.apache.commons.lang3.tuple.MutablePair; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; import java.io.Closeable; import java.util.*; @@ -103,7 +109,7 @@ public class PluginManagerImpl

> implements PluginManager< @Override public void registerPlugin(REIPluginProvider plugin) { plugins.add((REIPluginProvider

) plugin); - RoughlyEnoughItemsCore.LOGGER.info("Registered plugin provider %s for %s", plugin.getPluginProviderName(), pluginClass.getSimpleName()); + RoughlyEnoughItemsCore.LOGGER.info("Registered plugin provider %s for %s", plugin.getPluginProviderName(), name(pluginClass)); } @Override @@ -139,23 +145,40 @@ public class PluginManagerImpl

> implements PluginManager< return new SectionClosable(sectionData, section); } - private void pluginSection(MutablePair sectionData, String sectionName, List

list, Consumer

consumer) { + private void pluginSection(MutablePair sectionData, String sectionName, List

list, @Nullable Reloadable reloadable, Consumer

consumer) { for (P plugin : list) { try (SectionClosable section = section(sectionData, sectionName + " for " + plugin.getPluginProviderName())) { - consumer.accept(plugin); + if (reloadable == null || !plugin.shouldBeForcefullyDoneOnMainThread(reloadable)) { + consumer.accept(plugin); + } else if (Platform.getEnvironment() == Env.CLIENT) { + EnvExecutor.runInEnv(Env.CLIENT, () -> () -> queueExecutionClient(() -> consumer.accept(plugin))); + } else { + queueExecution(() -> consumer.accept(plugin)); + } } catch (Throwable throwable) { RoughlyEnoughItemsCore.LOGGER.error(plugin.getPluginProviderName() + " plugin failed to " + sectionName + "!", throwable); } } } + private void queueExecution(Runnable runnable) { + MinecraftServer server = GameInstance.getServer(); + if (server != null) { + server.executeBlocking(runnable); + } + } + + private void queueExecutionClient(Runnable runnable) { + Minecraft.getInstance().executeBlocking(runnable); + } + @Override public void pre() { List

plugins = new ArrayList<>(getPlugins().toList()); plugins.sort(Comparator.comparingDouble(P::getPriority).reversed()); Collections.reverse(plugins); MutablePair sectionData = new MutablePair<>(Stopwatch.createUnstarted(), ""); - pluginSection(sectionData, "pre-register", plugins, REIPlugin::preRegister); + pluginSection(sectionData, "pre-register", plugins, null, REIPlugin::preRegister); } @Override @@ -164,7 +187,13 @@ public class PluginManagerImpl

> implements PluginManager< plugins.sort(Comparator.comparingDouble(P::getPriority).reversed()); Collections.reverse(plugins); MutablePair sectionData = new MutablePair<>(Stopwatch.createUnstarted(), ""); - pluginSection(sectionData, "post-register", plugins, REIPlugin::postRegister); + pluginSection(sectionData, "post-register", plugins, null, REIPlugin::postRegister); + } + + private static String name(Class clazz) { + String simpleName = clazz.getSimpleName(); + if (simpleName.isEmpty()) return clazz.getName(); + return simpleName; } @Override @@ -176,7 +205,7 @@ public class PluginManagerImpl

> implements PluginManager< for (Reloadable

reloadable : reloadables) { Class reloadableClass = reloadable.getClass(); - try (SectionClosable startReload = section(sectionData, "start-reload-" + MoreObjects.firstNonNull(reloadableClass.getSimpleName(), reloadableClass.getName()))) { + try (SectionClosable startReload = section(sectionData, "start-reload-" + name(reloadableClass))) { reloadable.startReload(stage); } catch (Throwable throwable) { throwable.printStackTrace(); @@ -185,17 +214,17 @@ public class PluginManagerImpl

> implements PluginManager< List

plugins = new ArrayList<>(getPlugins().toList()); plugins.sort(Comparator.comparingDouble(P::getPriority).reversed()); - RoughlyEnoughItemsCore.LOGGER.info("Reloading Plugin Manager [%s] stage [%s], registered %d plugins: %s", pluginClass.getSimpleName(), stage.toString(), plugins.size(), CollectionUtils.mapAndJoinToString(plugins, REIPlugin::getPluginProviderName, ", ")); + RoughlyEnoughItemsCore.LOGGER.info("Reloading Plugin Manager [%s] stage [%s], registered %d plugins: %s", name(pluginClass), stage.toString(), plugins.size(), CollectionUtils.mapAndJoinToString(plugins, REIPlugin::getPluginProviderName, ", ")); Collections.reverse(plugins); for (Reloadable

reloadable : getReloadables()) { Class reloadableClass = reloadable.getClass(); - pluginSection(sectionData, "reloadable-plugin-" + MoreObjects.firstNonNull(reloadableClass.getSimpleName(), reloadableClass.getName()), plugins, plugin -> reloadable.acceptPlugin(plugin, stage)); + pluginSection(sectionData, "reloadable-plugin-" + name(reloadableClass), plugins, reloadable, plugin -> reloadable.acceptPlugin(plugin, stage)); } for (Reloadable

reloadable : reloadables) { Class reloadableClass = reloadable.getClass(); - try (SectionClosable endReload = section(sectionData, "end-reload-" + MoreObjects.firstNonNull(reloadableClass.getSimpleName(), reloadableClass.getName()))) { + try (SectionClosable endReload = section(sectionData, "end-reload-" + name(reloadableClass))) { reloadable.endReload(stage); } catch (Throwable throwable) { throwable.printStackTrace(); -- cgit From 1dcf535cdf25c808ee4c0827a27c5b0e50094fda Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 16 Oct 2021 00:59:29 +0800 Subject: Fix merge conflicts --- .../rei/impl/common/compat/FabricFluidAPISupportPlugin.java | 4 ++-- .../rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java | 7 ++++--- .../me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java | 8 ++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/fabric/src/main/java/me/shedaniel/rei/impl/common/compat/FabricFluidAPISupportPlugin.java b/fabric/src/main/java/me/shedaniel/rei/impl/common/compat/FabricFluidAPISupportPlugin.java index 01b5f2a47..8847874c1 100644 --- a/fabric/src/main/java/me/shedaniel/rei/impl/common/compat/FabricFluidAPISupportPlugin.java +++ b/fabric/src/main/java/me/shedaniel/rei/impl/common/compat/FabricFluidAPISupportPlugin.java @@ -50,8 +50,8 @@ public class FabricFluidAPISupportPlugin implements REIServerPlugin { List> result; try (Transaction transaction = Transaction.openOuter()) { result = StreamSupport.stream(storage.iterable(transaction).spliterator(), false) - .filter(view -> !view.isResourceBlank() && !view.getResource().isBlank()) - .map(view -> EntryStacks.of(FluidStack.create(view.getResource().getFluid(), Fraction.of(view.getAmount(), FluidConstants.BUCKET), view.getResource().getNbt()))) + .filter(view -> !view.isResourceBlank()) + .map(view -> EntryStacks.of(FluidStack.create(view.getResource().getFluid(), view.getAmount(), view.getResource().getNbt()))) .collect(Collectors.toList()); } if (!result.isEmpty()) { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java index 48aea3c1a..c9015efa3 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java @@ -24,7 +24,7 @@ package me.shedaniel.rei.impl.client.gui.screen; import com.google.common.collect.Lists; -import me.shedaniel.architectury.fluid.FluidStack; +import dev.architectury.fluid.FluidStack; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.gui.screen.DisplayScreen; import me.shedaniel.rei.api.client.gui.widgets.Slot; @@ -43,6 +43,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.chat.NarratorChatListener; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.screens.Screen; +import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.Tag; import net.minecraft.tags.TagCollection; @@ -179,10 +180,10 @@ public abstract class AbstractDisplayViewingScreen extends Screen implements Dis TagCollection collection; List objects; if (type == VanillaEntryTypes.ITEM) { - collection = tags.getItems(); + collection = tags.getOrEmpty(Registry.ITEM_REGISTRY); objects = CollectionUtils.map(widget.getEntries(), stack -> stack.castValue().getItem()); } else if (type == VanillaEntryTypes.FLUID) { - collection = tags.getFluids(); + collection = tags.getOrEmpty(Registry.FLUID_REGISTRY); objects = CollectionUtils.map(widget.getEntries(), stack -> stack.castValue().getFluid()); } else continue; Map.Entry> firstOrNull = CollectionUtils.findFirstOrNull(collection.getAllTags().entrySet(), entry -> entry.getValue().getValues().equals(objects)); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java index f3421e76e..5969aada1 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java @@ -26,10 +26,10 @@ package me.shedaniel.rei.impl.common.plugins; import com.google.common.base.Stopwatch; import com.google.common.collect.FluentIterable; import com.google.common.collect.Iterables; -import me.shedaniel.architectury.platform.Platform; -import me.shedaniel.architectury.utils.Env; -import me.shedaniel.architectury.utils.EnvExecutor; -import me.shedaniel.architectury.utils.GameInstance; +import dev.architectury.platform.Platform; +import dev.architectury.utils.Env; +import dev.architectury.utils.EnvExecutor; +import dev.architectury.utils.GameInstance; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.common.plugins.PluginManager; import me.shedaniel.rei.api.common.plugins.PluginView; -