From 05069aa62b09f02a8cd6e526ec58a30347a56500 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Wed, 27 Jul 2022 23:25:27 +0800 Subject: WIP Module --- .../categories/.gradle/loom-cache/launch.cfg | 14 ++ .../categories/.gradle/loom-cache/log4j.xml | 63 +++++++ .../.gradle/loom-cache/remapClasspath.txt | 1 + .../CategoryRegistryImpl$Configuration.class | Bin 0 -> 7035 bytes .../registry/category/CategoryRegistryImpl.class | Bin 0 -> 10847 bytes .../CategoryIdentifierConstructorImpl.class | Bin 0 -> 1958 bytes .../common/category/CategoryIdentifierImpl.class | Bin 0 -> 2182 bytes .../libs/categories-transformProductionFabric.jar | Bin 0 -> 166 bytes .../libs/categories-transformProductionForge.jar | Bin 0 -> 166 bytes ...i.api.client.registry.category.CategoryRegistry | 1 + ...ei.impl.Internals.CategoryIdentifierConstructor | 1 + .../CategoryIdentifierConstructorImpl.java | 22 +++ .../registry/category/CategoryRegistryImpl.java | 201 +++++++++++++++++++++ .../CategoryIdentifierConstructorImpl.java | 45 +++++ .../common/category/CategoryIdentifierImpl.java | 67 +++++++ ...i.api.client.registry.category.CategoryRegistry | 1 + ...ei.impl.Internals.CategoryIdentifierConstructor | 1 + 17 files changed, 417 insertions(+) create mode 100644 runtime-engine/categories/.gradle/loom-cache/launch.cfg create mode 100644 runtime-engine/categories/.gradle/loom-cache/log4j.xml create mode 100644 runtime-engine/categories/.gradle/loom-cache/remapClasspath.txt create mode 100644 runtime-engine/categories/build/classes/java/main/me/shedaniel/rei/impl/client/registry/category/CategoryRegistryImpl$Configuration.class create mode 100644 runtime-engine/categories/build/classes/java/main/me/shedaniel/rei/impl/client/registry/category/CategoryRegistryImpl.class create mode 100644 runtime-engine/categories/build/classes/java/main/me/shedaniel/rei/impl/common/category/CategoryIdentifierConstructorImpl.class create mode 100644 runtime-engine/categories/build/classes/java/main/me/shedaniel/rei/impl/common/category/CategoryIdentifierImpl.class create mode 100644 runtime-engine/categories/build/libs/categories-transformProductionFabric.jar create mode 100644 runtime-engine/categories/build/libs/categories-transformProductionForge.jar create mode 100644 runtime-engine/categories/build/resources/main/META-INF/services/me.shedaniel.rei.api.client.registry.category.CategoryRegistry create mode 100644 runtime-engine/categories/build/resources/main/META-INF/services/me.shedaniel.rei.impl.Internals.CategoryIdentifierConstructor create mode 100644 runtime-engine/categories/build/tmp/updateLicenseMain/original/me/shedaniel/rei/impl/common/category/CategoryIdentifierConstructorImpl.java create mode 100644 runtime-engine/categories/src/main/java/me/shedaniel/rei/impl/client/registry/category/CategoryRegistryImpl.java create mode 100644 runtime-engine/categories/src/main/java/me/shedaniel/rei/impl/common/category/CategoryIdentifierConstructorImpl.java create mode 100644 runtime-engine/categories/src/main/java/me/shedaniel/rei/impl/common/category/CategoryIdentifierImpl.java create mode 100644 runtime-engine/categories/src/main/resources/META-INF/services/me.shedaniel.rei.api.client.registry.category.CategoryRegistry create mode 100644 runtime-engine/categories/src/main/resources/META-INF/services/me.shedaniel.rei.impl.Internals.CategoryIdentifierConstructor (limited to 'runtime-engine/categories') diff --git a/runtime-engine/categories/.gradle/loom-cache/launch.cfg b/runtime-engine/categories/.gradle/loom-cache/launch.cfg new file mode 100644 index 000000000..983de0279 --- /dev/null +++ b/runtime-engine/categories/.gradle/loom-cache/launch.cfg @@ -0,0 +1,14 @@ +commonProperties + fabric.development=true + fabric.remapClasspathFile=/home/shedaniel/Documents/JavaCoding/RoughlyEnoughItems-117/runtime-engine/categories/.gradle/loom-cache/remapClasspath.txt + log4j.configurationFile=/home/shedaniel/Documents/JavaCoding/RoughlyEnoughItems-117/runtime-engine/categories/.gradle/loom-cache/log4j.xml + log4j2.formatMsgNoLookups=true + fabric.log.disableAnsi=false +clientArgs + --assetIndex + 1.18.2-1.18 + --assetsDir + /home/shedaniel/.gradle/caches/fabric-loom/assets +clientProperties + java.library.path=/home/shedaniel/Documents/JavaCoding/RoughlyEnoughItems-117/.gradle/loom-cache/natives/1.18.2 + org.lwjgl.librarypath=/home/shedaniel/Documents/JavaCoding/RoughlyEnoughItems-117/.gradle/loom-cache/natives/1.18.2 \ No newline at end of file diff --git a/runtime-engine/categories/.gradle/loom-cache/log4j.xml b/runtime-engine/categories/.gradle/loom-cache/log4j.xml new file mode 100644 index 000000000..c009f9fb4 --- /dev/null +++ b/runtime-engine/categories/.gradle/loom-cache/log4j.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/runtime-engine/categories/.gradle/loom-cache/remapClasspath.txt b/runtime-engine/categories/.gradle/loom-cache/remapClasspath.txt new file mode 100644 index 000000000..01f75adc1 --- /dev/null +++ b/runtime-engine/categories/.gradle/loom-cache/remapClasspath.txt @@ -0,0 +1 @@ +/home/shedaniel/.gradle/caches/modules-2/files-2.1/net.fabricmc/tiny-mappings-parser/0.3.0+build.17/2f10540a290e382a7cd35c16ec3900046a4e252/tiny-mappings-parser-0.3.0+build.17.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/net.fabricmc/sponge-mixin/0.11.2+mixin.0.8.5/f4ae569d559b5e3244b67321945261d83ff7ad8e/sponge-mixin-0.11.2+mixin.0.8.5.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/net.fabricmc/tiny-remapper/0.8.1/d220c092cd1446d5f2668b53e71abe23a12cb8cf/tiny-remapper-0.8.1.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/net.fabricmc/access-widener/2.1.0/f62a27adbfd8ab4d4fa5681793039f2c0b177155/access-widener-2.1.0.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm/9.2/81a03f76019c67362299c40e0ba13405f5467bff/asm-9.2.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-analysis/9.2/7487dd756daf96cab9986e44b9d7bcb796a61c10/asm-analysis-9.2.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-commons/9.2/f4d7f0fc9054386f2893b602454d48e07d4fbead/asm-commons-9.2.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-tree/9.2/d96c99a30f5e1a19b0e609dbb19a44d8518ac01e/asm-tree-9.2.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-util/9.2/fbc178fc5ba3dab50fd7e8a5317b8b647c8e8946/asm-util-9.2.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/com.mojang/blocklist/1.0.10/5c685c5ffa94c4cd39496c7184c1d122e515ecef/blocklist-1.0.10.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/com.mojang/patchy/2.2.10/da05971b07cbb379d002cf7eaec6a2048211fefc/patchy-2.2.10.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/com.ibm.icu/icu4j/70.1/dfa3a1fbc55bf5db8c6e79fc0935ac7ab1202950/icu4j-70.1.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/commons-codec/commons-codec/1.15/49d94806b6e3dc933dacbd8acb0fdbab8ebd1e5d/commons-codec-1.15.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-compress/1.21/4ec95b60d4e86b5c95a0e919cb172a0af98011ef/commons-compress-1.21.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpclient/4.5.13/e5f6cae5ca7ecaac1ec2827a9e2d65ae2869cada/httpclient-4.5.13.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/commons-logging/commons-logging/1.2/4bfc12adfe4842bf07b657f0369c4cb522955686/commons-logging-1.2.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.4.14/9dd1a631c082d92ecd4bd8fd4cf55026c720a8c1/httpcore-4.4.14.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl/3.2.2/8ad6294407e15780b43e84929c40e4c5e997972e/lwjgl-3.2.2.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-jemalloc/3.2.2/ee8e57a79300f78294576d87c4a587f8c99402e2/lwjgl-jemalloc-3.2.2.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-openal/3.2.2/2b772a102b0a11ee5f2109a5b136f4dc7c630827/lwjgl-openal-3.2.2.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-opengl/3.2.2/6ac5bb88b44c43ea195a570aab059f63da004cd8/lwjgl-opengl-3.2.2.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-glfw/3.2.2/d3ad4df38e400b8afba1de63f84338809399df5b/lwjgl-glfw-3.2.2.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-stb/3.2.2/3b8e6ebc5851dd3d17e37e5cadce2eff2a429f0f/lwjgl-stb-3.2.2.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-tinyfd/3.2.2/fcbe606c8f8da6f8f9a05e2c540eb1ee8632b0e9/lwjgl-tinyfd-3.2.2.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/com.mojang/text2speech/1.12.4/1f618f522dbdd93218c270bcfd8f8dd84be31717/text2speech-1.12.4.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/com.mojang/logging/1.0.0/f6ca3b2eee0b80b384e8ed93d368faecb82dfb9b/logging-1.0.0.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/com.github.oshi/oshi-core/5.8.5/1d0ec654d820741327f5a9229d513732a4b7ce50/oshi-core-5.8.5.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/net.java.dev.jna/jna/5.10.0/7cf4c87dd802db50721db66947aa237d7ad09418/jna-5.10.0.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/net.java.dev.jna/jna-platform/5.10.0/fbed7d9669dba47714ad0d4f4454290a997aee69/jna-platform-5.10.0.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-api/1.8.0-beta4/83b0359d847ee053d745be7ec0d8e9e8a44304b4/slf4j-api-1.8.0-beta4.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-slf4j18-impl/2.17.0/bd7f6c0b9224dd214afb4e684957e2349b529a8d/log4j-slf4j18-impl-2.17.0.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/com.mojang/javabridge/1.2.24/c876796229b2ef5120f186eab5acc870699d3b9/javabridge-1.2.24.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/net.sf.jopt-simple/jopt-simple/5.0.4/4fdac2fbe92dfad86aa6e9301736f6b4342a3f5c/jopt-simple-5.0.4.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/io.netty/netty-all/4.1.68.Final/b8266a3c93c1c051109f71d3449e5dcd5d60b333/netty-all-4.1.68.Final.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/com.google.guava/failureaccess/1.0.1/1dcf1de382a0bf95a3d8b0849546c88bac1292c9/failureaccess-1.0.1.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/31.0.1-jre/119ea2b2bc205b138974d351777b20f02b92704b/guava-31.0.1-jre.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-lang3/3.12.0/c6842c86792ff03b9f1d1fe2aab8dc23aa6c6f0e/commons-lang3-3.12.0.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/commons-io/commons-io/2.11.0/a2503f302b11ebde7ebc3df41daebe0e4eea3689/commons-io-2.11.0.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/com.mojang/brigadier/1.0.18/c1ef1234282716483c92183f49bef47b1a89bfa9/brigadier-1.0.18.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/com.mojang/datafixerupper/4.1.27/a02c43824ce57c3f7a7d7e744f0d99a040398b5/datafixerupper-4.1.27.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/com.google.code.gson/gson/2.8.9/8a432c1d6825781e21a02db2e2c33c5fde2833b9/gson-2.8.9.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/com.mojang/authlib/3.3.39/289405e70c0917eaeac017f7fba9adb4427baa36/authlib-3.3.39.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/it.unimi.dsi/fastutil/8.5.6/76f95700418a68fbc4ac050525261f05dc681ca1/fastutil-8.5.6.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-api/2.17.0/bbd791e9c8c9421e45337c4fe0a10851c086e36c/log4j-api-2.17.0.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-core/2.17.0/fe6e7a32c1228884b9691a744f953a55d0dd8ead/log4j-core-2.17.0.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/me.shedaniel.cloth/cloth-config/6.2.57/51ec014dad95d65d070f9ef8a715966561998d3b/cloth-config-6.2.57.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/dev.architectury/architectury/4.5.75/aec16eaf48959ed6de2c446609dfa70ed8a8b4dd/architectury-4.5.75.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/me.shedaniel.cloth/basic-math/0.6.0/bcf71444d5a11d1ff0b70ded97c533ece0cea489/basic-math-0.6.0.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/net.fabricmc/fabric-loader/0.13.3/a91fc6ea7a5e8c3140dfaf34aeadb43ce2f38fe2/fabric-loader-0.13.3.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/net.fabricmc/fabric-loader/0.13.3/a91fc6ea7a5e8c3140dfaf34aeadb43ce2f38fe2/fabric-loader-0.13.3.jar:/home/shedaniel/.gradle/caches/fabric-loom/1.18.2/minecraft-merged-intermediary.jar \ No newline at end of file diff --git a/runtime-engine/categories/build/classes/java/main/me/shedaniel/rei/impl/client/registry/category/CategoryRegistryImpl$Configuration.class b/runtime-engine/categories/build/classes/java/main/me/shedaniel/rei/impl/client/registry/category/CategoryRegistryImpl$Configuration.class new file mode 100644 index 000000000..06ebb4a0d Binary files /dev/null and b/runtime-engine/categories/build/classes/java/main/me/shedaniel/rei/impl/client/registry/category/CategoryRegistryImpl$Configuration.class differ diff --git a/runtime-engine/categories/build/classes/java/main/me/shedaniel/rei/impl/client/registry/category/CategoryRegistryImpl.class b/runtime-engine/categories/build/classes/java/main/me/shedaniel/rei/impl/client/registry/category/CategoryRegistryImpl.class new file mode 100644 index 000000000..2107b717e Binary files /dev/null and b/runtime-engine/categories/build/classes/java/main/me/shedaniel/rei/impl/client/registry/category/CategoryRegistryImpl.class differ diff --git a/runtime-engine/categories/build/classes/java/main/me/shedaniel/rei/impl/common/category/CategoryIdentifierConstructorImpl.class b/runtime-engine/categories/build/classes/java/main/me/shedaniel/rei/impl/common/category/CategoryIdentifierConstructorImpl.class new file mode 100644 index 000000000..f068ae2eb Binary files /dev/null and b/runtime-engine/categories/build/classes/java/main/me/shedaniel/rei/impl/common/category/CategoryIdentifierConstructorImpl.class differ diff --git a/runtime-engine/categories/build/classes/java/main/me/shedaniel/rei/impl/common/category/CategoryIdentifierImpl.class b/runtime-engine/categories/build/classes/java/main/me/shedaniel/rei/impl/common/category/CategoryIdentifierImpl.class new file mode 100644 index 000000000..360d87b86 Binary files /dev/null and b/runtime-engine/categories/build/classes/java/main/me/shedaniel/rei/impl/common/category/CategoryIdentifierImpl.class differ diff --git a/runtime-engine/categories/build/libs/categories-transformProductionFabric.jar b/runtime-engine/categories/build/libs/categories-transformProductionFabric.jar new file mode 100644 index 000000000..08580be66 Binary files /dev/null and b/runtime-engine/categories/build/libs/categories-transformProductionFabric.jar differ diff --git a/runtime-engine/categories/build/libs/categories-transformProductionForge.jar b/runtime-engine/categories/build/libs/categories-transformProductionForge.jar new file mode 100644 index 000000000..08580be66 Binary files /dev/null and b/runtime-engine/categories/build/libs/categories-transformProductionForge.jar differ diff --git a/runtime-engine/categories/build/resources/main/META-INF/services/me.shedaniel.rei.api.client.registry.category.CategoryRegistry b/runtime-engine/categories/build/resources/main/META-INF/services/me.shedaniel.rei.api.client.registry.category.CategoryRegistry new file mode 100644 index 000000000..61b3a5741 --- /dev/null +++ b/runtime-engine/categories/build/resources/main/META-INF/services/me.shedaniel.rei.api.client.registry.category.CategoryRegistry @@ -0,0 +1 @@ +me.shedaniel.rei.impl.client.registry.category.CategoryRegistryImpl \ No newline at end of file diff --git a/runtime-engine/categories/build/resources/main/META-INF/services/me.shedaniel.rei.impl.Internals.CategoryIdentifierConstructor b/runtime-engine/categories/build/resources/main/META-INF/services/me.shedaniel.rei.impl.Internals.CategoryIdentifierConstructor new file mode 100644 index 000000000..6909538ca --- /dev/null +++ b/runtime-engine/categories/build/resources/main/META-INF/services/me.shedaniel.rei.impl.Internals.CategoryIdentifierConstructor @@ -0,0 +1 @@ +me.shedaniel.rei.impl.common.category.CategoryIdentifierConstructorImpl \ No newline at end of file diff --git a/runtime-engine/categories/build/tmp/updateLicenseMain/original/me/shedaniel/rei/impl/common/category/CategoryIdentifierConstructorImpl.java b/runtime-engine/categories/build/tmp/updateLicenseMain/original/me/shedaniel/rei/impl/common/category/CategoryIdentifierConstructorImpl.java new file mode 100644 index 000000000..cef00c684 --- /dev/null +++ b/runtime-engine/categories/build/tmp/updateLicenseMain/original/me/shedaniel/rei/impl/common/category/CategoryIdentifierConstructorImpl.java @@ -0,0 +1,22 @@ +package me.shedaniel.rei.impl.common.category; + +import me.shedaniel.rei.api.common.category.CategoryIdentifier; +import me.shedaniel.rei.api.common.display.Display; +import me.shedaniel.rei.impl.Internals; +import net.minecraft.resources.ResourceLocation; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class CategoryIdentifierConstructorImpl implements Internals.CategoryIdentifierConstructor { + private static final Map> CACHE = new ConcurrentHashMap<>(); + + @Override + public CategoryIdentifier create(String location) { + CategoryIdentifier identifier = CACHE.get(location); + if (identifier != null) return identifier.cast(); + identifier = new CategoryIdentifierImpl<>(new ResourceLocation(location)); + CACHE.put(location, identifier); + return identifier.cast(); + } +} diff --git a/runtime-engine/categories/src/main/java/me/shedaniel/rei/impl/client/registry/category/CategoryRegistryImpl.java b/runtime-engine/categories/src/main/java/me/shedaniel/rei/impl/client/registry/category/CategoryRegistryImpl.java new file mode 100644 index 000000000..b330b368c --- /dev/null +++ b/runtime-engine/categories/src/main/java/me/shedaniel/rei/impl/client/registry/category/CategoryRegistryImpl.java @@ -0,0 +1,201 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.impl.client.registry.category; + +import com.google.common.base.MoreObjects; +import dev.architectury.event.EventResult; +import me.shedaniel.rei.api.client.plugins.REIClientPlugin; +import me.shedaniel.rei.api.client.registry.category.ButtonArea; +import me.shedaniel.rei.api.client.registry.category.CategoryRegistry; +import me.shedaniel.rei.api.client.registry.category.extension.CategoryExtensionProvider; +import me.shedaniel.rei.api.client.registry.category.visibility.CategoryVisibilityPredicate; +import me.shedaniel.rei.api.client.registry.display.DisplayCategory; +import me.shedaniel.rei.api.client.registry.display.DisplayCategoryView; +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.impl.common.InternalLogger; +import org.jetbrains.annotations.ApiStatus; + +import java.util.*; +import java.util.function.Consumer; +import java.util.stream.Collectors; + +@ApiStatus.Internal +public class CategoryRegistryImpl implements CategoryRegistry { + private final Map, Configuration> categories = new LinkedHashMap<>(); + private final Map, List>>> listeners = new HashMap<>(); + private final List visibilityPredicates = new ArrayList<>(); + + @Override + public void acceptPlugin(REIClientPlugin plugin) { + plugin.registerCategories(this); + } + + @Override + public void startReload() { + this.categories.clear(); + this.listeners.clear(); + this.visibilityPredicates.clear(); + } + + @Override + public void endReload() { + InternalLogger.getInstance().debug("Registered %d categories: %s", this.categories.size(), + this.categories.values().stream().map(configuration -> configuration.getCategory().getTitle().getString()) + .collect(Collectors.joining(", "))); + } + + @Override + public void add(DisplayCategory category, Consumer> configurator) { + Configuration configuration = new Configuration<>(category); + this.categories.put(category.getCategoryIdentifier(), configuration); + configurator.accept(configuration); + + List>> listeners = this.listeners.get(category.getCategoryIdentifier()); + if (listeners != null) { + this.listeners.remove(category.getCategoryIdentifier()); + for (Consumer> listener : listeners) { + listener.accept(configuration); + } + } + + InternalLogger.getInstance().debug("Added category [%s]: %s", category.getCategoryIdentifier(), category.getTitle().getString()); + } + + @Override + public CategoryConfiguration get(CategoryIdentifier category) { + return (CategoryConfiguration) Objects.requireNonNull(this.categories.get(category), category.toString()); + } + + @Override + public Optional> tryGet(CategoryIdentifier category) { + return Optional.ofNullable((CategoryConfiguration) this.categories.get(category)); + } + + @Override + public void configure(CategoryIdentifier category, Consumer> action) { + if (this.categories.containsKey(category)) { + action.accept(get(category)); + } else { + //noinspection rawtypes + listeners.computeIfAbsent(category, location -> new ArrayList<>()).add((Consumer) action); + } + } + + @Override + public Iterator> iterator() { + return (Iterator>) (Iterator) categories.values().iterator(); + } + + @Override + public int size() { + return categories.size(); + } + + @Override + public void registerVisibilityPredicate(CategoryVisibilityPredicate predicate) { + visibilityPredicates.add(predicate); + visibilityPredicates.sort(Comparator.reverseOrder()); + InternalLogger.getInstance().debug("Added category visibility predicate: %s [%.2f priority]", predicate, predicate.getPriority()); + } + + @Override + public boolean isCategoryVisible(DisplayCategory category) { + for (CategoryVisibilityPredicate predicate : visibilityPredicates) { + try { + EventResult result = predicate.handleCategory(category); + if (result.interruptsFurtherEvaluation()) { + return result.isEmpty() || result.isTrue(); + } + } catch (Throwable throwable) { + InternalLogger.getInstance().error("Failed to check if the category is visible!", throwable); + } + } + + return true; + } + + @Override + public List getVisibilityPredicates() { + return Collections.unmodifiableList(visibilityPredicates); + } + + private static class Configuration implements CategoryConfiguration { + private final DisplayCategory category; + private final List workstations = Collections.synchronizedList(new ArrayList<>()); + private final List> extensionProviders = Collections.synchronizedList(new ArrayList<>()); + + private ButtonArea plusButtonArea = ButtonArea.defaultArea(); + + public Configuration(DisplayCategory category) { + this.category = category; + } + + @Override + public void addWorkstations(EntryIngredient... stations) { + this.workstations.addAll(Arrays.asList(stations)); + } + + @Override + public void setPlusButtonArea(ButtonArea area) { + this.plusButtonArea = MoreObjects.firstNonNull(area, ButtonArea.defaultArea()); + } + + @Override + public Optional getPlusButtonArea() { + return Optional.of(bounds -> Objects.requireNonNullElseGet(this.plusButtonArea.get(bounds), () -> ButtonArea.defaultArea().get(bounds))); + } + + @Override + public List getWorkstations() { + return Collections.unmodifiableList(this.workstations); + } + + @Override + public DisplayCategory getCategory() { + return this.category; + } + + @Override + public CategoryIdentifier getCategoryIdentifier() { + return this.category.getCategoryIdentifier(); + } + + @Override + public void registerExtension(CategoryExtensionProvider provider) { + this.extensionProviders.add(provider); + } + + @Override + public DisplayCategoryView getView(T display) { + DisplayCategory category = getCategory(); + DisplayCategoryView view = getCategory(); + for (CategoryExtensionProvider provider : this.extensionProviders) { + view = Objects.requireNonNull(provider.provide(display, category, view)); + } + return view; + } + } +} diff --git a/runtime-engine/categories/src/main/java/me/shedaniel/rei/impl/common/category/CategoryIdentifierConstructorImpl.java b/runtime-engine/categories/src/main/java/me/shedaniel/rei/impl/common/category/CategoryIdentifierConstructorImpl.java new file mode 100644 index 000000000..a4246ccec --- /dev/null +++ b/runtime-engine/categories/src/main/java/me/shedaniel/rei/impl/common/category/CategoryIdentifierConstructorImpl.java @@ -0,0 +1,45 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.impl.common.category; + +import me.shedaniel.rei.api.common.category.CategoryIdentifier; +import me.shedaniel.rei.api.common.display.Display; +import me.shedaniel.rei.impl.Internals; +import net.minecraft.resources.ResourceLocation; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class CategoryIdentifierConstructorImpl implements Internals.CategoryIdentifierConstructor { + private static final Map> CACHE = new ConcurrentHashMap<>(); + + @Override + public CategoryIdentifier create(String location) { + CategoryIdentifier identifier = CACHE.get(location); + if (identifier != null) return identifier.cast(); + identifier = new CategoryIdentifierImpl<>(new ResourceLocation(location)); + CACHE.put(location, identifier); + return identifier.cast(); + } +} diff --git a/runtime-engine/categories/src/main/java/me/shedaniel/rei/impl/common/category/CategoryIdentifierImpl.java b/runtime-engine/categories/src/main/java/me/shedaniel/rei/impl/common/category/CategoryIdentifierImpl.java new file mode 100644 index 000000000..8fc1e0a9b --- /dev/null +++ b/runtime-engine/categories/src/main/java/me/shedaniel/rei/impl/common/category/CategoryIdentifierImpl.java @@ -0,0 +1,67 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.impl.common.category; + +import me.shedaniel.rei.api.common.category.CategoryIdentifier; +import me.shedaniel.rei.api.common.display.Display; +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.ApiStatus; + +import java.util.Objects; + +@ApiStatus.Internal +class CategoryIdentifierImpl implements CategoryIdentifier { + private final ResourceLocation location; + private final int hashCode; + + CategoryIdentifierImpl(ResourceLocation location) { + this.location = Objects.requireNonNull(location); + this.hashCode = location.hashCode(); + } + + @Override + public ResourceLocation getIdentifier() { + return location; + } + + @Override + public int hashCode() { + return hashCode; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof CategoryIdentifier that)) return false; + if (obj instanceof CategoryIdentifierImpl thatImpl) { + return hashCode == obj.hashCode() && location.equals(thatImpl.location); + } + + return location.equals(that.getIdentifier()); + } + + @Override + public String toString() { + return location.toString(); + } +} diff --git a/runtime-engine/categories/src/main/resources/META-INF/services/me.shedaniel.rei.api.client.registry.category.CategoryRegistry b/runtime-engine/categories/src/main/resources/META-INF/services/me.shedaniel.rei.api.client.registry.category.CategoryRegistry new file mode 100644 index 000000000..61b3a5741 --- /dev/null +++ b/runtime-engine/categories/src/main/resources/META-INF/services/me.shedaniel.rei.api.client.registry.category.CategoryRegistry @@ -0,0 +1 @@ +me.shedaniel.rei.impl.client.registry.category.CategoryRegistryImpl \ No newline at end of file diff --git a/runtime-engine/categories/src/main/resources/META-INF/services/me.shedaniel.rei.impl.Internals.CategoryIdentifierConstructor b/runtime-engine/categories/src/main/resources/META-INF/services/me.shedaniel.rei.impl.Internals.CategoryIdentifierConstructor new file mode 100644 index 000000000..6909538ca --- /dev/null +++ b/runtime-engine/categories/src/main/resources/META-INF/services/me.shedaniel.rei.impl.Internals.CategoryIdentifierConstructor @@ -0,0 +1 @@ +me.shedaniel.rei.impl.common.category.CategoryIdentifierConstructorImpl \ No newline at end of file -- cgit