aboutsummaryrefslogtreecommitdiff
path: root/runtime/src/main/java/me/shedaniel/rei/plugin
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2024-04-16 00:43:25 +0900
committershedaniel <daniel@shedaniel.me>2024-04-16 00:43:25 +0900
commit5b03bcea21701b4dd7b0ae40aec7f448fd3513f3 (patch)
treeb2082db7c8a52f6c1a77197a7b6fe4bb43914407 /runtime/src/main/java/me/shedaniel/rei/plugin
parenta01b505ffcdb3ab1c4cf8fcc3aeaaef06c517f82 (diff)
parent2af03ce523320bab4b4086f0661f80e466c14477 (diff)
downloadRoughlyEnoughItems-5b03bcea21701b4dd7b0ae40aec7f448fd3513f3.tar.gz
RoughlyEnoughItems-5b03bcea21701b4dd7b0ae40aec7f448fd3513f3.tar.bz2
RoughlyEnoughItems-5b03bcea21701b4dd7b0ae40aec7f448fd3513f3.zip
Merge remote-tracking branch 'origin/feature/9.2' into feature/11.1
# Conflicts: # default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java # gradle.properties # runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java # runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ConfigureCategoriesScreen.java # runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringAddRuleScreen.java # runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringCategoriesEntry.java # runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringEntry.java # runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringScreen.java # runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/NoFilteringCategoriesEntry.java # runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/NoFilteringEntry.java # runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/RecipeScreenTypeEntry.java # runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ReloadPluginsEntry.java # runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/SearchFilterSyntaxHighlightingEntry.java # runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/PerformanceScreen.java # runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/entry/PerformanceEntry.java # runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/UncertainDisplayViewingScreen.java # runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/generic/OptionEntriesScreen.java # runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/PanelWidget.java # runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/PaginatedEntryListWidget.java
Diffstat (limited to 'runtime/src/main/java/me/shedaniel/rei/plugin')
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java195
1 files changed, 187 insertions, 8 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java
index e4898a6be..9382fd6a7 100644
--- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java
+++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java
@@ -23,6 +23,7 @@
package me.shedaniel.rei.plugin.client.runtime;
+import com.google.common.base.Suppliers;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.serialization.DataResult;
@@ -36,13 +37,15 @@ import me.shedaniel.rei.api.client.favorites.FavoriteEntry;
import me.shedaniel.rei.api.client.favorites.FavoriteEntryType;
import me.shedaniel.rei.api.client.gui.AbstractRenderer;
import me.shedaniel.rei.api.client.gui.Renderer;
+import me.shedaniel.rei.api.client.gui.config.RecipeBorderType;
+import me.shedaniel.rei.api.client.gui.drag.component.DraggableComponent;
import me.shedaniel.rei.api.client.gui.drag.component.DraggableComponentProviderWidget;
import me.shedaniel.rei.api.client.gui.drag.component.DraggableComponentVisitorWidget;
-import me.shedaniel.rei.api.client.gui.widgets.Panel;
-import me.shedaniel.rei.api.client.gui.widgets.Tooltip;
-import me.shedaniel.rei.api.client.gui.widgets.TooltipContext;
-import me.shedaniel.rei.api.client.gui.widgets.Widgets;
+import me.shedaniel.rei.api.client.gui.screen.DisplayScreen;
+import me.shedaniel.rei.api.client.gui.widgets.*;
import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
+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.entry.EntryRegistry;
import me.shedaniel.rei.api.client.registry.screen.ExclusionZones;
@@ -50,24 +53,35 @@ import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry;
import me.shedaniel.rei.api.client.registry.transfer.TransferHandlerRegistry;
import me.shedaniel.rei.api.client.search.method.InputMethodRegistry;
import me.shedaniel.rei.api.client.util.ClientEntryStacks;
+import me.shedaniel.rei.api.common.category.CategoryIdentifier;
+import me.shedaniel.rei.api.common.display.Display;
+import me.shedaniel.rei.api.common.display.DisplaySerializerRegistry;
+import me.shedaniel.rei.api.common.entry.EntryIngredient;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.plugins.PluginManager;
import me.shedaniel.rei.api.common.plugins.REIPlugin;
import me.shedaniel.rei.api.common.registry.Reloadable;
+import me.shedaniel.rei.api.common.util.CollectionUtils;
import me.shedaniel.rei.api.common.util.EntryStacks;
import me.shedaniel.rei.impl.client.ClientHelperImpl;
import me.shedaniel.rei.impl.client.REIRuntimeImpl;
import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl;
import me.shedaniel.rei.impl.client.gui.screen.DefaultDisplayViewingScreen;
+import me.shedaniel.rei.impl.client.gui.widget.AutoCraftingEvaluator;
+import me.shedaniel.rei.impl.client.gui.widget.DisplayCompositeWidget;
+import me.shedaniel.rei.impl.client.gui.widget.DisplayTooltipComponent;
import me.shedaniel.rei.impl.client.gui.widget.favorites.FavoritesListWidget;
import me.shedaniel.rei.impl.client.search.method.DefaultInputMethod;
import me.shedaniel.rei.impl.client.search.method.unihan.*;
+import me.shedaniel.rei.impl.common.InternalLogger;
import me.shedaniel.rei.impl.common.entry.type.EntryRegistryImpl;
import me.shedaniel.rei.impl.common.entry.type.EntryRegistryListener;
import me.shedaniel.rei.impl.common.util.HNEntryStackWrapper;
import me.shedaniel.rei.plugin.autocrafting.DefaultCategoryHandler;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
+import net.minecraft.ChatFormatting;
+import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
@@ -75,9 +89,9 @@ import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
-import java.util.Collections;
-import java.util.List;
+import java.util.*;
import java.util.function.Function;
+import java.util.function.Supplier;
@Environment(EnvType.CLIENT)
@ApiStatus.Internal
@@ -101,7 +115,7 @@ public class DefaultClientRuntimePlugin implements REIClientPlugin {
public void registerEntries(EntryRegistry registry) {
if (ClientHelperImpl.getInstance().isAprilFools.get()) {
registry.addEntry(ClientEntryStacks.of(new AbstractRenderer() {
- private ResourceLocation id = new ResourceLocation("roughlyenoughitems", "textures/gui/kirb.png");
+ private final ResourceLocation id = new ResourceLocation("roughlyenoughitems", "textures/gui/kirb.png");
@Override
public void render(PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta) {
@@ -162,6 +176,7 @@ public class DefaultClientRuntimePlugin implements REIClientPlugin {
@Override
public void registerFavorites(FavoriteEntryType.Registry registry) {
registry.register(EntryStackFavoriteType.INSTANCE.id, EntryStackFavoriteType.INSTANCE);
+ registry.register(DisplayFavoriteType.INSTANCE.id, DisplayFavoriteType.INSTANCE);
}
@Override
@@ -183,7 +198,7 @@ public class DefaultClientRuntimePlugin implements REIClientPlugin {
INSTANCE(FavoriteEntryType.ENTRY_STACK);
private final String key = "data";
- private ResourceLocation id;
+ private final ResourceLocation id;
EntryStackFavoriteType(ResourceLocation id) {
this.id = id;
@@ -263,4 +278,168 @@ public class DefaultClientRuntimePlugin implements REIClientPlugin {
return EntryStacks.equalsExact(stack, that.stack);
}
}
+
+ private enum DisplayFavoriteType implements FavoriteEntryType<DisplayFavoriteEntry> {
+ INSTANCE(FavoriteEntryType.DISPLAY);
+
+ private final String key = "data";
+ private final ResourceLocation id;
+
+ DisplayFavoriteType(ResourceLocation id) {
+ this.id = id;
+ }
+
+ @Override
+ public DataResult<DisplayFavoriteEntry> read(CompoundTag object) {
+ try {
+ if (object.contains("Data")) {
+ Display display = DisplaySerializerRegistry.getInstance().read(CategoryIdentifier.of(object.getString("CategoryID")), object.getCompound("Data"));
+ return DataResult.success(new DisplayFavoriteEntry(display, UUID.fromString(object.getString("UUID"))), Lifecycle.stable());
+ } else {
+ return DataResult.success(new DisplayFavoriteEntry(null, UUID.fromString(object.getString("UUID"))), Lifecycle.stable());
+ }
+ } catch (Throwable throwable) {
+ return DataResult.error(throwable.getMessage());
+ }
+ }
+
+ @Override
+ public DataResult<DisplayFavoriteEntry> fromArgs(Object... args) {
+ if (args.length == 0) return DataResult.error("Cannot create DisplayFavoriteEntry from empty args!");
+ if (!(args[0] instanceof Display display))
+ return DataResult.error("Creation of DisplayFavoriteEntry from args expected Display as the first argument!");
+ return DataResult.success(new DisplayFavoriteEntry(display, UUID.randomUUID()), Lifecycle.stable());
+ }
+
+ @Override
+ public CompoundTag save(DisplayFavoriteEntry entry, CompoundTag tag) {
+ boolean hasSerializer = DisplaySerializerRegistry.getInstance().hasSerializer(entry.display.getCategoryIdentifier());
+ tag.putString("CategoryID", entry.display.getCategoryIdentifier().toString());
+ tag.putString("UUID", entry.uuid.toString());
+
+ if (hasSerializer) {
+ try {
+ tag.put("Data", DisplaySerializerRegistry.getInstance().save(entry.display, new CompoundTag()));
+ } catch (Exception e) {
+ InternalLogger.getInstance().warn("Failed to save display favorite entry", e);
+ }
+ }
+
+ return tag;
+ }
+ }
+
+ private static class DisplayFavoriteEntry extends FavoriteEntry {
+ private static final Function<EntryStack<?>, String> CANCEL_FLUID_AMOUNT = s -> null;
+ private final Supplier<DisplayTooltipComponent> tooltipComponent;
+ private final Display display;
+ private final UUID uuid;
+ private final long hash;
+
+ public DisplayFavoriteEntry(Display display, UUID uuid) {
+ this.display = display;
+ this.uuid = uuid;
+ this.hash = uuid.hashCode();
+ this.tooltipComponent = Suppliers.memoize(() -> new DisplayTooltipComponent(display));
+ }
+
+ @Override
+ public UUID getUuid() {
+ return uuid;
+ }
+
+ @Override
+ public boolean isInvalid() {
+ return this.display == null;
+ }
+
+ @Override
+ public Renderer getRenderer(boolean showcase) {
+ Panel panel = Widgets.createRecipeBase(new Rectangle(0, 0, 18, 18))
+ .yTextureOffset(RecipeBorderType.LIGHTER.getYOffset());
+ Slot slot = Widgets.createSlot(new Rectangle())
+ .disableBackground()
+ .disableHighlight()
+ .disableTooltips();
+ for (EntryIngredient ingredient : display.getOutputEntries()) {
+ slot.entries(ingredient);
+ }
+ return new AbstractRenderer() {
+ @Override
+ public void render(PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta) {
+ matrices.pushPose();
+ matrices.translate(bounds.getX(), bounds.getY(), 1);
+ matrices.scale(bounds.width / (float) panel.getBounds().getWidth(), bounds.height / (float) panel.getBounds().getHeight(), 1);
+ panel.render(matrices, mouseX, mouseY, delta);
+ matrices.popPose();
+ if (bounds.width > 4 && bounds.height > 4) {
+ matrices.pushPose();
+ matrices.translate(0, 0.5, 0);
+ slot.getBounds().setBounds(bounds.x + 2, bounds.y + 2, bounds.width - 4, bounds.height - 4);
+ slot.render(matrices, mouseX, mouseY, delta);
+ matrices.popPose();
+ }
+ }
+
+ @Override
+ @Nullable
+ public Tooltip getTooltip(TooltipContext context) {
+ Tooltip tooltip = Tooltip.create(context.getPoint());
+ tooltip.add(tooltipComponent.get());
+ tooltip.add(Component.translatable("text.auto_craft.move_items.tooltip").withStyle(ChatFormatting.YELLOW));
+ return tooltip;
+ }
+ };
+ }
+
+ @Override
+ public boolean doAction(int button) {
+ Widgets.produceClickSound();
+
+ if (!(Minecraft.getInstance().screen instanceof DisplayScreen) && Screen.hasControlDown()) {
+ AutoCraftingEvaluator.evaluateAutoCrafting(true, Screen.hasShiftDown(), display, Collections::emptyList);
+ return true;
+ }
+
+ ClientHelperImpl.getInstance()
+ .openDisplayViewingScreen(Map.of(CategoryRegistry.getInstance().get(display.getCategoryIdentifier()).getCategory(), List.of(display)),
+ null, List.of(), List.of());
+ return true;
+ }
+
+ @Override
+ public long hashIgnoreAmount() {
+ return hash;
+ }
+
+ @Override
+ public FavoriteEntry copy() {
+ return new DisplayFavoriteEntry(this.display, this.uuid);
+ }
+
+ @Override
+ public ResourceLocation getType() {
+ return DisplayFavoriteType.INSTANCE.id;
+ }
+
+ @Override
+ public boolean isSame(FavoriteEntry other) {
+ if (!(other instanceof DisplayFavoriteEntry that)) return false;
+ return Objects.equals(this.uuid, that.uuid);
+ }
+
+ @Override
+ @Nullable
+ public DraggableComponent<?> asDraggableComponent(Slot slot) {
+ CategoryRegistry.CategoryConfiguration<Display> configuration = CategoryRegistry.getInstance().get((CategoryIdentifier<Display>) display.getCategoryIdentifier());
+ DisplayCategory<Display> category = configuration.getCategory();
+ Rectangle displayBounds = new Rectangle(0, 0, category.getDisplayWidth(display), category.getDisplayHeight());
+ List<Widget> widgets = configuration.getView(display).setupDisplay(display, displayBounds);
+ DisplayCompositeWidget.DisplayDraggableComponent component = new DisplayCompositeWidget.DisplayDraggableComponent(
+ Widgets.concat(CollectionUtils.filterToList(widgets, w -> !(w instanceof Panel))),
+ display, slot.getInnerBounds(), displayBounds);
+ component.onFavoritesRegion = true;
+ return component;
+ }
+ }
}