diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index ddb124c9..9a70edb5 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -171,15 +171,11 @@ jobs: cache: 'gradle' - name: Make gradle wrapper executable run: chmod +x ./gradlew - - name: Check current artifact hash TODO - run: sha1sum ${{ matrix.loader }}/build/libs/* - name: Publish run: ./gradlew :${{ matrix.loader }}:${{ matrix.site }} '-Pversion=${{needs.create-release.outputs.version}}' '-PtwelveIterationsNexusUsername=${{ secrets.NEXUS_USER }}' '-PtwelveIterationsNexusPassword=${{ secrets.NEXUS_PASSWORD }}' env: CURSEFORGE_TOKEN: ${{secrets.CURSEFORGE_TOKEN}} MODRINTH_TOKEN: ${{secrets.MODRINTH_TOKEN}} - - name: Check new artifact hash TODO - run: sha1sum ${{ matrix.loader }}/build/libs/* needs: - create-release - build-common diff --git a/common/src/main/java/net/blay09/mods/cookingforblockheads/InternalMethodsImpl.java b/common/src/main/java/net/blay09/mods/cookingforblockheads/InternalMethodsImpl.java index 419273cc..5c143d7f 100644 --- a/common/src/main/java/net/blay09/mods/cookingforblockheads/InternalMethodsImpl.java +++ b/common/src/main/java/net/blay09/mods/cookingforblockheads/InternalMethodsImpl.java @@ -44,12 +44,12 @@ public FoodStatsProvider getFoodStatsProvider() { } @Override - public > void registerKitchenRecipeHandler(Class recipeClass, KitchenRecipeHandler kitchenRecipeHandler) { + public > void registerKitchenRecipeHandler(Class recipeClass, KitchenRecipeHandler kitchenRecipeHandler) { CookingForBlockheadsRegistry.registerKitchenRecipeHandler(recipeClass, kitchenRecipeHandler); } @Override - public > KitchenRecipeHandler getKitchenRecipeHandler(T recipe) { + public > KitchenRecipeHandler getKitchenRecipeHandler(T recipe) { return CookingForBlockheadsRegistry.getKitchenRecipeHandler(recipe); } } diff --git a/common/src/main/java/net/blay09/mods/cookingforblockheads/api/CookingForBlockheadsAPI.java b/common/src/main/java/net/blay09/mods/cookingforblockheads/api/CookingForBlockheadsAPI.java index 2896962c..2f5f2692 100644 --- a/common/src/main/java/net/blay09/mods/cookingforblockheads/api/CookingForBlockheadsAPI.java +++ b/common/src/main/java/net/blay09/mods/cookingforblockheads/api/CookingForBlockheadsAPI.java @@ -41,11 +41,11 @@ public static Kitchen createKitchen(ItemStack itemStack) { return internalMethods.createKitchen(itemStack); } - public static > void registerKitchenRecipeHandler(Class recipeClass, KitchenRecipeHandler kitchenRecipeHandler) { + public static > void registerKitchenRecipeHandler(Class recipeClass, KitchenRecipeHandler kitchenRecipeHandler) { internalMethods.registerKitchenRecipeHandler(recipeClass, kitchenRecipeHandler); } - public static > KitchenRecipeHandler getKitchenRecipeHandler(T recipe) { + public static > KitchenRecipeHandler getKitchenRecipeHandler(T recipe) { return internalMethods.getKitchenRecipeHandler(recipe); } diff --git a/common/src/main/java/net/blay09/mods/cookingforblockheads/api/InternalMethods.java b/common/src/main/java/net/blay09/mods/cookingforblockheads/api/InternalMethods.java index ca2bf7a2..006e5145 100644 --- a/common/src/main/java/net/blay09/mods/cookingforblockheads/api/InternalMethods.java +++ b/common/src/main/java/net/blay09/mods/cookingforblockheads/api/InternalMethods.java @@ -20,7 +20,7 @@ public interface InternalMethods { FoodStatsProvider getFoodStatsProvider(); - > void registerKitchenRecipeHandler(Class recipeClass, KitchenRecipeHandler kitchenRecipeHandler); + > void registerKitchenRecipeHandler(Class recipeClass, KitchenRecipeHandler kitchenRecipeHandler); - > KitchenRecipeHandler getKitchenRecipeHandler(T recipe); + > KitchenRecipeHandler getKitchenRecipeHandler(T recipe); } diff --git a/common/src/main/java/net/blay09/mods/cookingforblockheads/api/KitchenRecipeHandler.java b/common/src/main/java/net/blay09/mods/cookingforblockheads/api/KitchenRecipeHandler.java index 8f5906fc..f4f64342 100644 --- a/common/src/main/java/net/blay09/mods/cookingforblockheads/api/KitchenRecipeHandler.java +++ b/common/src/main/java/net/blay09/mods/cookingforblockheads/api/KitchenRecipeHandler.java @@ -2,15 +2,15 @@ import net.blay09.mods.cookingforblockheads.crafting.CraftingContext; import net.minecraft.core.RegistryAccess; -import net.minecraft.world.inventory.CraftingContainer; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeInput; import java.util.List; import java.util.Optional; -public interface KitchenRecipeHandler> { +public interface KitchenRecipeHandler> { int mapToMatrixSlot(T recipe, int ingredientIndex); List> getIngredients(T recipe); diff --git a/common/src/main/java/net/blay09/mods/cookingforblockheads/crafting/AbstractKitchenCraftingRecipeHandler.java b/common/src/main/java/net/blay09/mods/cookingforblockheads/crafting/AbstractKitchenCraftingRecipeHandler.java index 32af9bea..8b8c59f7 100644 --- a/common/src/main/java/net/blay09/mods/cookingforblockheads/crafting/AbstractKitchenCraftingRecipeHandler.java +++ b/common/src/main/java/net/blay09/mods/cookingforblockheads/crafting/AbstractKitchenCraftingRecipeHandler.java @@ -4,11 +4,12 @@ import net.blay09.mods.cookingforblockheads.api.KitchenRecipeHandler; import net.minecraft.core.RegistryAccess; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.crafting.CraftingRecipe; +import net.minecraft.world.item.crafting.CraftingInput; +import net.minecraft.world.item.crafting.Recipe; import java.util.List; -public abstract class AbstractKitchenCraftingRecipeHandler implements KitchenRecipeHandler { +public abstract class AbstractKitchenCraftingRecipeHandler> implements KitchenRecipeHandler { @Override public ItemStack assemble(CraftingContext context, T recipe, List ingredientTokens, RegistryAccess registryAccess) { final var craftingContainer = new TransientHeadlessCraftingContainer(3, 3); diff --git a/common/src/main/java/net/blay09/mods/cookingforblockheads/crafting/CraftingContext.java b/common/src/main/java/net/blay09/mods/cookingforblockheads/crafting/CraftingContext.java index 33573bd1..508d9231 100644 --- a/common/src/main/java/net/blay09/mods/cookingforblockheads/crafting/CraftingContext.java +++ b/common/src/main/java/net/blay09/mods/cookingforblockheads/crafting/CraftingContext.java @@ -10,6 +10,7 @@ import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeHolder; +import net.minecraft.world.item.crafting.RecipeInput; import org.jetbrains.annotations.Nullable; import java.util.HashMap; @@ -28,8 +29,8 @@ public CraftingContext(final Kitchen kitchen, final @Nullable Player player) { itemProcessors = kitchen.getItemProcessors(); } - public CraftingOperation createOperation(RecipeHolder> recipe) { - return new CraftingOperation(this, recipe); + public > CraftingOperation createOperation(RecipeHolder recipe) { + return new CraftingOperation<>(this, recipe ); } public List getItemProviders() { diff --git a/common/src/main/java/net/blay09/mods/cookingforblockheads/crafting/KitchenImpl.java b/common/src/main/java/net/blay09/mods/cookingforblockheads/crafting/KitchenImpl.java index be243fcc..e4a50c51 100644 --- a/common/src/main/java/net/blay09/mods/cookingforblockheads/crafting/KitchenImpl.java +++ b/common/src/main/java/net/blay09/mods/cookingforblockheads/crafting/KitchenImpl.java @@ -5,8 +5,6 @@ import net.blay09.mods.cookingforblockheads.api.Kitchen; import net.blay09.mods.cookingforblockheads.api.KitchenItemProcessor; import net.blay09.mods.cookingforblockheads.api.KitchenItemProvider; -import net.blay09.mods.cookingforblockheads.block.CookingTableBlock; -import net.blay09.mods.cookingforblockheads.block.ModBlocks; import net.blay09.mods.cookingforblockheads.block.entity.CookingTableBlockEntity; import net.blay09.mods.cookingforblockheads.item.ModItems; import net.blay09.mods.cookingforblockheads.kitchen.ContainerKitchenItemProvider; @@ -18,6 +16,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeHolder; +import net.minecraft.world.item.crafting.RecipeInput; import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Blocks; @@ -113,7 +112,7 @@ public boolean canProcess(RecipeType recipeType) { return itemProcessorList.stream().anyMatch(it -> it.canProcess(recipeType)); } - public boolean isRecipeAvailable(RecipeHolder> recipe, CraftingOperation operation) { + public > boolean isRecipeAvailable(RecipeHolder recipe, CraftingOperation operation) { final var isNoFilter = activatingItemStack.is(ModItems.noFilterBook) || (activatingBlockEntity instanceof CookingTableBlockEntity cookingTable && cookingTable.hasNoFilterBook()); if (isNoFilter) { return true; diff --git a/common/src/main/java/net/blay09/mods/cookingforblockheads/crafting/KitchenSmeltingRecipeHandler.java b/common/src/main/java/net/blay09/mods/cookingforblockheads/crafting/KitchenSmeltingRecipeHandler.java index 83da282d..f1b1850b 100644 --- a/common/src/main/java/net/blay09/mods/cookingforblockheads/crafting/KitchenSmeltingRecipeHandler.java +++ b/common/src/main/java/net/blay09/mods/cookingforblockheads/crafting/KitchenSmeltingRecipeHandler.java @@ -6,12 +6,13 @@ import net.minecraft.core.RegistryAccess; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.SingleRecipeInput; import net.minecraft.world.item.crafting.SmeltingRecipe; import java.util.List; import java.util.Optional; -public class KitchenSmeltingRecipeHandler implements KitchenRecipeHandler { +public class KitchenSmeltingRecipeHandler implements KitchenRecipeHandler { @Override public int mapToMatrixSlot(SmeltingRecipe recipe, int ingredientIndex) { return 4; diff --git a/common/src/main/java/net/blay09/mods/cookingforblockheads/menu/KitchenMenu.java b/common/src/main/java/net/blay09/mods/cookingforblockheads/menu/KitchenMenu.java index e639e59c..93c36557 100644 --- a/common/src/main/java/net/blay09/mods/cookingforblockheads/menu/KitchenMenu.java +++ b/common/src/main/java/net/blay09/mods/cookingforblockheads/menu/KitchenMenu.java @@ -3,6 +3,7 @@ import net.blay09.mods.balm.api.Balm; import net.blay09.mods.balm.api.container.DefaultContainer; import net.blay09.mods.cookingforblockheads.CookingForBlockheads; +import net.blay09.mods.cookingforblockheads.api.CookingForBlockheadsAPI; import net.blay09.mods.cookingforblockheads.api.Kitchen; import net.blay09.mods.cookingforblockheads.crafting.CraftableWithStatus; import net.blay09.mods.cookingforblockheads.crafting.CraftingContext; @@ -24,13 +25,11 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; -import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.item.crafting.RecipeInput; -import net.minecraft.world.item.crafting.display.RecipeDisplayEntry; -import net.minecraft.world.item.crafting.display.RecipeDisplayId; -import net.minecraft.world.item.crafting.display.SlotDisplayContext; +import net.minecraft.world.item.crafting.RecipeManager; +import net.minecraft.world.item.crafting.display.*; import org.jetbrains.annotations.Nullable; import java.util.*; @@ -79,7 +78,7 @@ public KitchenMenu(MenuType containerType, int windowId, Player pla for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - final var slot = new CraftMatrixFakeSlot(fakeInventory, j + i * 3, 24 + j * 18, 20 + i * 18); + final var slot = new CraftMatrixFakeSlot(this, fakeInventory, j + i * 3, 24 + j * 18, 20 + i * 18); matrixSlots.add(slot); addSlot(slot); } @@ -242,27 +241,33 @@ public List getAvailableCraftables() { final var context = new CraftingContext(kitchen, player); final var recipesByItemId = CookingForBlockheadsRegistry.getRecipesByItemId(); for (ResourceLocation itemId : recipesByItemId.keySet()) { - for (final var recipe : recipesByItemId.get(itemId)) { - final var resultItem = recipe.value().getResultItem(player.level().registryAccess()); - if (isGroupItem(resultItem)) { - continue; - } - - final var operation = context.createOperation(recipe).prepare(); - if (!kitchen.isRecipeAvailable(recipe, operation)) { - continue; - } - - final var craftableWithStatus = new CraftableWithStatus(resultItem, - operation.getMissingIngredients(), - operation.getMissingIngredientsMask(), - operation.getLockedInputs()); + for (final var recipeHolder : recipesByItemId.get(itemId)) { + final var craftableWithStatus = craftableWithStatusFromRecipe(context, recipeHolder); + if (craftableWithStatus == null) continue; result.compute(itemId, (k, v) -> CraftableWithStatus.best(v, craftableWithStatus)); } } return result.values().stream().toList(); } + private > @Nullable CraftableWithStatus craftableWithStatusFromRecipe(CraftingContext context, RecipeHolder recipeHolder) { + final var recipe = recipeHolder.value(); + final var recipeHandler = CookingForBlockheadsAPI.getKitchenRecipeHandler(recipe); + final var resultItem = recipeHandler.predictResultItem(recipe); + if (isGroupItem(resultItem)) { + return null; + } + + final var operation = context.createOperation(recipeHolder).prepare(); + if (!kitchen.isRecipeAvailable(recipeHolder, operation)) { + return null; + } + + final var missingIngredients = operation.getMissingIngredients(); + final var missingUtensils = operation.getMissingIngredients(); + return new CraftableWithStatus(resultItem, !missingIngredients.isEmpty(), !missingUtensils.isEmpty()); + } + private boolean isGroupItem(ItemStack resultItem) { final var itemId = Balm.getRegistries().getKey(resultItem.getItem()); for (final var group : CookingForBlockheadsRegistry.getGroups()) { @@ -281,7 +286,7 @@ private boolean isGroupItem(ItemStack resultItem) { return false; } - private Collection>> getRecipesFor(ItemStack resultItem) { + private Collection> getRecipesFor(ItemStack resultItem) { final var recipes = new ArrayList<>(CookingForBlockheadsRegistry.getRecipesFor(resultItem)); recipes.addAll(CookingForBlockheadsRegistry.getRecipesInGroup(resultItem)); return recipes; @@ -299,42 +304,42 @@ public void broadcastRecipesForResultItem(ItemStack resultItem) { final var context = new CraftingContext(kitchen, player); final var recipesForResult = getRecipesFor(resultItem); for (final var recipe : recipesForResult) { - final var operation = context.createOperation(recipe).withLockedInputs(lockedInputs).prepare(); - recipeManager.listDisplaysForRecipe(recipe.id(), recipeDisplayEntry -> result.add(new RecipeWithStatus(recipeDisplayEntry, - operation.getMissingIngredients(), - operation.getMissingIngredientsMask(), - operation.getLockedInputs()))); + extracted(recipe, context, recipeManager, result); } this.recipesForSelection = result; Balm.getNetworking().sendTo(player, new SelectionRecipesListMessage(result)); } + private > void extracted(RecipeHolder recipe, CraftingContext context, RecipeManager recipeManager, List result) { + final var operation = context.createOperation(recipe).withLockedInputs(lockedInputs).prepare(); + recipeManager.listDisplaysForRecipe(recipe.id(), recipeDisplayEntry -> result.add(new RecipeWithStatus(recipeDisplayEntry, + operation.getMissingIngredients(), + operation.getMissingIngredientsMask(), + operation.getLockedInputs()))); + } + public void craft(RecipeDisplayId recipeDisplayId, NonNullList lockedInputs, boolean craftFullStack, boolean addToInventory) { final var level = player.level(); - final var recipe = (RecipeHolder>) level.getServer().getRecipeManager().getRecipeFromDisplay(recipeDisplayId).parent(); - if (recipe == null) { + final var serverDisplayInfo = level.getServer().getRecipeManager().getRecipeFromDisplay(recipeDisplayId); + if (serverDisplayInfo == null) { CookingForBlockheads.logger.error("Received invalid recipe from client: {}", recipeDisplayId); return; } + craftRecipe(recipeDisplayId, lockedInputs, craftFullStack, addToInventory, serverDisplayInfo.parent()); + } + + private > void craftRecipe(RecipeDisplayId recipeDisplayId, NonNullList lockedInputs, boolean craftFullStack, boolean addToInventory, RecipeHolder recipe) { if (!kitchen.canProcess(recipe.value().getType())) { CookingForBlockheads.logger.error("Received invalid craft request, unprocessable recipe {}", recipeDisplayId); return; } - var craftable = this.craftables.stream().filter(it -> it.recipe(player) == recipe).findAny().orElse(null); - if (craftable == null) { - craftable = this.recipesForSelection.stream().filter(it -> it.recipe(player) == recipe).findAny().orElse(null); - if (craftable == null) { - CookingForBlockheads.logger.error("Received invalid craft request, unknown recipe {}", recipeDisplayId); - return; - } - } - final var context = new CraftingContext(kitchen, player); final var operation = context.createOperation(recipe).withLockedInputs(lockedInputs); - final var resultItem = recipe.value().getResultItem(level.registryAccess()); + final var recipeHandler = CookingForBlockheadsAPI.getKitchenRecipeHandler(recipe.value()); + final var resultItem = recipeHandler.predictResultItem(recipe.value()); final var repeats = craftFullStack ? resultItem.getMaxStackSize() / resultItem.getCount() : 1; for (int i = 0; i < repeats; i++) { operation.prepare(); @@ -424,36 +429,59 @@ public void updateCraftableSlots() { private void updateMatrixSlots() { final var selectedRecipe = getSelectedRecipe(); if (selectedRecipe != null) { - final var recipe = selectedRecipe.recipe(player); - updateMatrixSlots(recipe.value(), selectedRecipe); + updateMatrixSlots(selectedRecipe); } else { for (int i = 0; i < matrixSlots.size(); i++) { CraftMatrixFakeSlot matrixSlot = matrixSlots.get(i); - matrixSlot.setIngredient(i, Ingredient.EMPTY, ItemStack.EMPTY); + matrixSlot.setIngredient(i, null, ItemStack.EMPTY); matrixSlot.setMissing(true); } } } - private > void updateMatrixSlots(T recipe, RecipeWithStatus status) { - final var ingredients = recipe.getIngredients(); - final var matrix = NonNullList.withSize(9, Ingredient.EMPTY); + private void updateMatrixSlots(RecipeWithStatus recipe) { + final var recipeDisplay = recipe.recipeDisplayEntry().display(); + final var matrix = NonNullList.withSize(9, SlotDisplay.Empty.INSTANCE); final var missingMatrix = new boolean[9]; final var ingredientIndexMatrix = new int[9]; - final var recipeTypeHandler = CookingForBlockheadsRegistry.getKitchenRecipeHandler(recipe); - if (recipeTypeHandler != null) { - for (int i = 0; i < ingredients.size(); i++) { - final var ingredient = ingredients.get(i); - final var matrixSlot = recipeTypeHandler.mapToMatrixSlot(recipe, i); + switch (recipeDisplay) { + case ShapedCraftingRecipeDisplay shapedCraftingRecipeDisplay -> { + final var ingredients = shapedCraftingRecipeDisplay.ingredients(); + for (int i = 0; i < ingredients.size(); i++) { + final var ingredient = ingredients.get(i); + final int recipeWidth = shapedCraftingRecipeDisplay.width(); + final int origX = i % recipeWidth; + final int origY = i / recipeWidth; + final int offsetX = recipeWidth == 1 ? 1 : 0; + int matrixSlot = origY * 3 + origX + offsetX; + matrix.set(matrixSlot, ingredient); + missingMatrix[matrixSlot] = (recipe.missingIngredientsMask() & (1 << i)) == (1 << i); + ingredientIndexMatrix[matrixSlot] = i; + } + } + case ShapelessCraftingRecipeDisplay shapelessCraftingRecipeDisplay -> { + final var ingredients = shapelessCraftingRecipeDisplay.ingredients(); + for (int i = 0; i < ingredients.size(); i++) { + final var ingredient = ingredients.get(i); + matrix.set(i, ingredient); + missingMatrix[i] = (recipe.missingIngredientsMask() & (1 << i)) == (1 << i); + ingredientIndexMatrix[i] = i; + } + } + case FurnaceRecipeDisplay furnaceRecipeDisplay -> { + final var ingredient = furnaceRecipeDisplay.ingredient(); + final var matrixSlot = 4; matrix.set(matrixSlot, ingredient); - missingMatrix[matrixSlot] = (status.missingIngredientsMask() & (1 << i)) == (1 << i); - ingredientIndexMatrix[matrixSlot] = i; + missingMatrix[matrixSlot] = (recipe.missingIngredientsMask() & (1)) == (1); + ingredientIndexMatrix[matrixSlot] = 0; + } + default -> { } } for (int i = 0; i < matrixSlots.size(); i++) { final var matrixSlot = matrixSlots.get(i); - final var lockedInputs = status.lockedInputs(); + final var lockedInputs = recipe.lockedInputs(); final int ingredientIndex = ingredientIndexMatrix[i]; final var lockedInput = lockedInputs.get(ingredientIndex); matrixSlot.setIngredient(ingredientIndex, matrix.get(i), lockedInput); @@ -519,10 +547,6 @@ public RecipeWithStatus getSelectedRecipe() { } public boolean isSelectedSlot(CraftableListingFakeSlot slot) { - final var selectedRecipe = getSelectedRecipe(); - if (selectedRecipe != null) { - // TODO - } return selectedCraftable != null && slot.getCraftable() != null && ItemStack.isSameItemSameComponents(slot.getCraftable().itemStack(), selectedCraftable.itemStack()); @@ -537,7 +561,7 @@ public void setScrollOffsetDirty(boolean dirty) { } public void setRecipesForSelection(List recipes) { - recipesForSelection = recipes.size() > 0 ? recipes : null; + recipesForSelection = !recipes.isEmpty() ? recipes : null; recipesForSelectionIndex = recipesForSelection != null ? Math.max(0, Math.min(recipesForSelection.size() - 1, recipesForSelectionIndex)) : 0; updateMatrixSlots(); diff --git a/common/src/main/java/net/blay09/mods/cookingforblockheads/menu/slot/CraftMatrixFakeSlot.java b/common/src/main/java/net/blay09/mods/cookingforblockheads/menu/slot/CraftMatrixFakeSlot.java index e390e0db..04ba987b 100644 --- a/common/src/main/java/net/blay09/mods/cookingforblockheads/menu/slot/CraftMatrixFakeSlot.java +++ b/common/src/main/java/net/blay09/mods/cookingforblockheads/menu/slot/CraftMatrixFakeSlot.java @@ -1,10 +1,13 @@ package net.blay09.mods.cookingforblockheads.menu.slot; import net.blay09.mods.balm.api.Balm; +import net.blay09.mods.cookingforblockheads.menu.KitchenMenu; import net.minecraft.core.NonNullList; import net.minecraft.world.Container; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.display.SlotDisplay; +import net.minecraft.world.item.crafting.display.SlotDisplayContext; import java.util.Comparator; @@ -13,38 +16,40 @@ public class CraftMatrixFakeSlot extends AbstractFakeSlot { private static final float ITEM_SWITCH_TIME = 40f; private final NonNullList visibleStacks = NonNullList.create(); + private final KitchenMenu menu; private int ingredientIndex; - private Ingredient ingredient; + private SlotDisplay slotDisplay; private float variantTimePassed; private int currentVariantIndex; private boolean isLocked; private boolean missing = true; - public CraftMatrixFakeSlot(Container container, int slotId, int x, int y) { + public CraftMatrixFakeSlot(KitchenMenu menu, Container container, int slotId, int x, int y) { super(container, slotId, x, y); + this.menu = menu; } - public void setIngredient(final int ingredientIndex, final Ingredient ingredient, final ItemStack lockedInput) { + public void setIngredient(final int ingredientIndex, final SlotDisplay slotDisplay, final ItemStack lockedInput) { this.ingredientIndex = ingredientIndex; - final var previousIngredient = this.ingredient; + final var previousIngredient = this.slotDisplay; var effectiveLockedInput = isLocked ? getItem() : ItemStack.EMPTY; if (!lockedInput.isEmpty()) { effectiveLockedInput = lockedInput; } visibleStacks.clear(); - this.ingredient = ingredient; - for (final var itemStack : ingredient.items()) { // TODO probably need to resolve the display here - // TODO if (!itemStack.isEmpty()) { - // TODO itemStack.setCount(1); - // TODO visibleStacks.add(itemStack); - // TODO } + this.slotDisplay = slotDisplay; + final var itemStacks = slotDisplay.resolveForStacks(SlotDisplayContext.fromLevel(menu.player.level())); + for (final var itemStack : itemStacks) { + if (!itemStack.isEmpty()) { + visibleStacks.add(itemStack.copyWithCount(1)); + } } visibleStacks.sort(Comparator.comparing(it -> Balm.getRegistries().getKey(it.getItem()).toString())); variantTimePassed = 0; - if (previousIngredient != ingredient) { + if (previousIngredient != slotDisplay) { currentVariantIndex = 0; } else { currentVariantIndex = !visibleStacks.isEmpty() ? currentVariantIndex % visibleStacks.size() : 0; diff --git a/common/src/main/java/net/blay09/mods/cookingforblockheads/registry/CookingForBlockheadsRegistry.java b/common/src/main/java/net/blay09/mods/cookingforblockheads/registry/CookingForBlockheadsRegistry.java index 81e105e1..bea27b12 100644 --- a/common/src/main/java/net/blay09/mods/cookingforblockheads/registry/CookingForBlockheadsRegistry.java +++ b/common/src/main/java/net/blay09/mods/cookingforblockheads/registry/CookingForBlockheadsRegistry.java @@ -22,11 +22,11 @@ public class CookingForBlockheadsRegistry { - private static final Multimap>> recipesByItemId = ArrayListMultimap.create(); - private static final Multimap>> recipesByGroup = ArrayListMultimap.create(); + private static final Multimap> recipesByItemId = ArrayListMultimap.create(); + private static final Multimap> recipesByGroup = ArrayListMultimap.create(); private static final List sortButtons = new ArrayList<>(); private static final Map ovenFuelItems = new HashMap<>(); - private static final Map>, KitchenRecipeHandler>> kitchenRecipeHandlers = new HashMap<>(); + private static final Map>, KitchenRecipeHandler> kitchenRecipeHandlers = new HashMap<>(); public static void initialize(BalmEvents events) { events.onEvent(ServerReloadFinishedEvent.class, @@ -51,14 +51,14 @@ private static > void loadRecipesByTy final var resultItem = recipeHandler.predictResultItem(recipe.value()); if (isEligibleResultItem(resultItem)) { final var itemId = Balm.getRegistries().getKey(resultItem.getItem()); - recipesByItemId.put(itemId, (RecipeHolder>) recipe); + recipesByItemId.put(itemId, recipe); final var groups = getGroups(); for (final var group : groups) { for (final var ingredient : group.getChildren()) { if (ingredient.test(resultItem)) { final var groupItemId = Balm.getRegistries().getKey(group.getParentItem()); - recipesByGroup.put(groupItemId, (RecipeHolder>) recipe); + recipesByGroup.put(groupItemId, recipe); break; } } @@ -83,12 +83,12 @@ private static boolean isEligibleRecipe(RecipeHolder> void registerKitchenRecipeHandler(Class recipeType, KitchenRecipeHandler handler) { + public static > void registerKitchenRecipeHandler(Class recipeType, KitchenRecipeHandler handler) { kitchenRecipeHandlers.put(recipeType, handler); } @SuppressWarnings("unchecked") - public static , V extends KitchenRecipeHandler> V getKitchenRecipeHandler(T recipe) { + public static , V extends KitchenRecipeHandler> V getKitchenRecipeHandler(T recipe) { for (Class> handlerClass : kitchenRecipeHandlers.keySet()) { if (handlerClass.isAssignableFrom(recipe.getClass())) { return (V) kitchenRecipeHandlers.get(handlerClass); @@ -119,17 +119,17 @@ public static int getOvenFuelTime(ItemStack itemStack) { return 0; } - public static Collection>> getRecipesFor(ItemStack resultItem) { + public static Collection> getRecipesFor(ItemStack resultItem) { final var itemId = Balm.getRegistries().getKey(resultItem.getItem()); return recipesByItemId.get(itemId); } - public static Collection>> getRecipesInGroup(ItemStack resultItem) { + public static Collection> getRecipesInGroup(ItemStack resultItem) { final var itemId = Balm.getRegistries().getKey(resultItem.getItem()); return recipesByGroup.get(itemId); } - public static Multimap>> getRecipesByItemId() { + public static Multimap> getRecipesByItemId() { return recipesByItemId; } }