From c80c345c4fa3def0536bcecbc2223f202af79415 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sun, 28 Mar 2021 01:44:38 +0800 Subject: Complete custom favorites Signed-off-by: shedaniel --- .../rei/api/client/favorites/FavoriteEntry.java | 17 +- .../api/client/favorites/FavoriteEntryType.java | 6 +- .../rei/api/client/gui/DisplayRenderer.java | 3 +- .../shedaniel/rei/api/common/entry/EntryStack.java | 39 ----- .../me/shedaniel/rei/impl/ClientInternals.java | 12 +- .../client/favorites/GameModeFavoriteEntry.java | 34 ++-- .../client/favorites/WeatherFavoriteEntry.java | 63 +++---- gradle.properties | 2 +- .../me/shedaniel/rei/RoughlyEnoughItemsCore.java | 105 +++++------- .../rei/impl/client/ClientHelperImpl.java | 8 +- .../rei/impl/client/config/ConfigManagerImpl.java | 182 +++++++++++++++------ .../impl/client/entry/filtering/FilteringRule.java | 8 +- .../entry/filtering/rules/ManualFilteringRule.java | 2 +- .../entry/filtering/rules/SearchFilteringRule.java | 2 +- .../entry/type/types/RenderingEntryDefinition.java | 3 +- .../favorites/FavoriteEntryTypeRegistryImpl.java | 3 +- .../impl/client/gui/ContainerScreenOverlay.java | 123 +++++++------- .../impl/client/gui/screen/TransformingScreen.java | 3 +- .../rei/impl/client/gui/widget/EntryWidget.java | 3 +- .../client/gui/widget/FavoritesListWidget.java | 82 ++++++---- .../entry/type/types/BuiltinEntryDefinition.java | 2 +- .../entry/type/types/EmptyEntryDefinition.java | 3 +- .../plugin/client/DefaultClientRuntimePlugin.java | 22 +-- .../plugin/client/entry/FluidEntryDefinition.java | 3 +- .../plugin/client/entry/ItemEntryDefinition.java | 3 +- 25 files changed, 397 insertions(+), 336 deletions(-) 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 da68b4d39..9ca3b960e 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 @@ -23,10 +23,10 @@ package me.shedaniel.rei.api.client.favorites; -import com.google.gson.JsonObject; import me.shedaniel.rei.api.client.gui.Renderer; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.impl.ClientInternals; +import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.Nullable; @@ -40,12 +40,12 @@ public abstract class FavoriteEntry { public static final String TYPE_KEY = "type"; private final UUID uuid = UUID.randomUUID(); - public static FavoriteEntry delegate(Supplier supplier, @Nullable Supplier toJson) { + public static FavoriteEntry delegate(Supplier supplier, @Nullable Supplier toJson) { return ClientInternals.delegateFavoriteEntry(supplier, toJson); } @Nullable - public static FavoriteEntry fromJson(JsonObject object) { + public static FavoriteEntry read(CompoundTag object) { return ClientInternals.favoriteEntryFromJson(object); } @@ -57,9 +57,9 @@ public abstract class FavoriteEntry { return entry == null || entry.isInvalid(); } - public JsonObject toJson(JsonObject object) { - object.addProperty(TYPE_KEY, getType().toString()); - return Objects.requireNonNull(Objects.requireNonNull(FavoriteEntryType.registry().get(getType())).toJson(this, object)); + public CompoundTag save(CompoundTag tag) { + tag.putString(TYPE_KEY, getType().toString()); + return Objects.requireNonNull(Objects.requireNonNull(FavoriteEntryType.registry().get(getType())).save(this, tag)); } public UUID getUuid() { @@ -94,7 +94,10 @@ public abstract class FavoriteEntry { @Override public int hashCode() { - return hashIgnoreAmount(); + int result = 1; + result = 31 * result + getType().hashCode(); + result = 31 * result + hashIgnoreAmount(); + return result; } public abstract boolean isSame(FavoriteEntry other); diff --git a/api/src/main/java/me/shedaniel/rei/api/client/favorites/FavoriteEntryType.java b/api/src/main/java/me/shedaniel/rei/api/client/favorites/FavoriteEntryType.java index c341581a9..b3e79bf4f 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/favorites/FavoriteEntryType.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/favorites/FavoriteEntryType.java @@ -23,11 +23,11 @@ package me.shedaniel.rei.api.client.favorites; -import com.google.gson.JsonObject; import me.shedaniel.rei.api.client.plugins.REIClientPlugin; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.plugins.PluginManager; import me.shedaniel.rei.api.common.registry.Reloadable; +import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.ApiStatus; @@ -45,11 +45,11 @@ public interface FavoriteEntryType { return PluginManager.getClientInstance().get(FavoriteEntryType.Registry.class); } - T fromJson(JsonObject object); + T read(CompoundTag object); T fromArgs(Object... args); - JsonObject toJson(T entry, JsonObject object); + CompoundTag save(T entry, CompoundTag tag); @ApiStatus.NonExtendable interface Registry extends Reloadable { diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/DisplayRenderer.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/DisplayRenderer.java index 29d3593bc..adfb9b087 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/DisplayRenderer.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/DisplayRenderer.java @@ -37,7 +37,8 @@ public abstract class DisplayRenderer extends AbstractRenderer { } @Override - public @Nullable Tooltip getTooltip(Point mouse) { + @Nullable + public Tooltip getTooltip(Point mouse) { return null; } } diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java index ce7201d51..cd3defe83 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java @@ -23,10 +23,6 @@ package me.shedaniel.rei.api.common.entry; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.mojang.serialization.Dynamic; -import com.mojang.serialization.JsonOps; import me.shedaniel.math.Point; import me.shedaniel.rei.api.client.config.ConfigObject; import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer; @@ -41,11 +37,8 @@ import me.shedaniel.rei.impl.Internals; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.NbtOps; -import net.minecraft.nbt.TagParser; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.GsonHelper; import net.minecraft.util.Unit; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; @@ -69,38 +62,6 @@ public interface EntryStack extends TextRepresentable, Renderer { return of(type.getDefinition(), value); } - @ApiStatus.Internal - static EntryStack readFromJson(JsonElement jsonElement) { - try { - JsonObject obj = jsonElement.getAsJsonObject(); - EntryType type = EntryType.deferred(new ResourceLocation(GsonHelper.getAsString(obj, "type"))); - EntrySerializer serializer = type.getDefinition().getSerializer(); - if (serializer != null && serializer.supportReading()) { - Object o = serializer.read(TagParser.parseTag(obj.toString())); - return EntryStack.of(type, o); - } - } catch (Exception e) { - e.printStackTrace(); - } - return EntryStack.empty(); - } - - @ApiStatus.Internal - @Nullable - default JsonElement toJson() { - try { - EntrySerializer serializer = getDefinition().getSerializer(); - if (serializer != null && serializer.supportSaving()) { - JsonObject object = Dynamic.convert(NbtOps.INSTANCE, JsonOps.INSTANCE, serializer.save(this, getValue())).getAsJsonObject(); - object.addProperty("type", getType().getId().toString()); - return object; - } - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - static EntryStack read(CompoundTag tag) { EntryDefinition definition = EntryTypeRegistry.getInstance().get(new ResourceLocation(tag.getString("type"))); EntrySerializer serializer = definition.getSerializer(); diff --git a/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java b/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java index 1daaa568d..50e512c49 100644 --- a/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java +++ b/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java @@ -23,7 +23,6 @@ package me.shedaniel.rei.impl; -import com.google.gson.JsonObject; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.ClientHelper; @@ -37,6 +36,7 @@ import me.shedaniel.rei.api.client.view.ViewSearchBuilder; import me.shedaniel.rei.api.common.plugins.PluginManager; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.FormattedText; import net.minecraft.resources.ResourceLocation; @@ -57,8 +57,8 @@ public final class ClientInternals { private static Supplier viewSearchBuilder = ClientInternals::throwNotSetup; private static Supplier> clientPluginManager = ClientInternals::throwNotSetup; private static Supplier> emptyEntryRenderer = ClientInternals::throwNotSetup; - private static BiFunction, Supplier, FavoriteEntry> delegateFavoriteEntry = (supplier, toJson) -> throwNotSetup(); - private static Function favoriteEntryFromJson = (object) -> throwNotSetup(); + private static BiFunction, Supplier, FavoriteEntry> delegateFavoriteEntry = (supplier, toJson) -> throwNotSetup(); + private static Function favoriteEntryFromJson = (object) -> throwNotSetup(); private static Function clickAreaHandlerResult = (result) -> throwNotSetup(); private static BiFunction<@Nullable Point, Collection, Tooltip> tooltipProvider = (point, texts) -> throwNotSetup(); private static Supplier> jeiCompatMods = ClientInternals::throwNotSetup; @@ -117,12 +117,12 @@ public final class ClientInternals { return tooltipProvider.apply(point, texts); } - public static FavoriteEntry delegateFavoriteEntry(Supplier supplier, Supplier toJoin) { + public static FavoriteEntry delegateFavoriteEntry(Supplier supplier, Supplier toJoin) { return delegateFavoriteEntry.apply(supplier, toJoin); } - public static FavoriteEntry favoriteEntryFromJson(JsonObject object) { - return favoriteEntryFromJson.apply(object); + public static FavoriteEntry favoriteEntryFromJson(CompoundTag tag) { + return favoriteEntryFromJson.apply(tag); } public static EntryRenderer getEmptyEntryRenderer() { diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/GameModeFavoriteEntry.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/GameModeFavoriteEntry.java index f9ab098e6..9be48eff1 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/GameModeFavoriteEntry.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/GameModeFavoriteEntry.java @@ -23,8 +23,8 @@ package me.shedaniel.rei.plugin.client.favorites; -import com.google.gson.JsonObject; import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.math.Vector4f; import me.shedaniel.clothconfig2.api.ScissorsHandler; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; @@ -44,11 +44,11 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.resources.sounds.SimpleSoundInstance; +import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvents; -import net.minecraft.util.GsonHelper; import net.minecraft.world.level.GameType; import org.jetbrains.annotations.Nullable; @@ -81,14 +81,18 @@ public class GameModeFavoriteEntry extends FavoriteEntry { @Override public void render(PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta) { int color = bounds.contains(mouseX, mouseY) ? 0xFFEEEEEE : 0xFFAAAAAA; - fillGradient(matrices, bounds.getX(), bounds.getY(), bounds.getMaxX(), bounds.getY() + 1, color, color); - fillGradient(matrices, bounds.getX(), bounds.getMaxY() - 1, bounds.getMaxX(), bounds.getMaxY(), color, color); - fillGradient(matrices, bounds.getX(), bounds.getY(), bounds.getX() + 1, bounds.getMaxY(), color, color); - fillGradient(matrices, bounds.getMaxX() - 1, bounds.getY(), bounds.getMaxX(), bounds.getMaxY(), color, color); +// fillGradient(matrices, bounds.getX(), bounds.getY(), bounds.getMaxX(), bounds.getY() + 1, color, color); +// fillGradient(matrices, bounds.getX(), bounds.getMaxY() - 1, bounds.getMaxX(), bounds.getMaxY(), color, color); +// fillGradient(matrices, bounds.getX(), bounds.getY(), bounds.getX() + 1, bounds.getMaxY(), color, color); +// fillGradient(matrices, bounds.getMaxX() - 1, bounds.getY(), bounds.getMaxX(), bounds.getMaxY(), color, color); if (bounds.width > 4 && bounds.height > 4) { if (gameMode == null) { updateAnimator(delta); - notSetScissorArea.setBounds(bounds.x + 2, bounds.y + 2, bounds.width - 4, bounds.height - 4); + Vector4f vector4f = new Vector4f(bounds.x + 2, bounds.y + 2, 0, 1.0F); + vector4f.transform(matrices.last().pose()); + Vector4f vector4f2 = new Vector4f(bounds.getMaxX() - 2, bounds.getMaxY() - 2, 0, 1.0F); + vector4f2.transform(matrices.last().pose()); + notSetScissorArea.setBounds((int) vector4f.x(), (int) vector4f.y(), (int) vector4f2.x() - (int) vector4f.x(), (int) vector4f2.y() - (int) vector4f.y()); ScissorsHandler.INSTANCE.scissor(notSetScissorArea); int offset = Math.round(notSetOffset.floatValue() * bounds.getHeight()); for (int i = 0; i <= 3; i++) { @@ -120,7 +124,7 @@ public class GameModeFavoriteEntry extends FavoriteEntry { private void renderGameModeText(PoseStack matrices, GameType type, int centerX, int centerY, int color) { Component s = new TranslatableComponent("text.rei.short_gamemode." + type.getName()); Font font = Minecraft.getInstance().font; - font.draw(matrices, s, centerX - font.width(s) / 2f + 1, centerY - 3.5f, color); + font.draw(matrices, s, centerX - font.width(s) / 2f + 0.5f, centerY - 3.5f, color); } @Override @@ -194,10 +198,10 @@ public class GameModeFavoriteEntry extends FavoriteEntry { public enum Type implements FavoriteEntryType { INSTANCE; - + @Override - public GameModeFavoriteEntry fromJson(JsonObject object) { - String stringValue = GsonHelper.getAsString(object, KEY); + public GameModeFavoriteEntry read(CompoundTag object) { + String stringValue = object.getString(KEY); GameType type = stringValue.equals("NOT_SET") ? null : GameType.valueOf(stringValue); return new GameModeFavoriteEntry(type); } @@ -206,11 +210,11 @@ public class GameModeFavoriteEntry extends FavoriteEntry { public GameModeFavoriteEntry fromArgs(Object... args) { return new GameModeFavoriteEntry((GameType) args[0]); } - + @Override - public JsonObject toJson(GameModeFavoriteEntry entry, JsonObject object) { - object.addProperty(KEY, entry.gameMode == null ? "NOT_SET" : entry.gameMode.name()); - return object; + public CompoundTag save(GameModeFavoriteEntry entry, CompoundTag tag) { + tag.putString(KEY, entry.gameMode == null ? "NOT_SET" : entry.gameMode.name()); + return tag; } } diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/WeatherFavoriteEntry.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/WeatherFavoriteEntry.java index 31b0db5fb..acd9e6a69 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/WeatherFavoriteEntry.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/WeatherFavoriteEntry.java @@ -23,10 +23,9 @@ package me.shedaniel.rei.plugin.client.favorites; -import com.google.gson.JsonObject; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.*; -import com.mojang.math.Matrix4f; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.math.Vector4f; +import me.shedaniel.clothconfig2.api.ScissorsHandler; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.REIHelper; @@ -42,13 +41,12 @@ import me.shedaniel.rei.api.common.util.CollectionUtils; import net.minecraft.Util; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.renderer.texture.TextureAtlas; import net.minecraft.client.resources.language.I18n; import net.minecraft.client.resources.sounds.SimpleSoundInstance; +import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvents; -import net.minecraft.util.GsonHelper; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; @@ -59,7 +57,7 @@ public class WeatherFavoriteEntry extends FavoriteEntry { public static final ResourceLocation ID = new ResourceLocation("roughlyenoughitems", "weather"); public static final String TRANSLATION_KEY = "favorite.section.weather"; private static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("roughlyenoughitems", "textures/gui/recipecontainer.png"); - public static final String KEY = "type"; + public static final String KEY = "weather"; @Nullable private final Weather weather; @@ -86,19 +84,27 @@ public class WeatherFavoriteEntry extends FavoriteEntry { if (weather == null) { matrices.pushPose(); updateAnimator(delta); - notSetScissorArea.setBounds(bounds.x, bounds.y, bounds.width, bounds.height); -// ScissorsHandler.INSTANCE.scissor(notSetScissorArea); + Vector4f vector4f = new Vector4f(bounds.x, bounds.y, 0, 1.0F); + vector4f.transform(matrices.last().pose()); + Vector4f vector4f2 = new Vector4f(bounds.getMaxX(), bounds.getMaxY(), 0, 1.0F); + vector4f2.transform(matrices.last().pose()); + notSetScissorArea.setBounds((int) vector4f.x(), (int) vector4f.y(), (int) vector4f2.x() - (int) vector4f.x(), (int) vector4f2.y() - (int) vector4f.y()); + ScissorsHandler.INSTANCE.scissor(notSetScissorArea); int offset = Math.round(notSetOffset.floatValue() * bounds.getHeight()); for (int i = 0; i <= 2; i++) { Weather type = Weather.byId(i); renderWeatherIcon(matrices, type, bounds.getCenterX(), bounds.getCenterY() + bounds.getHeight() * i - offset, color); } -// ScissorsHandler.INSTANCE.removeLastScissor(); + ScissorsHandler.INSTANCE.removeLastScissor(); matrices.popPose(); } else { renderWeatherIcon(matrices, weather, bounds.getCenterX(), bounds.getCenterY(), color); } } +// fillGradient(matrices, bounds.getX(), bounds.getY(), bounds.getMaxX(), bounds.getY() + 1, color, color); +// fillGradient(matrices, bounds.getX(), bounds.getMaxY() - 1, bounds.getMaxX(), bounds.getMaxY(), color, color); +// fillGradient(matrices, bounds.getX(), bounds.getY(), bounds.getX() + 1, bounds.getMaxY(), color, color); +// fillGradient(matrices, bounds.getMaxX() - 1, bounds.getY(), bounds.getMaxX(), bounds.getMaxY(), color, color); } private void updateAnimator(float delta) { @@ -118,28 +124,7 @@ public class WeatherFavoriteEntry extends FavoriteEntry { private void renderWeatherIcon(PoseStack matrices, Weather type, int centerX, int centerY, int color) { Minecraft.getInstance().getTextureManager().bind(CHEST_GUI_TEXTURE); - Minecraft.getInstance().getTextureManager().bind(TextureAtlas.LOCATION_BLOCKS); - RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); - Matrix4f matrix = matrices.last().pose(); - float j = centerX - 6.5f; - float i = j + 14; - float k = centerY - 6.5f; - float l = k + 14; - float m = getZ(); - float f = type.getId() * 14 / 256f; - float g = f + 14 / 256f; - float h = 14 / 256f; - float n = h + 14 / 256f; - - BufferBuilder bufferBuilder = Tesselator.getInstance().getBuilder(); - bufferBuilder.begin(7, DefaultVertexFormat.POSITION_TEX); - bufferBuilder.vertex(matrix, i, l, m).uv(f, n).endVertex(); - bufferBuilder.vertex(matrix, j, l, m).uv(g, n).endVertex(); - bufferBuilder.vertex(matrix, j, k, m).uv(g, h).endVertex(); - bufferBuilder.vertex(matrix, i, k, m).uv(f, h).endVertex(); - bufferBuilder.end(); - RenderSystem.enableAlphaTest(); - BufferUploader.end(bufferBuilder); + blit(matrices, centerX - 7, centerY - 7, type.getId() * 14, 14, 14, 14, 256, 256); } @Override @@ -211,10 +196,10 @@ public class WeatherFavoriteEntry extends FavoriteEntry { public enum Type implements FavoriteEntryType { INSTANCE; - + @Override - public WeatherFavoriteEntry fromJson(JsonObject object) { - String stringValue = GsonHelper.getAsString(object, KEY); + public WeatherFavoriteEntry read(CompoundTag object) { + String stringValue = object.getString(KEY); Weather type = stringValue.equals("NOT_SET") ? null : Weather.valueOf(stringValue); return new WeatherFavoriteEntry(type); } @@ -223,11 +208,11 @@ public class WeatherFavoriteEntry extends FavoriteEntry { public WeatherFavoriteEntry fromArgs(Object... args) { return new WeatherFavoriteEntry((Weather) args[0]); } - + @Override - public JsonObject toJson(WeatherFavoriteEntry entry, JsonObject object) { - object.addProperty(KEY, entry.weather == null ? "NOT_SET" : entry.weather.name()); - return object; + public CompoundTag save(WeatherFavoriteEntry entry, CompoundTag tag) { + tag.putString(KEY, entry.weather == null ? "NOT_SET" : entry.weather.name()); + return tag; } } diff --git a/gradle.properties b/gradle.properties index 50c282545..657fd1fcc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ supported_version=1.16.2/3/4/5 minecraft_version=1.16.5 forge_version=36.0.43 fabricloader_version=0.11.1 -cloth_config_version=4.11.14 +cloth_config_version=4.11.17 modmenu_version=1.16.7 fabric_api=0.30.0+1.16 architectury_version=1.9.136 diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index f82444644..3f7e762a7 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -24,15 +24,12 @@ package me.shedaniel.rei; import com.google.common.collect.Lists; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; import me.shedaniel.architectury.event.events.GuiEvent; import me.shedaniel.architectury.event.events.RecipeUpdateEvent; import me.shedaniel.architectury.event.events.client.ClientScreenInputEvent; import me.shedaniel.architectury.networking.NetworkManager; import me.shedaniel.architectury.platform.Platform; import me.shedaniel.architectury.utils.Env; -import me.shedaniel.architectury.utils.EnvExecutor; import me.shedaniel.math.Point; import me.shedaniel.rei.api.client.REIHelper; import me.shedaniel.rei.api.client.REIOverlay; @@ -102,10 +99,10 @@ import net.minecraft.client.gui.screens.recipebook.GhostRecipe; import net.minecraft.client.gui.screens.recipebook.RecipeBookComponent; import net.minecraft.client.gui.screens.recipebook.RecipeUpdateListener; import net.minecraft.client.resources.language.I18n; +import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextComponent; import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.GsonHelper; import net.minecraft.util.Unit; import net.minecraft.world.InteractionResult; import net.minecraft.world.inventory.CraftingMenu; @@ -147,18 +144,6 @@ public class RoughlyEnoughItemsCore { public static void attachCommonInternals() { CategoryIdentifierImpl.attach(); - Internals.attachInstanceSupplier(new PluginManagerImpl<>( - REIPlugin.class, - UnaryOperator.identity(), - new EntryTypeRegistryImpl(), - new RecipeManagerContextImpl<>(RecipeManagerContextImpl.supplier()), - new ItemComparatorRegistryImpl(), - new DisplaySerializerRegistryImpl(), - new FluidSupportProviderImpl()), "commonPluginManager"); - Internals.attachInstanceSupplier(new PluginManagerImpl<>( - REIServerPlugin.class, - view -> view.then(PluginView.getInstance()), - new MenuInfoRegistryImpl()), "serverPluginManager"); Internals.attachInstance((Function>) new Function>() { ResourceLocation RENDERING_ID = new ResourceLocation("rendering"); private Map> typeCache = new ConcurrentHashMap<>(); @@ -222,35 +207,33 @@ public class RoughlyEnoughItemsCore { if (Objects.equals(definition.getType().getId(), BuiltinEntryTypes.EMPTY_ID)) { return empty().cast(); } - + return new TypedEntryStack<>(definition, value); } }, Internals.EntryStackProvider.class); Internals.attachInstance(new NbtHasherProviderImpl(), Internals.NbtHasherProvider.class); Internals.attachInstance(EntryIngredientImpl.provide(), Internals.EntryIngredientProvider.class); + Internals.attachInstanceSupplier(new PluginManagerImpl<>( + REIPlugin.class, + UnaryOperator.identity(), + new EntryTypeRegistryImpl(), + new RecipeManagerContextImpl<>(RecipeManagerContextImpl.supplier()), + new ItemComparatorRegistryImpl(), + new DisplaySerializerRegistryImpl(), + new FluidSupportProviderImpl()), "commonPluginManager"); + Internals.attachInstanceSupplier(new PluginManagerImpl<>( + REIServerPlugin.class, + view -> view.then(PluginView.getInstance()), + new MenuInfoRegistryImpl()), "serverPluginManager"); } @Environment(EnvType.CLIENT) public static void attachClientInternals() { - ClientInternals.attachInstanceSupplier(new PluginManagerImpl<>( - REIClientPlugin.class, - view -> view.then(PluginView.getInstance()), - new ViewsImpl(), - new SearchProviderImpl(), - new ConfigManagerImpl(), - new CategoryRegistryImpl(), - new DisplayRegistryImpl(), - new ScreenRegistryImpl(), - new EntryRegistryImpl(), - new FavoriteEntryTypeRegistryImpl(), - new SubsetsRegistryImpl(), - new TransferHandlerRegistryImpl(), - new REIHelperImpl()), "clientPluginManager"); InternalWidgets.attach(); ClientInternals.attachInstance((Supplier>) () -> EmptyEntryDefinition.EmptyRenderer.INSTANCE, "emptyEntryRenderer"); - ClientInternals.attachInstance((BiFunction, Supplier, FavoriteEntry>) (supplier, toJson) -> new FavoriteEntry() { + ClientInternals.attachInstance((BiFunction, Supplier, FavoriteEntry>) (supplier, toJson) -> new FavoriteEntry() { FavoriteEntry value = null; - + @Override public FavoriteEntry getUnwrapped() { if (this.value == null) { @@ -258,7 +241,7 @@ public class RoughlyEnoughItemsCore { } return Objects.requireNonNull(value).getUnwrapped(); } - + @Override public UUID getUuid() { return getUnwrapped().getUuid(); @@ -302,58 +285,60 @@ public class RoughlyEnoughItemsCore { public ResourceLocation getType() { return getUnwrapped().getType(); } - + @Override - public JsonObject toJson(JsonObject to) { + public CompoundTag save(CompoundTag tag) { if (toJson == null) { - return getUnwrapped().toJson(to); - } - - JsonObject object = toJson.get(); - for (Map.Entry entry : object.entrySet()) { - to.add(entry.getKey(), entry.getValue()); + return getUnwrapped().save(tag); } - return to; - } + return tag.merge(toJson.get()); + } + @Override public boolean isSame(FavoriteEntry other) { return getUnwrapped().isSame(other.getUnwrapped()); } }, "delegateFavoriteEntry"); - ClientInternals.attachInstance((Function) (object) -> { - String type = GsonHelper.getAsString(object, FavoriteEntry.TYPE_KEY); - switch (type) { - case "stack": - case "item": - case "fluid": - case "empty": - return FavoriteEntry.fromEntryStack(EntryStack.readFromJson(object)); - default: - ResourceLocation id = new ResourceLocation(type); - return Objects.requireNonNull(Objects.requireNonNull(FavoriteEntryType.registry().get(id)).fromJson(object)); - } + ClientInternals.attachInstance((Function) (object) -> { + String type = object.getString(FavoriteEntry.TYPE_KEY); + ResourceLocation id = new ResourceLocation(type); + return Objects.requireNonNull(Objects.requireNonNull(FavoriteEntryType.registry().get(id)).read(object)); }, "favoriteEntryFromJson"); ClientInternals.attachInstance((BiFunction<@Nullable Point, Collection, Tooltip>) QueuedTooltip::create, "tooltipProvider"); ClientInternals.attachInstance((Function<@Nullable Boolean, ClickArea.Result>) successful -> new ClickArea.Result() { private List> categories = Lists.newArrayList(); - + @Override public ClickArea.Result category(CategoryIdentifier category) { this.categories.add(category); return this; } - + @Override public boolean isSuccessful() { return successful; } - + @Override public Stream> getCategories() { return categories.stream(); } }, "clickAreaHandlerResult"); + ClientInternals.attachInstanceSupplier(new PluginManagerImpl<>( + REIClientPlugin.class, + view -> view.then(PluginView.getInstance()), + new ViewsImpl(), + new SearchProviderImpl(), + new ConfigManagerImpl(), + new CategoryRegistryImpl(), + new DisplayRegistryImpl(), + new ScreenRegistryImpl(), + new EntryRegistryImpl(), + new FavoriteEntryTypeRegistryImpl(), + new SubsetsRegistryImpl(), + new TransferHandlerRegistryImpl(), + new REIHelperImpl()), "clientPluginManager"); } @ApiStatus.Internal @@ -479,7 +464,7 @@ public class RoughlyEnoughItemsCore { if (shouldReturn(screen)) return InteractionResult.PASS; resetFocused(screen); - if (REIHelper.getInstance().isOverlayVisible() && REIHelper.getInstance().getOverlay().get().mouseClicked(mouseX, mouseY, button)) { + if (REIHelper.getInstance().getOverlay().get().mouseClicked(mouseX, mouseY, button)) { if (button == 0) { screen.setDragging(true); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java index 64700c4cd..0c18217cb 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java @@ -330,7 +330,8 @@ public class ClientHelperImpl implements ClientHelper { } @Override - public @Nullable CategoryIdentifier getPreferredOpenedCategory() { + @Nullable + public CategoryIdentifier getPreferredOpenedCategory() { return this.preferredOpenedCategory; } @@ -414,9 +415,10 @@ public class ClientHelperImpl implements ClientHelper { this.preferredOpenedCategory = category; return this; } - + @Override - public @Nullable CategoryIdentifier getPreferredOpenedCategory() { + @Nullable + public CategoryIdentifier getPreferredOpenedCategory() { return this.preferredOpenedCategory; } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java index 4ce4c30f6..6a9feabe9 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java @@ -26,9 +26,9 @@ package me.shedaniel.rei.impl.client.config; import com.google.common.collect.Lists; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import com.google.gson.JsonElement; import com.mojang.blaze3d.platform.InputConstants; import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.math.Matrix4f; import me.shedaniel.architectury.hooks.ScreenHooks; import me.shedaniel.architectury.platform.Platform; @@ -42,7 +42,7 @@ import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.Jankson; import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.JsonNull; import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.JsonObject; import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.JsonPrimitive; -import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.api.SyntaxError; +import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.api.DeserializationException; import me.shedaniel.clothconfig2.api.ConfigEntryBuilder; import me.shedaniel.clothconfig2.api.Modifier; import me.shedaniel.clothconfig2.api.ModifierKeyCode; @@ -76,6 +76,7 @@ import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.resources.language.I18n; import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.Tag; import net.minecraft.nbt.TagParser; import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; @@ -99,60 +100,13 @@ import static me.shedaniel.autoconfig.util.Utils.setUnsafely; @ApiStatus.Internal @Environment(EnvType.CLIENT) public class ConfigManagerImpl implements ConfigManager { - private boolean craftableOnly; + private boolean craftableOnly = false; private final Gson gson = new GsonBuilder().create(); private ConfigObjectImpl object; public ConfigManagerImpl() { - this.craftableOnly = false; Jankson jankson = Jankson.builder().build(); - AutoConfig.register(ConfigObjectImpl.class, (definition, configClass) -> new JanksonConfigSerializer<>(definition, configClass, Jankson.builder().registerPrimitiveTypeAdapter(InputConstants.Key.class, it -> { - return it instanceof String ? InputConstants.getKey((String) it) : null; - }).registerSerializer(InputConstants.Key.class, (it, marshaller) -> new JsonPrimitive(it.getName())).registerTypeAdapter(ModifierKeyCode.class, o -> { - String code = ((JsonPrimitive) o.get("keyCode")).asString(); - if (code.endsWith(".unknown")) return ModifierKeyCode.unknown(); - InputConstants.Key keyCode = InputConstants.getKey(code); - Modifier modifier = Modifier.of(((Number) ((JsonPrimitive) o.get("modifier")).getValue()).shortValue()); - return ModifierKeyCode.of(keyCode, modifier); - }).registerSerializer(ModifierKeyCode.class, (keyCode, marshaller) -> { - JsonObject object = new JsonObject(); - object.put("keyCode", new JsonPrimitive(keyCode.getKeyCode().getName())); - object.put("modifier", new JsonPrimitive(keyCode.getModifier().getValue())); - return object; - }).registerSerializer(EntryStack.class, (stack, marshaller) -> { - try { - return jankson.load(gson.toJson(stack.toJson())); - } catch (SyntaxError syntaxError) { - syntaxError.printStackTrace(); - return JsonNull.INSTANCE; - } - }).registerPrimitiveTypeAdapter(EntryStack.class, it -> { - return it instanceof String ? EntryStack.readFromJson(gson.fromJson((String) it, JsonElement.class)) : null; - }).registerTypeAdapter(EntryStack.class, it -> { - return EntryStack.readFromJson(gson.fromJson(it.toString(), JsonElement.class)); - }).registerSerializer(FavoriteEntry.class, (favoriteEntry, marshaller) -> { - try { - return jankson.load(favoriteEntry.toJson(new com.google.gson.JsonObject()).toString()); - } catch (SyntaxError syntaxError) { - syntaxError.printStackTrace(); - return JsonNull.INSTANCE; - } - }).registerTypeAdapter(FavoriteEntry.class, it -> { - com.google.gson.JsonObject object = gson.fromJson(it.toString(), com.google.gson.JsonObject.class); - return FavoriteEntry.delegate(() -> FavoriteEntry.fromJson(object), () -> object); - }).registerPrimitiveTypeAdapter(FavoriteEntry.class, it -> { - com.google.gson.JsonObject object = gson.fromJson(it.toString(), com.google.gson.JsonObject.class); - return FavoriteEntry.delegate(() -> FavoriteEntry.fromJson(object), () -> object); - }).registerSerializer(FilteringRule.class, (rule, marshaller) -> { - return new JsonPrimitive(FilteringRule.toTag(rule, new CompoundTag()).toString()); - }).registerPrimitiveTypeAdapter(FilteringRule.class, it -> { - try { - return it instanceof String ? FilteringRule.fromTag(TagParser.parseTag((String) it)) : null; - } catch (Exception e) { - e.printStackTrace(); - return null; - } - }).build())); + AutoConfig.register(ConfigObjectImpl.class, (definition, configClass) -> new JanksonConfigSerializer<>(definition, configClass, buildJankson(Jankson.builder()))); GuiRegistry guiRegistry = AutoConfig.getGuiRegistry(ConfigObjectImpl.class); guiRegistry.registerPredicateProvider((i13n, field, config, defaults, guiProvider) -> { if (field.isAnnotationPresent(ConfigEntry.Gui.Excluded.class)) @@ -183,6 +137,127 @@ public class ConfigManagerImpl implements ConfigManager { RoughlyEnoughItemsCore.LOGGER.info("Config loaded."); } + private static Jankson buildJankson(Jankson.Builder builder) { + // InputConstants.Key + builder.registerSerializer(InputConstants.Key.class, (value, marshaller) -> { + return new JsonPrimitive(value.getName()); + }); + builder.registerDeserializer(String.class, InputConstants.Key.class, (value, marshaller) -> { + return InputConstants.getKey(value); + }); + + // ModifierKeyCode + builder.registerSerializer(ModifierKeyCode.class, (value, marshaller) -> { + JsonObject object = new JsonObject(); + object.put("keyCode", new JsonPrimitive(value.getKeyCode().getName())); + object.put("modifier", new JsonPrimitive(value.getModifier().getValue())); + return object; + }); + builder.registerDeserializer(JsonObject.class, ModifierKeyCode.class, (value, marshaller) -> { + String code = value.get(String.class, "keyCode"); + if (code.endsWith(".unknown")) { + return ModifierKeyCode.unknown(); + } else { + InputConstants.Key keyCode = InputConstants.getKey(code); + Modifier modifier = Modifier.of(value.getShort("modifier", (short) 0)); + return ModifierKeyCode.of(keyCode, modifier); + } + }); + + // Tag + builder.registerSerializer(Tag.class, (value, marshaller) -> { + return marshaller.serialize(value.toString()); + }); + builder.registerDeserializer(String.class, Tag.class, (value, marshaller) -> { + try { + return TagParser.parseTag(value); + } catch (CommandSyntaxException e) { + throw new DeserializationException(e); + } + }); + + // EntryStack + builder.registerSerializer(EntryStack.class, (stack, marshaller) -> { + try { + return marshaller.serialize(stack.save()); + } catch (Exception e) { + e.printStackTrace(); + return JsonNull.INSTANCE; + } + }); + builder.registerDeserializer(Tag.class, EntryStack.class, (value, marshaller) -> { + try { + return EntryStack.read((CompoundTag) value); + } catch (Exception e) { + e.printStackTrace(); + return EntryStack.empty(); + } + }); + builder.registerDeserializer(String.class, EntryStack.class, (value, marshaller) -> { + try { + return EntryStack.read(TagParser.parseTag(value)); + } catch (Exception e) { + e.printStackTrace(); + return EntryStack.empty(); + } + }); + + // FilteringRule + builder.registerSerializer(FilteringRule.class, (value, marshaller) -> { + try { + return marshaller.serialize(FilteringRule.save(value, new CompoundTag())); + } catch (Exception e) { + e.printStackTrace(); + return JsonNull.INSTANCE; + } + }); + builder.registerDeserializer(Tag.class, FilteringRule.class, (value, marshaller) -> { + try { + return FilteringRule.read((CompoundTag) value); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + }); + builder.registerDeserializer(String.class, FilteringRule.class, (value, marshaller) -> { + try { + return FilteringRule.read(TagParser.parseTag(value)); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + }); + + // FavoriteEntry + builder.registerSerializer(FavoriteEntry.class, (value, marshaller) -> { + try { + return marshaller.serialize(value.save(new CompoundTag())); + } catch (Exception e) { + e.printStackTrace(); + return JsonNull.INSTANCE; + } + }); + builder.registerDeserializer(Tag.class, FavoriteEntry.class, (value, marshaller) -> { + try { + return FavoriteEntry.delegate(() -> FavoriteEntry.read((CompoundTag) value), () -> (CompoundTag) value); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + }); + builder.registerDeserializer(String.class, FavoriteEntry.class, (value, marshaller) -> { + try { + CompoundTag tag = TagParser.parseTag(value); + return FavoriteEntry.delegate(() -> FavoriteEntry.read(tag), () -> tag); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + }); + + return builder.build(); + } + @Override public void startReload() { } @@ -193,8 +268,9 @@ public class ConfigManagerImpl implements ConfigManager { @Override public void saveConfig() { - if (getConfig().getFavoriteEntries() != null) + if (getConfig().getFavoriteEntries() != null) { getConfig().getFavoriteEntries().removeIf(Objects::isNull); + } if (getConfig().getFilteredStacks() != null) { getConfig().getFilteredStacks().removeIf(EntryStack::isEmpty); List> normalizedFilteredStacks = CollectionUtils.map(getConfig().getFilteredStacks(), EntryStack::normalize); @@ -204,11 +280,11 @@ public class ConfigManagerImpl implements ConfigManager { if (getConfig().getFilteringRules().stream().noneMatch(filteringRule -> filteringRule instanceof ManualFilteringRule)) { getConfig().getFilteringRules().add(new ManualFilteringRule()); } - AutoConfig.getConfigHolder(ConfigObjectImpl.class).save(); AutoConfig.getConfigHolder(ConfigObjectImpl.class).registerLoadListener((configHolder, configObject) -> { object = configObject; return InteractionResult.PASS; }); + AutoConfig.getConfigHolder(ConfigObjectImpl.class).save(); } @Override diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/FilteringRule.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/FilteringRule.java index a5098779a..dd8cd6340 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/FilteringRule.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/FilteringRule.java @@ -56,17 +56,17 @@ public interface FilteringRule> { return registry; } - static CompoundTag toTag(FilteringRule rule, CompoundTag tag) { + static CompoundTag save(FilteringRule rule, CompoundTag tag) { tag.putString("id", REGISTRY.getKey(rule).toString()); - tag.put("rule", rule.toTag(new CompoundTag())); + tag.put("rule", rule.save(new CompoundTag())); return tag; } - static FilteringRule fromTag(CompoundTag tag) { + static FilteringRule read(CompoundTag tag) { return REGISTRY.get(ResourceLocation.tryParse(tag.getString("id"))).createFromTag(tag.getCompound("rule")); } - CompoundTag toTag(CompoundTag tag); + CompoundTag save(CompoundTag tag); T createFromTag(CompoundTag tag); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/ManualFilteringRule.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/ManualFilteringRule.java index 5bcd19e2c..d5a2cfde3 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/ManualFilteringRule.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/ManualFilteringRule.java @@ -41,7 +41,7 @@ import java.util.stream.Collectors; public class ManualFilteringRule extends AbstractFilteringRule { @Override - public CompoundTag toTag(CompoundTag tag) { + public CompoundTag save(CompoundTag tag) { return tag; } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/SearchFilteringRule.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/SearchFilteringRule.java index 3113cc79c..eeb494cea 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/SearchFilteringRule.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/SearchFilteringRule.java @@ -65,7 +65,7 @@ public class SearchFilteringRule extends AbstractFilteringRule entry, Point mouse) { + @Nullable + public Tooltip getTooltip(EntryStack entry, Point mouse) { return entry.getValue().getTooltip(mouse); } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/favorites/FavoriteEntryTypeRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/favorites/FavoriteEntryTypeRegistryImpl.java index 759ff2ab9..41c308588 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/favorites/FavoriteEntryTypeRegistryImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/favorites/FavoriteEntryTypeRegistryImpl.java @@ -60,7 +60,8 @@ public class FavoriteEntryTypeRegistryImpl implements FavoriteEntryType.Registry } @Override - public @Nullable ResourceLocation getId(FavoriteEntryType type) { + @Nullable + public ResourceLocation getId(FavoriteEntryType type) { return this.registry.inverse().get(type); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ContainerScreenOverlay.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ContainerScreenOverlay.java index 68d9a7782..ef88474a0 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ContainerScreenOverlay.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ContainerScreenOverlay.java @@ -23,7 +23,6 @@ package me.shedaniel.rei.impl.client.gui; -import com.google.common.collect.AbstractIterator; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.collect.Sets; @@ -44,7 +43,10 @@ import me.shedaniel.rei.api.client.gui.config.SearchFieldLocation; import me.shedaniel.rei.api.client.gui.drag.DraggableStackProvider; import me.shedaniel.rei.api.client.gui.drag.DraggableStackVisitor; import me.shedaniel.rei.api.client.gui.drag.DraggingContext; -import me.shedaniel.rei.api.client.gui.widgets.*; +import me.shedaniel.rei.api.client.gui.widgets.Button; +import me.shedaniel.rei.api.client.gui.widgets.Tooltip; +import me.shedaniel.rei.api.client.gui.widgets.Widget; +import me.shedaniel.rei.api.client.gui.widgets.Widgets; import me.shedaniel.rei.api.client.registry.category.CategoryRegistry; import me.shedaniel.rei.api.client.registry.screen.ClickArea; import me.shedaniel.rei.api.client.registry.screen.OverlayDecider; @@ -70,7 +72,6 @@ import me.shedaniel.rei.impl.client.gui.widget.search.OverlaySearchField; 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.ContainerEventHandler; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; @@ -109,6 +110,7 @@ public class ContainerScreenOverlay extends REIOverlay { private Rectangle bounds; private Window window; private Button leftButton, rightButton; + private Widget configButton; private CurrentDraggingStack draggingStack = new CurrentDraggingStack(); @Nullable @@ -171,6 +173,7 @@ public class ContainerScreenOverlay extends REIOverlay { public void openMenu(UUID uuid, Menu menu) { openMenu(uuid, menu, point -> false, point -> true); } + public void openMenu(UUID uuid, Menu menu, Predicate or, Predicate and) { this.overlayMenu = new OverlayMenu(uuid, menu, Widgets.withTranslate(menu, 0, 0, 400), or, and); } @@ -255,51 +258,53 @@ public class ContainerScreenOverlay extends REIOverlay { .tooltipLine(new TranslatableComponent("text.rei.next_page")) .focusable(false)); } - + final Rectangle configButtonArea = getConfigButtonArea(); - Widget tmp; - widgets.add(tmp = InternalWidgets.wrapLateRenderable(InternalWidgets.concatWidgets( - Widgets.createButton(configButtonArea, NarratorChatListener.NO_TITLE) - .onClick(button -> { - if (Screen.hasShiftDown() || Screen.hasControlDown()) { - ClientHelper.getInstance().setCheating(!ClientHelper.getInstance().isCheating()); - return; - } - ConfigManager.getInstance().openConfigScreen(REIHelper.getInstance().getPreviousScreen()); - }) - .onRender((matrices, button) -> { - if (ClientHelper.getInstance().isCheating() && ClientHelperImpl.getInstance().hasOperatorPermission()) { - button.setTint(ClientHelperImpl.getInstance().hasPermissionToUsePackets() ? 721354752 : 1476440063); - } else { - button.removeTint(); - } - }) - .focusable(false) - .containsMousePredicate((button, point) -> button.getBounds().contains(point) && isNotInExclusionZones(point.x, point.y)) - .tooltipSupplier(button -> { - List tooltips = new ArrayList<>(); - tooltips.add(new TranslatableComponent("text.rei.config_tooltip")); - tooltips.add(new ImmutableTextComponent(" ")); - if (!ClientHelper.getInstance().isCheating()) - tooltips.add(new TranslatableComponent("text.rei.cheating_disabled")); - else if (!ClientHelperImpl.getInstance().hasOperatorPermission()) { - if (minecraft.gameMode.hasInfiniteItems()) - tooltips.add(new TranslatableComponent("text.rei.cheating_limited_creative_enabled")); - else tooltips.add(new TranslatableComponent("text.rei.cheating_enabled_no_perms")); - } else if (ClientHelperImpl.getInstance().hasPermissionToUsePackets()) - tooltips.add(new TranslatableComponent("text.rei.cheating_enabled")); - else - tooltips.add(new TranslatableComponent("text.rei.cheating_limited_enabled")); - return tooltips.toArray(new Component[0]); - }), - Widgets.createDrawableWidget((helper, matrices, mouseX, mouseY, delta) -> { - helper.setBlitOffset(helper.getBlitOffset() + 1); - Minecraft.getInstance().getTextureManager().bind(CHEST_GUI_TEXTURE); - helper.blit(matrices, configButtonArea.x + 3, configButtonArea.y + 3, 0, 0, 14, 14); - }) + widgets.add(configButton = InternalWidgets.wrapLateRenderable( + Widgets.withTranslate( + InternalWidgets.concatWidgets( + Widgets.createButton(configButtonArea, NarratorChatListener.NO_TITLE) + .onClick(button -> { + if (Screen.hasShiftDown() || Screen.hasControlDown()) { + ClientHelper.getInstance().setCheating(!ClientHelper.getInstance().isCheating()); + return; + } + ConfigManager.getInstance().openConfigScreen(REIHelper.getInstance().getPreviousScreen()); + }) + .onRender((matrices, button) -> { + if (ClientHelper.getInstance().isCheating() && ClientHelperImpl.getInstance().hasOperatorPermission()) { + button.setTint(ClientHelperImpl.getInstance().hasPermissionToUsePackets() ? 721354752 : 1476440063); + } else { + button.removeTint(); + } + }) + .focusable(false) + .containsMousePredicate((button, point) -> button.getBounds().contains(point) && isNotInExclusionZones(point.x, point.y)) + .tooltipSupplier(button -> { + List tooltips = new ArrayList<>(); + tooltips.add(new TranslatableComponent("text.rei.config_tooltip")); + tooltips.add(new ImmutableTextComponent(" ")); + if (!ClientHelper.getInstance().isCheating()) + tooltips.add(new TranslatableComponent("text.rei.cheating_disabled")); + else if (!ClientHelperImpl.getInstance().hasOperatorPermission()) { + if (minecraft.gameMode.hasInfiniteItems()) + tooltips.add(new TranslatableComponent("text.rei.cheating_limited_creative_enabled")); + else tooltips.add(new TranslatableComponent("text.rei.cheating_enabled_no_perms")); + } else if (ClientHelperImpl.getInstance().hasPermissionToUsePackets()) + tooltips.add(new TranslatableComponent("text.rei.cheating_enabled")); + else + tooltips.add(new TranslatableComponent("text.rei.cheating_limited_enabled")); + return tooltips.toArray(new Component[0]); + }), + Widgets.createDrawableWidget((helper, matrices, mouseX, mouseY, delta) -> { + helper.setBlitOffset(helper.getBlitOffset() + 1); + Minecraft.getInstance().getTextureManager().bind(CHEST_GUI_TEXTURE); + helper.blit(matrices, configButtonArea.x + 3, configButtonArea.y + 3, 0, 0, 14, 14); + }) + ), + 0, 0, 600 ) )); - tmp.setZ(600); if (ConfigObject.getInstance().doesShowUtilsButtons()) { widgets.add(Widgets.createButton(ConfigObject.getInstance().isLowerConfigButton() ? new Rectangle(ConfigObject.getInstance().isLeftHandSidePanel() ? window.getGuiScaledWidth() - 30 : 10, 10, 20, 20) : new Rectangle(ConfigObject.getInstance().isLeftHandSidePanel() ? window.getGuiScaledWidth() - 55 : 35, 10, 20, 20), NarratorChatListener.NO_TITLE) .onRender((matrices, button) -> { @@ -375,7 +380,7 @@ public class ContainerScreenOverlay extends REIOverlay { Rectangle area = getCraftableToggleArea(); ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer(); ItemStack icon = new ItemStack(Blocks.CRAFTING_TABLE); - this.widgets.add(tmp = InternalWidgets.wrapLateRenderable(InternalWidgets.concatWidgets( + this.widgets.add(Widgets.withTranslate(InternalWidgets.wrapLateRenderable(InternalWidgets.concatWidgets( Widgets.createButton(area, NarratorChatListener.NO_TITLE) .focusable(false) .onClick(button -> { @@ -392,8 +397,7 @@ public class ContainerScreenOverlay extends REIOverlay { itemRenderer.renderGuiItem(icon, (int) vector.x(), (int