diff options
15 files changed, 347 insertions, 97 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/ItemComparator.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/EntryComparator.java index 09c36cec6..c40966887 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/ItemComparator.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/EntryComparator.java @@ -23,6 +23,7 @@ package me.shedaniel.rei.api.common.entry.comparison; +import me.shedaniel.architectury.fluid.FluidStack; import me.shedaniel.rei.impl.Internals; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; @@ -32,15 +33,15 @@ import java.util.Objects; import java.util.function.ToLongFunction; /** - * Hasher implementation for {@link ItemStack}. + * Hasher implementation for {@link T}. */ @FunctionalInterface -public interface ItemComparator { - static ItemComparator noop() { +public interface EntryComparator<T> { + static <T> EntryComparator<T> noop() { return (context, stack) -> 1; } - static ItemComparator itemNbt() { + static EntryComparator<ItemStack> itemNbt() { ToLongFunction<Tag> nbtHasher = nbtHasher("Count"); return (context, stack) -> { CompoundTag tag = stack.getTag(); @@ -48,23 +49,31 @@ public interface ItemComparator { }; } + static EntryComparator<FluidStack> fluidNbt() { + ToLongFunction<Tag> nbtHasher = nbtHasher("Amount"); + return (context, stack) -> { + CompoundTag tag = stack.getTag(); + return tag == null ? 0L : nbtHasher.applyAsLong(tag); + }; + } + static ToLongFunction<Tag> nbtHasher(String... ignoredKeys) { return Internals.getNbtHasher(ignoredKeys); } - long hash(ComparisonContext context, ItemStack stack); + long hash(ComparisonContext context, T stack); - default ItemComparator onlyExact() { - ItemComparator self = this; + default EntryComparator<T> onlyExact() { + EntryComparator<T> self = this; return (context, stack) -> { return context.isExact() ? self.hash(context, stack) : 1; }; } - default ItemComparator then(ItemComparator other) { + default EntryComparator<T> then(EntryComparator<T> other) { Objects.requireNonNull(other); - ItemComparator self = this; + EntryComparator<T> self = this; return (context, stack) -> { long hash = 1L; diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/EntryComparatorRegistry.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/EntryComparatorRegistry.java new file mode 100644 index 000000000..ba77326e6 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/EntryComparatorRegistry.java @@ -0,0 +1,49 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.common.entry.comparison; + +import me.shedaniel.rei.api.common.plugins.REIPlugin; +import me.shedaniel.rei.api.common.registry.Reloadable; + +/** + * Registry for registering custom methods for identifying variants of {@link T}. + * The default comparator is {@link EntryComparator#noop()}, which does not compare the NBT of the entries. + * <p> + * This comparator is used when the comparison context is {@link ComparisonContext#EXACT}. + */ +public interface EntryComparatorRegistry<T, S> extends Reloadable<REIPlugin<?>> { + void register(EntryComparator<T> comparator, S entry); + + default void register(EntryComparator<T> comparator, S... entries) { + for (S entry : entries) { + register(comparator, entry); + } + } + + long hashOf(ComparisonContext context, T stack); + + boolean containsComparator(S entry); + + int comparatorSize(); +} diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/FluidComparatorRegistry.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/FluidComparatorRegistry.java new file mode 100644 index 000000000..f8489ef2e --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/FluidComparatorRegistry.java @@ -0,0 +1,45 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.common.entry.comparison; + +import me.shedaniel.architectury.fluid.FluidStack; +import me.shedaniel.rei.api.common.plugins.PluginManager; +import net.minecraft.world.level.material.Fluid; + +public interface FluidComparatorRegistry extends EntryComparatorRegistry<FluidStack, Fluid> { + /** + * @return the instance of {@link FluidComparatorRegistry} + */ + static FluidComparatorRegistry getInstance() { + return PluginManager.getInstance().get(FluidComparatorRegistry.class); + } + + default void registerNbt(Fluid fluid) { + register(EntryComparator.fluidNbt(), fluid); + } + + default void registerNbt(Fluid... fluids) { + register(EntryComparator.fluidNbt(), fluids); + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/ItemComparatorRegistry.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/ItemComparatorRegistry.java index 99f8a0038..299eab648 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/ItemComparatorRegistry.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/ItemComparatorRegistry.java @@ -24,18 +24,10 @@ package me.shedaniel.rei.api.common.entry.comparison; import me.shedaniel.rei.api.common.plugins.PluginManager; -import me.shedaniel.rei.api.common.plugins.REIPlugin; -import me.shedaniel.rei.api.common.registry.Reloadable; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; -/** - * Registry for registering custom methods for identifying variants of {@link net.minecraft.world.item.ItemStack}. - * The default comparator is {@link ItemComparator#noop()}, which does not compare the NBT of the items. - * <p> - * This comparator is used when the comparison context is {@link ComparisonContext#EXACT}. - */ -public interface ItemComparatorRegistry extends Reloadable<REIPlugin<?>> { +public interface ItemComparatorRegistry extends EntryComparatorRegistry<ItemStack, Item> { /** * @return the instance of {@link ItemComparatorRegistry} */ @@ -43,25 +35,11 @@ public interface ItemComparatorRegistry extends Reloadable<REIPlugin<?>> { return PluginManager.getInstance().get(ItemComparatorRegistry.class); } - void register(ItemComparator comparator, Item item); - - default void register(ItemComparator comparator, Item... items) { - for (Item item : items) { - register(comparator, item); - } - } - default void registerNbt(Item item) { - register(ItemComparator.itemNbt(), item); + register(EntryComparator.itemNbt(), item); } default void registerNbt(Item... items) { - register(ItemComparator.itemNbt(), items); + register(EntryComparator.itemNbt(), items); } - - long hashOf(ComparisonContext context, ItemStack stack); - - boolean containsComparator(Item item); - - int comparatorSize(); } diff --git a/api/src/main/java/me/shedaniel/rei/api/common/plugins/REIPlugin.java b/api/src/main/java/me/shedaniel/rei/api/common/plugins/REIPlugin.java index 0c5559f05..44998c914 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/plugins/REIPlugin.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/plugins/REIPlugin.java @@ -24,6 +24,7 @@ package me.shedaniel.rei.api.common.plugins; import me.shedaniel.rei.api.common.display.DisplaySerializerRegistry; +import me.shedaniel.rei.api.common.entry.comparison.FluidComparatorRegistry; import me.shedaniel.rei.api.common.entry.comparison.ItemComparatorRegistry; import me.shedaniel.rei.api.common.entry.type.EntryTypeRegistry; import me.shedaniel.rei.api.common.fluid.FluidSupportProvider; @@ -69,6 +70,15 @@ public interface REIPlugin<P extends REIPlugin<?>> extends Comparable<REIPlugin< } /** + * Registers fluid comparators for identifying variants of {@link me.shedaniel.architectury.fluid.FluidStack}. + * + * @see FluidComparatorRegistry + */ + @ApiStatus.OverrideOnly + default void registerFluidComparators(FluidComparatorRegistry registry) { + } + + /** * Registers new item to fluid support providers. * * @param support the support registry diff --git a/build.gradle b/build.gradle index 43374d259..e6a71eb19 100755 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id("architectury-plugin") version("3.1-SNAPSHOT") - id("forgified-fabric-loom") version("0.6-SNAPSHOT") apply false + id("dev.architectury.loom") version("0.7.2-SNAPSHOT") apply false id("org.cadixdev.licenser") version("0.5.0") id("com.matthewprenger.cursegradle") version("1.4.0") id("java") @@ -18,7 +18,7 @@ group = "me.shedaniel" subprojects { apply plugin: "com.matthewprenger.cursegradle" - apply plugin: "forgified-fabric-loom" + apply plugin: "dev.architectury.loom" loom { silentMojangMappingsLicense() diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java index c531d422f..819c4be51 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java @@ -29,6 +29,8 @@ import com.google.common.collect.Sets; import it.unimi.dsi.fastutil.objects.Object2FloatMap; import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet; import it.unimi.dsi.fastutil.objects.ReferenceSet; +import me.shedaniel.architectury.annotations.ExpectPlatform; +import me.shedaniel.architectury.annotations.PlatformOnly; import me.shedaniel.architectury.platform.Platform; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.favorites.FavoriteEntry; @@ -42,6 +44,7 @@ import me.shedaniel.rei.api.client.registry.screen.ExclusionZones; import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry; import me.shedaniel.rei.api.client.registry.transfer.TransferHandlerRegistry; import me.shedaniel.rei.api.common.entry.EntryIngredient; +import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.api.common.util.EntryIngredients; import me.shedaniel.rei.api.common.util.EntryStacks; @@ -226,14 +229,14 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin } EntryIngredient arrowStack = EntryIngredient.of(EntryStacks.of(Items.ARROW)); ReferenceSet<Potion> registeredPotions = new ReferenceOpenHashSet<>(); - EntryRegistry.getInstance().getEntryStacks().filter(entry -> entry.getValue() == Items.LINGERING_POTION).forEach(entry -> { + EntryRegistry.getInstance().getEntryStacks().filter(entry -> entry.getType() == VanillaEntryTypes.ITEM && entry.<ItemStack>cast().getValue().getItem() == Items.LINGERING_POTION).forEach(entry -> { ItemStack itemStack = (ItemStack) entry.getValue(); Potion potion = PotionUtils.getPotion(itemStack); if (registeredPotions.add(potion)) { List<EntryIngredient> input = new ArrayList<>(); for (int i = 0; i < 4; i++) input.add(arrowStack); - input.add(EntryIngredient.of(EntryStacks.of(itemStack))); + input.add(EntryIngredients.of(itemStack)); for (int i = 0; i < 4; i++) input.add(arrowStack); ItemStack outputStack = new ItemStack(Items.TIPPED_ARROW, 8); @@ -292,9 +295,17 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin registerBrewingRecipe(base, ingredient, output); } } + } else { + registerForgePotions(registry, this); } } + @ExpectPlatform + @PlatformOnly(PlatformOnly.FORGE) + private static void registerForgePotions(DisplayRegistry registry, BuiltinClientPlugin clientPlugin) { + + } + @Override public void registerExclusionZones(ExclusionZones zones) { zones.register(EffectRenderingInventoryScreen.class, new DefaultPotionEffectExclusionZones()); diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java index c3b59ba3f..a4cf1fd7c 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java @@ -29,7 +29,7 @@ import me.shedaniel.architectury.hooks.FluidStackHooks; import me.shedaniel.architectury.platform.Platform; import me.shedaniel.architectury.utils.NbtType; import me.shedaniel.rei.api.common.display.DisplaySerializerRegistry; -import me.shedaniel.rei.api.common.entry.comparison.ItemComparator; +import me.shedaniel.rei.api.common.entry.comparison.EntryComparator; import me.shedaniel.rei.api.common.entry.comparison.ItemComparatorRegistry; import me.shedaniel.rei.api.common.fluid.FluidSupportProvider; import me.shedaniel.rei.api.common.plugins.REIServerPlugin; @@ -65,7 +65,7 @@ import java.util.stream.Stream; public class DefaultPlugin implements BuiltinPlugin, REIServerPlugin { @Override public void registerItemComparators(ItemComparatorRegistry registry) { - ToLongFunction<Tag> nbtHasher = ItemComparator.nbtHasher(); + ToLongFunction<Tag> nbtHasher = EntryComparator.nbtHasher(); Function<ItemStack, ListTag> enchantmentTag = stack -> { CompoundTag tag = stack.getTag(); if (tag == null) return null; diff --git a/forge/gradle.properties b/forge/gradle.properties index 3507db2d4..82425854e 100644 --- a/forge/gradle.properties +++ b/forge/gradle.properties @@ -1 +1 @@ -loom.forge=true +loom.platform=forge diff --git a/forge/src/main/java/me/shedaniel/rei/plugin/client/forge/DefaultClientPluginImpl.java b/forge/src/main/java/me/shedaniel/rei/plugin/client/forge/DefaultClientPluginImpl.java new file mode 100644 index 000000000..7c47d1c84 --- /dev/null +++ b/forge/src/main/java/me/shedaniel/rei/plugin/client/forge/DefaultClientPluginImpl.java @@ -0,0 +1,71 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.plugin.client.forge; + +import com.google.common.collect.Sets; +import me.shedaniel.rei.api.client.registry.display.DisplayRegistry; +import me.shedaniel.rei.plugin.client.BuiltinClientPlugin; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.alchemy.Potion; +import net.minecraft.world.item.alchemy.PotionBrewing; +import net.minecraft.world.item.alchemy.PotionUtils; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraftforge.registries.IRegistryDelegate; + +import java.util.Arrays; +import java.util.Set; + +public class DefaultClientPluginImpl { + public static void registerForgePotions(DisplayRegistry registry, BuiltinClientPlugin clientPlugin) { + Set<Potion> potions = Sets.newLinkedHashSet(); + for (Ingredient container : PotionBrewing.ALLOWED_CONTAINERS) { + for (PotionBrewing.Mix<Potion> mix : PotionBrewing.POTION_MIXES) { + IRegistryDelegate<Potion> from = mix.from; + Ingredient ingredient = mix.ingredient; + IRegistryDelegate<Potion> to = mix.to; + Ingredient base = Ingredient.of(Arrays.stream(container.getItems()) + .map(ItemStack::copy) + .map(stack -> PotionUtils.setPotion(stack, from.get()))); + ItemStack output = Arrays.stream(container.getItems()) + .map(ItemStack::copy) + .map(stack -> PotionUtils.setPotion(stack, to.get())) + .findFirst().orElse(ItemStack.EMPTY); + clientPlugin.registerBrewingRecipe(base, ingredient, output); + potions.add(from.get()); + potions.add(to.get()); + } + } + for (Potion potion : potions) { + for (PotionBrewing.Mix<Item> mix : PotionBrewing.CONTAINER_MIXES) { + IRegistryDelegate<Item> from = mix.from; + Ingredient ingredient = mix.ingredient; + IRegistryDelegate<Item> to = mix.to; + Ingredient base = Ingredient.of(PotionUtils.setPotion(new ItemStack(from.get()), potion)); + ItemStack output = PotionUtils.setPotion(new ItemStack(to.get()), potion); + clientPlugin.registerBrewingRecipe(base, ingredient, output); + } + } + } +} diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index 8112b7630..312957985 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -52,6 +52,8 @@ import me.shedaniel.rei.api.client.registry.screen.OverlayDecider; import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.entry.EntryStack; +import me.shedaniel.rei.api.common.entry.comparison.EntryComparatorRegistry; +import me.shedaniel.rei.api.common.entry.comparison.FluidComparatorRegistry; import me.shedaniel.rei.api.common.entry.comparison.ItemComparatorRegistry; import me.shedaniel.rei.api.common.entry.type.BuiltinEntryTypes; import me.shedaniel.rei.api.common.entry.type.EntryDefinition; @@ -85,6 +87,8 @@ import me.shedaniel.rei.impl.common.display.DisplaySerializerRegistryImpl; import me.shedaniel.rei.impl.common.entry.EmptyEntryStack; import me.shedaniel.rei.impl.common.entry.EntryIngredientImpl; import me.shedaniel.rei.impl.common.entry.TypedEntryStack; +import me.shedaniel.rei.impl.common.entry.comparison.EntryComparatorRegistryImpl; +import me.shedaniel.rei.impl.common.entry.comparison.FluidComparatorRegistryImpl; import me.shedaniel.rei.impl.common.entry.comparison.ItemComparatorRegistryImpl; import me.shedaniel.rei.impl.common.entry.comparison.NbtHasherProviderImpl; import me.shedaniel.rei.impl.common.entry.type.EntryRegistryImpl; @@ -234,10 +238,11 @@ public class RoughlyEnoughItemsCore { REIPlugin.class, UnaryOperator.identity(), usedTime -> { - RoughlyEnoughItemsCore.LOGGER.info("Reloaded Plugin Manager [%s] with %d entry types, %d item comparators and %d fluid support providers in %dms.", + RoughlyEnoughItemsCore.LOGGER.info("Reloaded Plugin Manager [%s] with %d entry types, %d item comparators, %d fluid comparators and %d fluid support providers in %dms.", REIPlugin.class.getSimpleName(), EntryTypeRegistry.getInstance().values().size(), ItemComparatorRegistry.getInstance().comparatorSize(), + FluidComparatorRegistry.getInstance().comparatorSize(), FluidSupportProvider.getInstance().size(), usedTime ); @@ -245,6 +250,7 @@ public class RoughlyEnoughItemsCore { new EntryTypeRegistryImpl(), new RecipeManagerContextImpl<>(RecipeManagerContextImpl.supplier()), new ItemComparatorRegistryImpl(), + new FluidComparatorRegistryImpl(), new DisplaySerializerRegistryImpl(), new FluidSupportProviderImpl()), "commonPluginManager"); Internals.attachInstanceSupplier(new PluginManagerImpl<>( @@ -381,10 +387,10 @@ public class RoughlyEnoughItemsCore { new ViewsImpl(), new SearchProviderImpl(), new ConfigManagerImpl(), + new EntryRegistryImpl(), new CategoryRegistryImpl(), new DisplayRegistryImpl(), new ScreenRegistryImpl(), - new EntryRegistryImpl(), new FavoriteEntryTypeRegistryImpl(), new SubsetsRegistryImpl(), new TransferHandlerRegistryImpl(), diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/comparison/EntryComparatorRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/comparison/EntryComparatorRegistryImpl.java new file mode 100644 index 000000000..1304e7c5d --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/comparison/EntryComparatorRegistryImpl.java @@ -0,0 +1,78 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.impl.common.entry.comparison; + +import me.shedaniel.rei.api.common.entry.comparison.ComparisonContext; +import me.shedaniel.rei.api.common.entry.comparison.EntryComparator; +import me.shedaniel.rei.api.common.entry.comparison.EntryComparatorRegistry; +import me.shedaniel.rei.api.common.plugins.REIPlugin; +import net.minecraft.core.Registry; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.jetbrains.annotations.ApiStatus; + +import java.util.IdentityHashMap; +import java.util.Map; + +@ApiStatus.Internal +public abstract class EntryComparatorRegistryImpl<T, S> implements EntryComparatorRegistry<T, S> { + private static final Logger LOGGER = LogManager.getLogger(EntryComparatorRegistryImpl.class); + private final Map<S, EntryComparator<T>> comparators = new IdentityHashMap<>(); + + @Override + public void register(EntryComparator<T> comparator, S entry) { + EntryComparator<T> put = this.comparators.put(entry, comparator); + if (put != null) { + LOGGER.warn("[REI] Overriding " + put + "entry comparator with " + comparator + "for " + entry + "! This may result in unwanted comparisons!"); + } + } + + @Override + public void startReload() { + comparators.clear(); + } + + public abstract S getEntry(T stack); + + @Override + public long hashOf(ComparisonContext context, T stack) { + EntryComparator<T> comparator = comparators.get(getEntry(stack)); + if (comparator != null) { + return comparator.hash(context, stack); + } + return 1; + } + + @Override + public boolean containsComparator(S item) { + return comparators.containsKey(item); + } + + @Override + public int comparatorSize() { + return this.comparators.size(); + } +} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/comparison/FluidComparatorRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/comparison/FluidComparatorRegistryImpl.java new file mode 100644 index 000000000..67cceb6dd --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/comparison/FluidComparatorRegistryImpl.java @@ -0,0 +1,41 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.impl.common.entry.comparison; + +import me.shedaniel.architectury.fluid.FluidStack; +import me.shedaniel.rei.api.common.entry.comparison.FluidComparatorRegistry; +import me.shedaniel.rei.api.common.plugins.REIPlugin; +import net.minecraft.world.level.material.Fluid; + +public class FluidComparatorRegistryImpl extends EntryComparatorRegistryImpl<FluidStack, Fluid> implements FluidComparatorRegistry { + @Override + public Fluid getEntry(FluidStack stack) { + return stack.getFluid(); + } + + @Override + public void acceptPlugin(REIPlugin<?> plugin) { + plugin.registerFluidComparators(this); + } +} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/comparison/ItemComparatorRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/comparison/ItemComparatorRegistryImpl.java index ed3eb1fba..e1c7b7a3b 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/comparison/ItemComparatorRegistryImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/comparison/ItemComparatorRegistryImpl.java @@ -23,59 +23,19 @@ package me.shedaniel.rei.impl.common.entry.comparison; -import me.shedaniel.rei.api.common.entry.comparison.ComparisonContext; -import me.shedaniel.rei.api.common.entry.comparison.ItemComparator; import me.shedaniel.rei.api.common.entry.comparison.ItemComparatorRegistry; import me.shedaniel.rei.api.common.plugins.REIPlugin; -import net.minecraft.core.Registry; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.jetbrains.annotations.ApiStatus; -import java.util.IdentityHashMap; -import java.util.Map; - -@ApiStatus.Internal -public class ItemComparatorRegistryImpl implements ItemComparatorRegistry { - private static final Logger LOGGER = LogManager.getLogger(ItemComparatorRegistryImpl.class); - private final Map<Item, ItemComparator> comparators = new IdentityHashMap<>(); - +public class ItemComparatorRegistryImpl extends EntryComparatorRegistryImpl<ItemStack, Item> implements ItemComparatorRegistry { @Override - public void register(ItemComparator comparator, Item item) { - ItemComparator put = this.comparators.put(item, comparator); - if (put != null) { - LOGGER.warn("[REI] Overriding " + put + "item comparator with " + comparator + "for " + Registry.ITEM.getKey(item) + "! This may result in unwanted comparisons!"); - } - } - - @Override - public void startReload() { - comparators.clear(); + public Item getEntry(ItemStack stack) { + return stack.getItem(); } @Override public void acceptPlugin(REIPlugin<?> plugin) { plugin.registerItemComparators(this); } - - @Override - public long hashOf(ComparisonContext context, ItemStack stack) { - ItemComparator comparator = comparators.get(stack.getItem()); - if (comparator != null) { - return comparator.hash(context, stack); - } - return 1; - } - - @Override - public boolean containsComparator(Item item) { - return com |
