aboutsummaryrefslogtreecommitdiff
path: root/api/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'api/src/main/java')
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/REIRuntime.java8
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/entry/region/RegionEntry.java61
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/favorites/FavoriteEntry.java26
3 files changed, 92 insertions, 3 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/REIRuntime.java b/api/src/main/java/me/shedaniel/rei/api/client/REIRuntime.java
index 354c1ce19..adc1cb968 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/REIRuntime.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/REIRuntime.java
@@ -54,10 +54,14 @@ public interface REIRuntime extends Reloadable<REIClientPlugin> {
void toggleOverlayVisible();
default Optional<ScreenOverlay> getOverlay() {
- return getOverlay(false);
+ return getOverlay(false, false);
}
- Optional<ScreenOverlay> getOverlay(boolean reset);
+ default Optional<ScreenOverlay> getOverlay(boolean reset) {
+ return getOverlay(reset, true);
+ }
+
+ Optional<ScreenOverlay> getOverlay(boolean reset, boolean init);
@Nullable
AbstractContainerScreen<?> getPreviousContainerScreen();
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/entry/region/RegionEntry.java b/api/src/main/java/me/shedaniel/rei/api/client/entry/region/RegionEntry.java
new file mode 100644
index 000000000..c36a9444b
--- /dev/null
+++ b/api/src/main/java/me/shedaniel/rei/api/client/entry/region/RegionEntry.java
@@ -0,0 +1,61 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021 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.api.client.entry.region;
+
+import me.shedaniel.rei.api.client.favorites.FavoriteEntry;
+import me.shedaniel.rei.api.client.favorites.FavoriteMenuEntry;
+import me.shedaniel.rei.api.common.entry.EntryStack;
+import org.jetbrains.annotations.ApiStatus;
+
+import java.util.Collection;
+import java.util.Optional;
+import java.util.UUID;
+import java.util.function.Supplier;
+
+@ApiStatus.Experimental
+@ApiStatus.Internal
+public interface RegionEntry<T extends RegionEntry<T>> {
+ EntryStack<?> toStack();
+
+ T copy();
+
+ default FavoriteEntry asFavorite() {
+ FavoriteEntry entry = FavoriteEntry.fromEntryStack(copy().toStack().normalize());
+ return entry.isInvalid() ? null : entry;
+ }
+
+ default boolean isEntryInvalid() {
+ return false;
+ }
+
+ default Optional<Supplier<Collection<FavoriteMenuEntry>>> getMenuEntries() {
+ return Optional.empty();
+ }
+
+ UUID getUuid();
+
+ default boolean doAction(int button) {
+ return false;
+ }
+}
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/favorites/FavoriteEntry.java b/api/src/main/java/me/shedaniel/rei/api/client/favorites/FavoriteEntry.java
index dc50639b7..5add3f4a0 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/favorites/FavoriteEntry.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/favorites/FavoriteEntry.java
@@ -25,13 +25,16 @@ package me.shedaniel.rei.api.client.favorites;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.Lifecycle;
+import me.shedaniel.rei.api.client.entry.region.RegionEntry;
import me.shedaniel.rei.api.client.gui.Renderer;
+import me.shedaniel.rei.api.client.util.ClientEntryStacks;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.impl.ClientInternals;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
+import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
@@ -41,7 +44,7 @@ import java.util.UUID;
import java.util.function.Supplier;
@Environment(EnvType.CLIENT)
-public abstract class FavoriteEntry {
+public abstract class FavoriteEntry implements RegionEntry<FavoriteEntry> {
public static final String TYPE_KEY = "type";
private final UUID uuid = UUID.randomUUID();
@@ -71,15 +74,23 @@ public abstract class FavoriteEntry {
return delegateResult(() -> FavoriteEntryType.registry().get(FavoriteEntryType.ENTRY_STACK).fromArgsResult(stack), null);
}
+ @ApiStatus.ScheduledForRemoval
+ @Deprecated
public static boolean isEntryInvalid(@Nullable FavoriteEntry entry) {
return entry == null || entry.isInvalid();
}
+ @Override
+ public boolean isEntryInvalid() {
+ return isInvalid();
+ }
+
public CompoundTag save(CompoundTag tag) {
tag.putString(TYPE_KEY, getType().toString());
return Objects.requireNonNull(Objects.requireNonNull(FavoriteEntryType.registry().get(getType())).save(this, tag));
}
+ @Override
public UUID getUuid() {
return uuid;
}
@@ -88,14 +99,17 @@ public abstract class FavoriteEntry {
public abstract Renderer getRenderer(boolean showcase);
+ @Override
public abstract boolean doAction(int button);
+ @Override
public Optional<Supplier<Collection<FavoriteMenuEntry>>> getMenuEntries() {
return Optional.empty();
}
public abstract long hashIgnoreAmount();
+ @Override
public abstract FavoriteEntry copy();
public abstract ResourceLocation getType();
@@ -128,4 +142,14 @@ public abstract class FavoriteEntry {
public FavoriteEntry getUnwrapped() {
return this;
}
+
+ @Override
+ public EntryStack<?> toStack() {
+ return ClientEntryStacks.of(getRenderer(false));
+ }
+
+ @Override
+ public FavoriteEntry asFavorite() {
+ return copy();
+ }
}