diff options
| author | shedaniel <daniel@shedaniel.me> | 2024-08-14 23:11:28 +0900 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2024-09-05 01:06:44 +0900 |
| commit | 3cf87de5b6fea02eb26b747761f8f85ad0b65f51 (patch) | |
| tree | 2e343df11d27db3337135810a877a2c4363ad6a8 /api/src | |
| parent | e80ca84f1affb91d2388ddb298bfc6b141828cad (diff) | |
| download | RoughlyEnoughItems-3cf87de5b6fea02eb26b747761f8f85ad0b65f51.tar.gz RoughlyEnoughItems-3cf87de5b6fea02eb26b747761f8f85ad0b65f51.tar.bz2 RoughlyEnoughItems-3cf87de5b6fea02eb26b747761f8f85ad0b65f51.zip | |
New Optimised Craftable Filter
(should remove almost all stutters with the filter)
Developers can also use the new TransferHandlerMeta to provide custom info for available ingredients used for quickly determining whether the player can craft it.
Diffstat (limited to 'api/src')
3 files changed, 64 insertions, 2 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandlerMeta.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandlerMeta.java new file mode 100644 index 000000000..2bdb5616d --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandlerMeta.java @@ -0,0 +1,48 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.client.registry.transfer; + +import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.ApiStatus; + +import java.util.List; + +/** + * A meta interface for {@link TransferHandler}. + */ +@ApiStatus.Experimental +public interface TransferHandlerMeta { + /** + * Returns the available ingredients for the transfer handler. + * This is used in the craftable filter, and the quick transfer tooltip to quickly determine if the handler can handle the recipe. + * <p> + * If this interface is not implemented, REI will assume stacks only from the player's inventory are available. + * + * @param context the context + * @return the available ingredients + */ + default Iterable<ItemStack> getAvailableIngredients(TransferHandler.Context context) { + return List.of(); + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/simple/SimpleTransferHandler.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/simple/SimpleTransferHandler.java index e072cea9d..af21306ba 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/simple/SimpleTransferHandler.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/simple/SimpleTransferHandler.java @@ -23,14 +23,17 @@ package me.shedaniel.rei.api.client.registry.transfer.simple; +import com.google.common.collect.Iterables; import com.mojang.blaze3d.vertex.PoseStack; import it.unimi.dsi.fastutil.ints.IntSet; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.gui.widgets.Slot; import me.shedaniel.rei.api.client.gui.widgets.Widget; import me.shedaniel.rei.api.client.registry.transfer.TransferHandler; +import me.shedaniel.rei.api.client.registry.transfer.TransferHandlerMeta; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.Display; +import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.entry.InputIngredient; import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; import me.shedaniel.rei.api.common.transfer.info.stack.SlotAccessor; @@ -44,13 +47,14 @@ import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.ApiStatus; +import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import java.util.stream.IntStream; @ApiStatus.Experimental -public interface SimpleTransferHandler extends TransferHandler { +public interface SimpleTransferHandler extends TransferHandler, TransferHandlerMeta { static <C extends AbstractContainerMenu, D extends Display> SimpleTransferHandler create(Class<? extends C> containerClass, CategoryIdentifier<D> categoryIdentifier, IntRange inputSlots) { @@ -147,6 +151,11 @@ public interface SimpleTransferHandler extends TransferHandler { InputIngredient.withType(entry, VanillaEntryTypes.ITEM)); } + @Override + default Iterable<ItemStack> getAvailableIngredients(Context context) { + return Iterables.transform(Iterables.concat(getInputSlots(context), getInventorySlots(context)), SlotAccessor::getItemStack); + } + /** * Renders the missing ingredients of the transfer. * diff --git a/api/src/main/java/me/shedaniel/rei/api/client/view/Views.java b/api/src/main/java/me/shedaniel/rei/api/client/view/Views.java index 061d5470d..fb4c6d019 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/view/Views.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/view/Views.java @@ -31,6 +31,7 @@ import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import java.util.Collection; +import java.util.List; public interface Views extends Reloadable<REIClientPlugin> { /** @@ -49,6 +50,10 @@ public interface Views extends Reloadable<REIClientPlugin> { * Returns all craftable items from materials. * * @return the list of craftable entries + * @deprecated This is no longer exposed in the API due to the lack of use cases and how this API is very specific to a type of implementation. */ - Collection<EntryStack<?>> findCraftableEntriesByMaterials(); + @Deprecated(forRemoval = true) + default Collection<EntryStack<?>> findCraftableEntriesByMaterials() { + return List.of(); + } } |
