diff options
| author | shedaniel <daniel@shedaniel.me> | 2022-07-27 23:25:27 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2022-08-26 10:52:27 +0900 |
| commit | 05069aa62b09f02a8cd6e526ec58a30347a56500 (patch) | |
| tree | acb90d01f0a06de7c6b540eefeeee8259016f8ac /runtime-engine/entries | |
| parent | 685861c91bbb8a8a882da51381d392f1310d061d (diff) | |
| download | RoughlyEnoughItems-05069aa62b09f02a8cd6e526ec58a30347a56500.tar.gz RoughlyEnoughItems-05069aa62b09f02a8cd6e526ec58a30347a56500.tar.bz2 RoughlyEnoughItems-05069aa62b09f02a8cd6e526ec58a30347a56500.zip | |
WIP Module
Diffstat (limited to 'runtime-engine/entries')
13 files changed, 941 insertions, 0 deletions
diff --git a/runtime-engine/entries/.gradle/loom-cache/launch.cfg b/runtime-engine/entries/.gradle/loom-cache/launch.cfg new file mode 100644 index 000000000..37d0ec9e3 --- /dev/null +++ b/runtime-engine/entries/.gradle/loom-cache/launch.cfg @@ -0,0 +1,14 @@ +commonProperties + fabric.development=true + fabric.remapClasspathFile=/home/shedaniel/Documents/JavaCoding/RoughlyEnoughItems-117/runtime-engine/entries/.gradle/loom-cache/remapClasspath.txt + log4j.configurationFile=/home/shedaniel/Documents/JavaCoding/RoughlyEnoughItems-117/runtime-engine/entries/.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/entries/.gradle/loom-cache/log4j.xml b/runtime-engine/entries/.gradle/loom-cache/log4j.xml new file mode 100644 index 000000000..c009f9fb4 --- /dev/null +++ b/runtime-engine/entries/.gradle/loom-cache/log4j.xml @@ -0,0 +1,63 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Configuration status="WARN" packages="com.mojang.util,net.minecrell.terminalconsole.util"> + <Appenders> + + <!-- System out --> + <Console name="SysOut" target="SYSTEM_OUT"> + <PatternLayout> + <LoggerNamePatternSelector defaultPattern="%style{[%d{HH:mm:ss}]}{blue} %highlight{[%t/%level]}{FATAL=red, ERROR=red, WARN=yellow, INFO=green, DEBUG=green, TRACE=blue} %style{(%logger{1})}{cyan} %highlight{%msg%n}{FATAL=red, ERROR=red, WARN=normal, INFO=normal, DEBUG=normal, TRACE=normal}" disableAnsi="${sys:fabric.log.disableAnsi:-true}"> + <!-- Dont show the logger name for minecraft classes--> + <PatternMatch key="net.minecraft.,com.mojang." pattern="%style{[%d{HH:mm:ss}]}{blue} %highlight{[%t/%level]}{FATAL=red, ERROR=red, WARN=yellow, INFO=green, DEBUG=green, TRACE=blue} %style{(Minecraft)}{cyan} %highlight{%msg{nolookups}%n}{FATAL=red, ERROR=red, WARN=normal, INFO=normal, DEBUG=normal, TRACE=normal}"/> + </LoggerNamePatternSelector> + </PatternLayout> + </Console> + + <!-- Vanilla server gui --> + <Queue name="ServerGuiConsole" ignoreExceptions="true"> + <PatternLayout> + <LoggerNamePatternSelector defaultPattern="[%d{HH:mm:ss} %level] (%logger{1}) %msg{nolookups}%n"> + <!-- Dont show the logger name for minecraft classes--> + <PatternMatch key="net.minecraft.,com.mojang." pattern="[%d{HH:mm:ss} %level] %msg{nolookups}%n"/> + </LoggerNamePatternSelector> + </PatternLayout> + </Queue> + + <!-- latest.log same as vanilla --> + <RollingRandomAccessFile name="LatestFile" fileName="logs/latest.log" filePattern="logs/%d{yyyy-MM-dd}-%i.log.gz"> + <PatternLayout> + <LoggerNamePatternSelector defaultPattern="[%d{HH:mm:ss}] [%t/%level] (%logger{1}) %msg{nolookups}%n"> + <!-- Dont show the logger name for minecraft classes--> + <PatternMatch key="net.minecraft.,com.mojang." pattern="[%d{HH:mm:ss}] [%t/%level] (Minecraft) %msg{nolookups}%n"/> + </LoggerNamePatternSelector> + </PatternLayout> + <Policies> + <TimeBasedTriggeringPolicy /> + <OnStartupTriggeringPolicy /> + </Policies> + </RollingRandomAccessFile> + + <!-- Debug log file --> + <RollingRandomAccessFile name="DebugFile" fileName="logs/debug.log" filePattern="logs/debug-%i.log.gz"> + <PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level] (%logger) %msg{nolookups}%n" /> + + <!-- Keep 5 files max --> + <DefaultRolloverStrategy max="5" fileIndex="min"/> + + <Policies> + <SizeBasedTriggeringPolicy size="200MB"/> + <OnStartupTriggeringPolicy /> + </Policies> + + </RollingRandomAccessFile> + </Appenders> + <Loggers> + <Logger level="${sys:fabric.log.level:-info}" name="net.minecraft"/> + <Logger level="warn" name="cpw.mods.modlauncher.ClassTransformer"/> + <Root level="all"> + <AppenderRef ref="DebugFile" level="${sys:fabric.log.debug.level:-debug}"/> + <AppenderRef ref="SysOut" level="${sys:fabric.log.level:-info}"/> + <AppenderRef ref="LatestFile" level="${sys:fabric.log.level:-info}"/> + <AppenderRef ref="ServerGuiConsole" level="${sys:fabric.log.level:-info}"/> + </Root> + </Loggers> +</Configuration>
\ No newline at end of file diff --git a/runtime-engine/entries/.gradle/loom-cache/remapClasspath.txt b/runtime-engine/entries/.gradle/loom-cache/remapClasspath.txt new file mode 100644 index 000000000..01f75adc1 --- /dev/null +++ b/runtime-engine/entries/.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/entries/build/libs/entries-transformProductionFabric.jar b/runtime-engine/entries/build/libs/entries-transformProductionFabric.jar Binary files differnew file mode 100644 index 000000000..08580be66 --- /dev/null +++ b/runtime-engine/entries/build/libs/entries-transformProductionFabric.jar diff --git a/runtime-engine/entries/build/libs/entries-transformProductionForge.jar b/runtime-engine/entries/build/libs/entries-transformProductionForge.jar Binary files differnew file mode 100644 index 000000000..08580be66 --- /dev/null +++ b/runtime-engine/entries/build/libs/entries-transformProductionForge.jar diff --git a/runtime-engine/entries/src/main/java/me/shedaniel/rei/impl/client/entry/type/EntryRegistryImpl.java b/runtime-engine/entries/src/main/java/me/shedaniel/rei/impl/client/entry/type/EntryRegistryImpl.java new file mode 100644 index 000000000..be1ed5225 --- /dev/null +++ b/runtime-engine/entries/src/main/java/me/shedaniel/rei/impl/client/entry/type/EntryRegistryImpl.java @@ -0,0 +1,276 @@ +/* + * 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.entry.type; + +import com.google.common.collect.Lists; +import it.unimi.dsi.fastutil.longs.LongArrayList; +import it.unimi.dsi.fastutil.longs.LongList; +import it.unimi.dsi.fastutil.longs.LongOpenHashSet; +import it.unimi.dsi.fastutil.longs.LongSet; +import me.shedaniel.rei.api.client.REIRuntime; +import me.shedaniel.rei.api.client.overlay.ScreenOverlay; +import me.shedaniel.rei.api.client.plugins.REIClientPlugin; +import me.shedaniel.rei.api.client.registry.entry.EntryRegistry; +import me.shedaniel.rei.api.common.entry.EntryStack; +import me.shedaniel.rei.api.common.entry.comparison.ComparisonContext; +import me.shedaniel.rei.api.common.entry.type.EntryDefinition; +import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; +import me.shedaniel.rei.api.common.registry.ReloadStage; +import me.shedaniel.rei.api.common.util.CollectionUtils; +import me.shedaniel.rei.api.common.util.EntryStacks; +import me.shedaniel.rei.impl.Internals; +import me.shedaniel.rei.impl.common.InternalLogger; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; + +import java.util.*; +import java.util.function.LongPredicate; +import java.util.function.Predicate; +import java.util.stream.Stream; + +@ApiStatus.Internal +@Environment(EnvType.CLIENT) +public class EntryRegistryImpl implements EntryRegistry { + private final List<EntryRegistryListener> listeners = Lists.newCopyOnWriteArrayList(); + private EntryRegistryList registryList; + private LongSet entriesHash; + private boolean reloading; + + public EntryRegistryImpl() { + registryList = new NormalEntryRegistryList(); + entriesHash = new LongOpenHashSet(); + listeners.addAll(Internals.resolveServices(EntryRegistryListener.class)); + } + + @Override + public void acceptPlugin(REIClientPlugin plugin) { + plugin.registerEntries(this); + } + + @Override + public ReloadStage getStage() { + return ReloadStage.START; + } + + @Override + public void startReload() { + registryList = new ReloadingEntryRegistryList(); + entriesHash = new LongOpenHashSet(); + reloading = true; + } + + @Override + public void endReload() { + reloading = false; + if (!(registryList instanceof ReloadingEntryRegistryList)) { + throw new IllegalStateException("Expected ReloadingEntryRegistryList, got " + registryList.getClass().getName()); + } + registryList = new NormalEntryRegistryList(registryList.stream().filter(((Predicate<EntryStack<?>>) EntryStack::isEmpty).negate())); + refilter(); + REIRuntime.getInstance().getOverlay().ifPresent(ScreenOverlay::queueReloadOverlay); + InternalLogger.getInstance().debug("Reloaded entry registry with %d entries and %d filtered entries", size(), getPreFilteredList().size()); + } + + @Override + public boolean isReloading() { + return reloading; + } + + @Override + public int size() { + return registryList.size(); + } + + @Override + public Stream<EntryStack<?>> getEntryStacks() { + return registryList.stream(); + } + + @Override + public void refilter() { + List<EntryStack<?>> stacks = registryList.collect(); + + for (EntryRegistryListener listener : listeners) { + listener.onReFilter(stacks); + } + } + + private static final Comparator<ItemStack> STACK_COMPARATOR = (a, b) -> ItemStack.matches(a, b) ? 0 : 1; + + @Override + public List<ItemStack> appendStacksForItem(Item item) { + NonNullList<ItemStack> list = NonNullList.create(); + LongSet set = new LongOpenHashSet(); + EntryDefinition<ItemStack> itemDefinition = VanillaEntryTypes.ITEM.getDefinition(); + for (CreativeModeTab tab : CreativeModeTab.TABS) { + if (tab != CreativeModeTab.TAB_HOTBAR && tab != CreativeModeTab.TAB_INVENTORY) { + NonNullList<ItemStack> tabList = NonNullList.create(); + item.fillItemCategory(tab, tabList); + for (ItemStack stack : tabList) { + if (set.add(itemDefinition.hash(null, stack, ComparisonContext.EXACT))) { + list.add(stack); + } + } + } + } + if (list.isEmpty()) { + return Collections.singletonList(item.getDefaultInstance()); + } + if (list.size() > 1) { + list.sort(STACK_COMPARATOR); + } + return list; + } + + @Override + public boolean alreadyContain(EntryStack<?> stack) { + return entriesHash.contains(EntryStacks.hashExact(stack)); + } + + @Override + public void addEntryAfter(@Nullable EntryStack<?> afterEntry, EntryStack<?> stack) { + long hashExact = EntryStacks.hashExact(stack); + if (this.entriesHash.add(hashExact)) { + if (afterEntry != null) { + int index = registryList.lastIndexOf(afterEntry); + registryList.add(index, stack, hashExact); + } else registryList.add(stack, hashExact); + + for (EntryRegistryListener listener : listeners) { + listener.addEntryAfter(afterEntry, stack, hashExact); + } + } + } + + @Override + public void addEntriesAfter(@Nullable EntryStack<?> afterEntry, Collection<? extends EntryStack<?>> stacks) { + List<EntryStack<?>> filtered; + LongList hashes = registryList.needsHash() ? new LongArrayList(stacks.size()) : null; + + if (registryList.needsHash()) { + filtered = new ArrayList<>(stacks.size()); + for (EntryStack<?> stack : stacks) { + long hashExact = EntryStacks.hashExact(stack); + if (entriesHash.add(hashExact)) { + filtered.add(stack); + hashes.add(hashExact); + } + } + } else { + filtered = CollectionUtils.filterToList((List<EntryStack<?>>) stacks, entry -> entriesHash.add(EntryStacks.hashExact(entry))); + } + + if (afterEntry != null) { + int index = registryList.lastIndexOf(afterEntry); + registryList.addAll(index, filtered, hashes); + } else registryList.addAll(filtered, hashes); + + for (EntryRegistryListener listener : listeners) { + listener.addEntriesAfter(afterEntry, filtered, hashes); + } + } + + @Override + public boolean removeEntry(EntryStack<?> stack) { + long hashExact = EntryStacks.hashExact(stack); + registryList.remove(stack, hashExact); + boolean removed = entriesHash.remove(hashExact); + + if (removed) { + for (EntryRegistryListener listener : listeners) { + listener.removeEntry(stack, hashExact); + } + } + + return removed; + } + + @Override + public boolean removeEntryIf(Predicate<? extends EntryStack<?>> predicate) { + List<EntryStack<?>> removedStacks = new ArrayList<>(); + LongList hashes = registryList.needsHash() ? new LongArrayList() : null; + + boolean removed = registryList.removeIf(stack -> { + if (((Predicate<EntryStack<?>>) predicate).test(stack)) { + long hashExact = EntryStacks.hashExact(stack); + entriesHash.remove(hashExact); + removedStacks.add(stack); + if (hashes != null) hashes.add(hashExact); + return true; + } + + return false; + }); + + if (removed) { + for (EntryRegistryListener listener : listeners) { + listener.removeEntries(removedStacks, hashes); + } + } + + return removed; + } + + @Override + public boolean removeEntryExactHashIf(LongPredicate predicate) { + LongPredicate entryStackPredicate = hash -> { + if (predicate.test(hash)) { + entriesHash.remove(hash); + return true; + } + + return false; + }; + + for (EntryRegistryListener listener : listeners) { + listener.removeEntriesIf(stack -> predicate.test(EntryStacks.hashExact(stack))); + } + + return registryList.removeExactIf(entryStackPredicate); + } + + @Override + public boolean removeEntryFuzzyHashIf(LongPredicate predicate) { + Predicate<EntryStack<?>> entryStackPredicate = stack -> { + if (predicate.test(EntryStacks.hashFuzzy(stack))) { + entriesHash.remove(EntryStacks.hashExact(stack)); + return true; + } + + return false; + }; + + for (EntryRegistryListener listener : listeners) { + listener.removeEntriesIf(entryStackPredicate); + } + + return registryList.removeIf(entryStackPredicate); + } +} diff --git a/runtime-engine/entries/src/main/java/me/shedaniel/rei/impl/client/entry/type/EntryRegistryList.java b/runtime-engine/entries/src/main/java/me/shedaniel/rei/impl/client/entry/type/EntryRegistryList.java new file mode 100644 index 000000000..401bf61a9 --- /dev/null +++ b/runtime-engine/entries/src/main/java/me/shedaniel/rei/impl/client/entry/type/EntryRegistryList.java @@ -0,0 +1,62 @@ +/* + * 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.entry.type; + +import it.unimi.dsi.fastutil.longs.LongList; +import me.shedaniel.rei.api.common.entry.EntryStack; +import org.jetbrains.annotations.ApiStatus; + +import java.util.List; +import java.util.function.LongPredicate; +import java.util.function.Predicate; +import java.util.stream.Stream; + +@ApiStatus.Internal +public interface EntryRegistryList { + int size(); + + Stream<EntryStack<?>> stream(); + + List<EntryStack<?>> collect(); + + int indexOf(EntryStack<?> stack); + + int lastIndexOf(EntryStack<?> stack); + + void add(EntryStack<?> stack, long hashExact); + + void add(int index, EntryStack<?> stack, long hashExact); + + void addAll(List<EntryStack<?>> stacks, LongList hashes); + + void addAll(int index, List<EntryStack<?>> stacks, LongList hashes); + + void remove(EntryStack<?> stack, long hashExact); + + boolean removeIf(Predicate<? extends EntryStack<?>> predicate); + + boolean removeExactIf(LongPredicate predicate); + + boolean needsHash(); +} diff --git a/runtime-engine/entries/src/main/java/me/shedaniel/rei/impl/client/entry/type/EntryRegistryListener.java b/runtime-engine/entries/src/main/java/me/shedaniel/rei/impl/client/entry/type/EntryRegistryListener.java new file mode 100644 index 000000000..b1c59e0e7 --- /dev/null +++ b/runtime-engine/entries/src/main/java/me/shedaniel/rei/impl/client/entry/type/EntryRegistryListener.java @@ -0,0 +1,47 @@ +/* + * 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.entry.type; + +import it.unimi.dsi.fastutil.longs.LongList; +import me.shedaniel.rei.api.common.entry.EntryStack; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.function.Predicate; + +@ApiStatus.Internal +public interface EntryRegistryListener { + default void addEntryAfter(@Nullable EntryStack<?> afterEntry, EntryStack<?> stack, long stackHashExact) {} + + default void addEntriesAfter(@Nullable EntryStack<?> afterEntry, List<EntryStack<?>> stacks, @Nullable LongList hashes) {} + + default void removeEntry(EntryStack<?> stack, long hashExact) {} + + default void removeEntries(List<EntryStack<?>> stacks, @Nullable LongList hashes) {} + + default void removeEntriesIf(Predicate<EntryStack<?>> predicate) {} + + default void onReFilter(List<EntryStack<?>> stacks) {} +} diff --git a/runtime-engine/entries/src/main/java/me/shedaniel/rei/impl/client/entry/type/EntryTypeRegistryImpl.java b/runtime-engine/entries/src/main/java/me/shedaniel/rei/impl/client/entry/type/EntryTypeRegistryImpl.java new file mode 100644 index 000000000..ad5a6261d --- /dev/null +++ b/runtime-engine/entries/src/main/java/me/shedaniel/rei/impl/client/entry/type/EntryTypeRegistryImpl.java @@ -0,0 +1,102 @@ +/* + * 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.entry.type; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBasedTable; +import com.google.common.collect.HashBiMap; +import com.google.common.collect.Table; +import me.shedaniel.rei.api.common.entry.type.EntryDefinition; +import me.shedaniel.rei.api.common.entry.type.EntryType; +import me.shedaniel.rei.api.common.entry.type.EntryTypeBridge; +import me.shedaniel.rei.api.common.entry.type.EntryTypeRegistry; +import me.shedaniel.rei.api.common.plugins.REIPlugin; +import me.shedaniel.rei.api.common.registry.ReloadStage; +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.ApiStatus; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Set; + +@ApiStatus.Internal +public class EntryTypeRegistryImpl implements EntryTypeRegistry { + private final BiMap<ResourceLocation, EntryDefinition<?>> entryTypes = HashBiMap.create(); + private final Table<ResourceLocation, ResourceLocation, List<EntryTypeBridge<?, ?>>> typeBridges = HashBasedTable.create(); + + @Override + public ReloadStage getStage() { + return ReloadStage.START; + } + + @Override + public void acceptPlugin(REIPlugin<?> plugin) { + plugin.registerEntryTypes(this); + } + + @Override + public <T> void register(ResourceLocation id, EntryDefinition<T> definition) { + this.entryTypes.put(id, definition); + } + + @Override + public <A, B> void registerBridge(EntryType<A> original, EntryType<B> destination, EntryTypeBridge<A, B> bridge) { + List<EntryTypeBridge<?, ?>> list = this.typeBridges.get(original.getId(), destination.getId()); + if (list == null) { + this.typeBridges.put(original.getId(), destination.getId(), list = new ArrayList<>()); + } + list.add(bridge); + } + + @Override + public EntryDefinition<?> get(ResourceLocation id) { + return this.entryTypes.get(id); + } + + @Override + public Set<ResourceLocation> keySet() { + return this.entryTypes.keySet(); + } + + @Override + public Set<EntryDefinition<?>> values() { + return this.entryTypes.values(); + } + + @Override + public <A, B> Iterable<EntryTypeBridge<A, B>> getBridgesFor(EntryType<A> original, EntryType<B> destination) { + List<? extends EntryTypeBridge<?, ?>> list = this.typeBridges.get(original.getId(), destination.getId()); + if (list == null) { + return Collections.emptyList(); + } + return (Iterable<EntryTypeBridge<A, B>>) list; + } + + @Override + public void startReload() { + entryTypes.clear(); + typeBridges.clear(); + } +} diff --git a/runtime-engine/entries/src/main/java/ |
