diff --git a/common/src/main/java/net/mehvahdjukaar/moonlight/api/resources/recipe/BlockTypeSwapIngredient.java b/common/src/main/java/net/mehvahdjukaar/moonlight/api/resources/recipe/BlockTypeSwapIngredient.java index 3fd38b7e..818fb618 100644 --- a/common/src/main/java/net/mehvahdjukaar/moonlight/api/resources/recipe/BlockTypeSwapIngredient.java +++ b/common/src/main/java/net/mehvahdjukaar/moonlight/api/resources/recipe/BlockTypeSwapIngredient.java @@ -2,19 +2,26 @@ import dev.architectury.injectables.annotations.ExpectPlatform; import net.mehvahdjukaar.moonlight.api.set.BlockType; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; import org.jetbrains.annotations.ApiStatus; -public class BlockTypeSwapIngredient { +import java.util.List; + +public interface BlockTypeSwapIngredient { @ExpectPlatform - public static Ingredient create(Ingredient original, T from, T to) { + static Ingredient create(Ingredient original, T from, T to) { throw new AssertionError(); } @ApiStatus.Internal @ExpectPlatform - public static void init() { + static void init() { throw new AssertionError(); } + + Ingredient getInner(); + + List convertItems(List items); } diff --git a/fabric/src/main/java/net/mehvahdjukaar/moonlight/api/resources/recipe/fabric/BlockTypeSwapIngredientImpl.java b/fabric/src/main/java/net/mehvahdjukaar/moonlight/api/resources/recipe/fabric/BlockTypeSwapIngredientImpl.java index 66a89953..2ceca445 100644 --- a/fabric/src/main/java/net/mehvahdjukaar/moonlight/api/resources/recipe/fabric/BlockTypeSwapIngredientImpl.java +++ b/fabric/src/main/java/net/mehvahdjukaar/moonlight/api/resources/recipe/fabric/BlockTypeSwapIngredientImpl.java @@ -3,6 +3,7 @@ import com.google.gson.JsonObject; import net.fabricmc.fabric.api.recipe.v1.ingredient.CustomIngredient; import net.fabricmc.fabric.api.recipe.v1.ingredient.CustomIngredientSerializer; +import net.mehvahdjukaar.moonlight.api.resources.recipe.BlockTypeSwapIngredient; import net.mehvahdjukaar.moonlight.api.set.BlockType; import net.mehvahdjukaar.moonlight.api.set.BlockTypeRegistry; import net.mehvahdjukaar.moonlight.core.Moonlight; @@ -16,7 +17,7 @@ import java.util.Arrays; import java.util.List; -public class BlockTypeSwapIngredientImpl implements CustomIngredient { +public class BlockTypeSwapIngredientImpl implements CustomIngredient, BlockTypeSwapIngredient { private static final ResourceLocation ID = Moonlight.res("block_type_swap"); @@ -36,6 +37,11 @@ public BlockTypeSwapIngredientImpl(Ingredient inner, T fromType, T toType, Block } + @Override + public Ingredient getInner() { + return inner; + } + @Override public boolean test(ItemStack stack) { if (stack != null) { @@ -48,28 +54,33 @@ public boolean test(ItemStack stack) { return false; } + @Override + public List convertItems(List toConvert) { + List newItems = new ArrayList<>(); + boolean success = false; + for (ItemStack it : toConvert) { + var type = this.registry.getBlockTypeOf(it.getItem()); + if (type != this.fromType) { + break; + } else { + var newItem = BlockType.changeItemType(it.getItem(), this.fromType, this.toType); + if (newItem != null) { + newItems.add(new ItemStack(newItem)); + success = true; + } + } + } + if (!success) { + newItems.addAll(toConvert); + } + return newItems; + } + @Override public List getMatchingStacks() { if (this.items == null) { var original = this.inner.getItems(); - List newItems = new ArrayList<>(); - boolean success = false; - for (ItemStack it : this.items) { - var type = this.registry.getBlockTypeOf(it.getItem()); - if (type != this.fromType) { - break; - } else { - var newItem = BlockType.changeItemType(it.getItem(), this.fromType, this.toType); - if (newItem != null) { - newItems.add(new ItemStack(newItem)); - success = true; - } - } - } - if (!success) { - newItems.addAll(Arrays.stream(original).toList()); - } - this.items = newItems; + this.items = convertItems(Arrays.asList(original)); } return this.items; } diff --git a/forge/src/main/java/net/mehvahdjukaar/moonlight/api/resources/recipe/forge/BlockTypeSwapIngredientImpl.java b/forge/src/main/java/net/mehvahdjukaar/moonlight/api/resources/recipe/forge/BlockTypeSwapIngredientImpl.java index c0eb4ff7..593601ea 100644 --- a/forge/src/main/java/net/mehvahdjukaar/moonlight/api/resources/recipe/forge/BlockTypeSwapIngredientImpl.java +++ b/forge/src/main/java/net/mehvahdjukaar/moonlight/api/resources/recipe/forge/BlockTypeSwapIngredientImpl.java @@ -2,6 +2,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.mehvahdjukaar.moonlight.api.resources.recipe.BlockTypeSwapIngredient; import net.mehvahdjukaar.moonlight.api.set.BlockType; import net.mehvahdjukaar.moonlight.api.set.BlockTypeRegistry; import net.mehvahdjukaar.moonlight.core.Moonlight; @@ -17,7 +18,7 @@ import java.util.Arrays; import java.util.List; -public class BlockTypeSwapIngredientImpl extends AbstractIngredient { +public class BlockTypeSwapIngredientImpl extends AbstractIngredient implements BlockTypeSwapIngredient { private final Ingredient inner; private final T fromType; @@ -34,33 +35,43 @@ public BlockTypeSwapIngredientImpl(Ingredient inner, T fromType, T toType, Block this.registry = registry; } + @Override + public Ingredient getInner() { + return inner; + } + @Override public boolean isSimple() { return false; } + @Override + public List convertItems(List toConvert) { + List newItems = new ArrayList<>(); + boolean success = false; + for (ItemStack it : toConvert) { + var type = this.registry.getBlockTypeOf(it.getItem()); + if (type != this.fromType) { + break; + } else { + var newItem = BlockType.changeItemType(it.getItem(), this.fromType, this.toType); + if (newItem != null) { + newItems.add(new ItemStack(newItem)); + success = true; + } + } + } + if (!success) { + newItems.addAll(toConvert); + } + return newItems; + } + @Override public ItemStack[] getItems() { if (this.items == null) { var original = this.inner.getItems(); - List newItems = new ArrayList<>(); - boolean success = false; - for (ItemStack it : this.items) { - var type = this.registry.getBlockTypeOf(it.getItem()); - if (type != this.fromType) { - break; - } else { - var newItem = BlockType.changeItemType(it.getItem(), this.fromType, this.toType); - if (newItem != null) { - newItems.add(new ItemStack(newItem)); - success = true; - } - } - } - if (!success) { - newItems.addAll(Arrays.stream(original).toList()); - } - this.items = newItems.toArray(new ItemStack[0]); + this.items = convertItems(Arrays.asList(original)).toArray(new ItemStack[0]); } return this.items; }