diff --git a/src/main/java/twilightforest/inventory/UncrafterPlaceRecipe.java b/src/main/java/twilightforest/inventory/UncrafterPlaceRecipe.java deleted file mode 100644 index da75418ba4..0000000000 --- a/src/main/java/twilightforest/inventory/UncrafterPlaceRecipe.java +++ /dev/null @@ -1,156 +0,0 @@ -package twilightforest.inventory; - -import com.google.common.collect.Lists; -import it.unimi.dsi.fastutil.ints.IntArrayList; -import it.unimi.dsi.fastutil.ints.IntList; -import net.minecraft.network.protocol.game.ClientboundPlaceGhostRecipePacket; -import net.minecraft.recipebook.ServerPlaceRecipe; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.player.StackedContents; -import net.minecraft.world.inventory.RecipeBookMenu; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.crafting.*; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -public class UncrafterPlaceRecipe> extends ServerPlaceRecipe implements UncraftingPlaceRecipe { - // Slots 0 & 1 are Uncrafting input & crafting output - // Slots 2 to 10 are Uncrafting matrix - // Slots 11 to 19 are Crafting matrix - private static final int matrixOffset = 11; - - public UncrafterPlaceRecipe(RecipeBookMenu menu) { - super(menu); - } - - @Override - public void recipeClicked(ServerPlayer player, @Nullable RecipeHolder recipe, boolean placeAll) { - if (recipe != null && player.getRecipeBook().contains(recipe)) { - this.inventory = player.getInventory(); - if (this.tryClearGrid() || player.isCreative()) { - this.stackedContents.clear(); - player.getInventory().fillStackedContents(this.stackedContents); - this.menu.fillCraftSlotsStackedContents(this.stackedContents); - if (this.stackedContents.canCraft(recipe.value(), null)) { - this.handleRecipeClicked(recipe, placeAll); - } else { - this.clearGrid(); - player.connection.send(new ClientboundPlaceGhostRecipePacket(player.containerMenu.containerId, recipe)); - } - - player.getInventory().setChanged(); - } - } - } - - @Override - protected void handleRecipeClicked(RecipeHolder recipeHolder, boolean placeAll) { - boolean flag = this.menu.recipeMatches(recipeHolder); - int i = this.stackedContents.getBiggestCraftableStack(recipeHolder, null); - if (flag) { - for (int slot = 0; slot < this.menu.getSize(); ++slot) { - if (slot != this.menu.getResultSlotIndex()) { - ItemStack itemstack = this.menu.getSlot(slot).getItem(); - if (!itemstack.isEmpty() && Math.min(i, itemstack.getMaxStackSize()) < itemstack.getCount() + 1) { - return; - } - } - } - } - - int j1 = this.getStackSize(placeAll, i, flag); - IntList intlist = new IntArrayList(); - if (this.stackedContents.canCraft(recipeHolder.value(), intlist, j1)) { - int k = j1; - - for (int l : intlist) { - int i1 = StackedContents.fromStackingIndex(l).getMaxStackSize(); - if (i1 < k) { - k = i1; - } - } - - if (this.stackedContents.canCraft(recipeHolder.value(), intlist, k)) { - this.clearGrid(); - this.placeRecipe(this.menu.getGridWidth(), this.menu.getGridHeight(), this.menu.getResultSlotIndex(), recipeHolder, intlist.iterator(), k); - } - } - } - - @Override - protected int getStackSize(boolean placeAll, int maxPossible, boolean recipeMatches) { - int i = 1; - if (placeAll) { - i = maxPossible; - } else if (recipeMatches) { - i = 64; - - for (int j = 0; j < this.menu.getGridWidth() * this.menu.getGridHeight(); ++j) { - ItemStack itemStack = this.menu.getSlot(j + matrixOffset).getItem(); - if (!itemStack.isEmpty() && i > itemStack.getCount()) { - i = itemStack.getCount(); - } - } - - if (i < 64) { - ++i; - } - } - - return i; - } - - private int getAmountOfFreeSlotsInInventory() { - int i = 0; - - for (ItemStack itemstack : this.inventory.items) { - if (itemstack.isEmpty()) { - ++i; - } - } - - return i; - } - - private boolean tryClearGrid() { - List list = Lists.newArrayList(); - int i = this.getAmountOfFreeSlotsInInventory(); - - if (i > 0) { - // Uncrafting input slot - ItemStack itemstack = this.menu.getSlot(0).getItem().copy(); - if (!itemstack.isEmpty()) list.add(itemstack); - } - - for (int slotIndex = 0; slotIndex < this.menu.getGridWidth() * this.menu.getGridHeight(); ++slotIndex) { - ItemStack itemstack = this.menu.getSlot(slotIndex + matrixOffset).getItem().copy(); - if (!itemstack.isEmpty()) { - int k = this.inventory.getSlotWithRemainingSpace(itemstack); - if (k == -1 && list.size() <= i) { - for (ItemStack itemstack1 : list) { - if (ItemStack.isSameItem(itemstack1, itemstack) - && itemstack1.getCount() != itemstack1.getMaxStackSize() - && itemstack1.getCount() + itemstack.getCount() <= itemstack1.getMaxStackSize()) { - itemstack1.grow(itemstack.getCount()); - itemstack.setCount(0); - break; - } - } - - if (!itemstack.isEmpty()) { - if (list.size() >= i) { - return false; - } - - list.add(itemstack); - } - } else if (k == -1) { - return false; - } - } - } - - return true; - } -} diff --git a/src/main/java/twilightforest/inventory/UncraftingContainer.java b/src/main/java/twilightforest/inventory/UncraftingContainer.java index d308685891..cbaf6e06b6 100644 --- a/src/main/java/twilightforest/inventory/UncraftingContainer.java +++ b/src/main/java/twilightforest/inventory/UncraftingContainer.java @@ -2,6 +2,7 @@ import net.minecraft.core.NonNullList; import net.minecraft.world.Container; +import net.minecraft.world.entity.ContainerUser; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import twilightforest.config.TFConfig; @@ -76,8 +77,7 @@ public int getMaxStackSize() { } @Override - public void setChanged() { - } + public void setChanged() {} @Override public boolean stillValid(Player player) { @@ -85,12 +85,10 @@ public boolean stillValid(Player player) { } @Override - public void startOpen(Player player) { - } + public void startOpen(ContainerUser containerUser) {} @Override - public void stopOpen(Player player) { - } + public void stopOpen(ContainerUser containerUser) {} @Override public boolean canPlaceItem(int index, ItemStack stack) { diff --git a/src/main/java/twilightforest/inventory/UncraftingMenu.java b/src/main/java/twilightforest/inventory/UncraftingMenu.java index 9f485934a5..7ae3dc97cd 100644 --- a/src/main/java/twilightforest/inventory/UncraftingMenu.java +++ b/src/main/java/twilightforest/inventory/UncraftingMenu.java @@ -2,27 +2,31 @@ import it.unimi.dsi.fastutil.objects.Object2IntMap; import net.minecraft.core.Holder; +import net.minecraft.core.HolderLookup; import net.minecraft.core.NonNullList; import net.minecraft.core.component.DataComponents; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.tags.ItemTags; +import net.minecraft.util.context.ContextMap; import net.minecraft.world.Container; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.entity.player.StackedContents; +import net.minecraft.world.entity.player.StackedItemContents; import net.minecraft.world.inventory.*; -import net.minecraft.world.item.ArmorItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.crafting.*; import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.ItemEnchantments; -import net.minecraft.world.level.GameRules; +import net.minecraft.world.item.equipment.Equippable; import net.minecraft.world.level.Level; +import net.minecraft.world.level.gamerules.GameRules; import net.neoforged.fml.loading.FMLLoader; import net.neoforged.neoforge.common.Tags; -import org.jetbrains.annotations.NotNull; +import net.neoforged.neoforge.server.ServerLifecycleHooks; import org.jetbrains.annotations.Nullable; import twilightforest.TwilightForestMod; import twilightforest.config.TFConfig; @@ -38,7 +42,7 @@ import java.util.*; -public class UncraftingMenu extends RecipeBookMenu> { +public class UncraftingMenu extends RecipeBookMenu { private static final String TAG_MARKER = "TwilightForestMarker"; @@ -108,7 +112,7 @@ public UncraftingMenu(int id, Inventory inventory, Level level, ContainerLevelAc this.slotsChanged(this.assemblyMatrix); - if (!FMLLoader.isProduction()) { + if (!FMLLoader.getCurrent().isProduction()) { // Debug slot listing NonNullList slots = this.slots; @@ -190,7 +194,7 @@ public void slotsChanged(Container inventory) { } // store number of items this recipe produces (and thus how many input items are required for uncrafting) - this.uncraftingMatrix.numberOfInputItems = recipe instanceof UncraftingRecipe uncraftingRecipe ? uncraftingRecipe.getCount() : recipe.getResultItem(this.level.registryAccess()).getCount(); //Uncrafting recipes need this method call + this.uncraftingMatrix.numberOfInputItems = recipe instanceof UncraftingRecipe uncraftingRecipe ? uncraftingRecipe.getCount() : recipe.display().getFirst().result().resolveForFirstStack(ContextMap.EMPTY).getCount(); //Uncrafting recipes need this method call this.uncraftingMatrix.uncraftingCost = this.calculateUncraftingCost(); this.uncraftingMatrix.recraftingCost = 0; @@ -236,7 +240,7 @@ public void slotsChanged(Container inventory) { ItemStack result = this.tinkerResult.getItem(0); if (!result.isEmpty() && isValidMatchForInput(input, result)) { - if (result.getItem().isEnchantable(result)) { + if (result.isEnchantable()) { //store copy of input enchants ItemEnchantments.Mutable enchants = new ItemEnchantments.Mutable(input.getOrDefault(DataComponents.ENCHANTMENTS, ItemEnchantments.EMPTY)); //add all resulting item enchants to the list. This allows pre-enchanted gear to keep its enchants @@ -273,7 +277,7 @@ public static void unmarkStack(ItemStack stack) { } public static boolean isIngredientProblematic(ItemStack ingredient) { - return (!ingredient.isEmpty() && ingredient.getItem().hasCraftingRemainingItem(ingredient)) || ingredient.is(Items.BARRIER); + return (!ingredient.isEmpty() && ingredient.getItem().getCraftingRemainder(ingredient) != null) || ingredient.is(Items.BARRIER); } private static ItemStack normalizeIngredient(ItemStack ingredient) { @@ -283,25 +287,38 @@ private static ItemStack normalizeIngredient(ItemStack ingredient) { return ingredient; } - private static Recipe[] getRecipesFor(ItemStack inputStack, Level world) { - + private static Recipe[] getRecipesFor(ItemStack inputStack, Level level) { List> recipes = new ArrayList<>(); + if (inputStack.isEmpty()) return new Recipe[0]; + + HolderLookup.Provider registryAccess = level.registryAccess(); + var server = ServerLifecycleHooks.getCurrentServer(); + if (server == null) return new Recipe[0]; + RecipeManager recipeManager = server.getRecipeManager(); + + for (RecipeHolder recipeHolder : recipeManager.getRecipes()) { + Recipe recipe = recipeHolder.value(); + + if (isRecipeSupported(recipe) && + !recipe.placementInfo().isImpossibleToPlace() && + !recipe.placementInfo().ingredients().isEmpty()) { - if (!inputStack.isEmpty()) { - for (RecipeHolder recipe : world.getRecipeManager().getRecipes()) { - if (isRecipeSupported(recipe.value()) && - !recipe.value().isIncomplete() && - recipe.value().canCraftInDimensions(3, 3) && - !recipe.value().getIngredients().isEmpty() && - matches(inputStack, recipe.value().getResultItem(world.registryAccess())) && - TFConfig.reverseRecipeBlacklist == TFConfig.disableUncraftingRecipes.contains(recipe.id().toString())) { - if (TFConfig.flipUncraftingModIdList == TFConfig.blacklistedUncraftingModIds.contains(recipe.id().getNamespace())) { - recipes.add(recipe.value()); + ItemStack resultStackItem = recipe.display().getFirst().result().resolveForFirstStack(ContextMap.EMPTY); + + if (matches(inputStack, resultStackItem)) { + if (TFConfig.reverseRecipeBlacklist == TFConfig.disableUncraftingRecipes.contains(recipeHolder.id().toString())) { + if (TFConfig.flipUncraftingModIdList == TFConfig.blacklistedUncraftingModIds.contains(recipeHolder.id().identifier().getNamespace())) { + recipes.add(recipe); + } } } } - for (RecipeHolder uncraftingRecipe : world.getRecipeManager().getAllRecipesFor(TFRecipes.UNCRAFTING_RECIPE.get())) { - if (uncraftingRecipe.value().isItemStackAnIngredient(inputStack)) recipes.add(uncraftingRecipe.value()); + } + + for (RecipeHolder recipe : recipeManager.recipeMap().byType(TFRecipes.UNCRAFTING_RECIPE.get())) { + UncraftingRecipe uncraftingRecipe = recipe.value(); + if (uncraftingRecipe.isItemStackAnIngredient(inputStack)) { + recipes.add(uncraftingRecipe); } } @@ -316,25 +333,25 @@ private static boolean matches(ItemStack input, ItemStack output) { return input.is(output.getItem()) && input.getCount() >= output.getCount(); } - @SuppressWarnings({"unchecked", "rawtypes"}) - private static RecipeHolder[] getRecipesFor(CraftingInput input, Level level) { - return level.getRecipeManager().getRecipesFor(RecipeType.CRAFTING, input, level).toArray(new RecipeHolder[0]); + private static List> getRecipesFor(CraftingInput input, Level level) { + if (!(level instanceof ServerLevel serverLevel)) return List.of(); + return serverLevel.getServer().getRecipeManager().recipeMap().getRecipesFor(RecipeType.CRAFTING, input, level).toList(); } private void chooseRecipe(CraftingInput input) { + List> recipes = getRecipesFor(input, this.level); - RecipeHolder[] recipes = getRecipesFor(input, this.level); - - if (recipes.length == 0) { + if (recipes.isEmpty()) { this.tinkerResult.setItem(0, ItemStack.EMPTY); return; } - RecipeHolder recipe = recipes[Math.floorMod(this.recipeInCycle, recipes.length)]; + RecipeHolder recipe = recipes.get(Math.floorMod(this.recipeInCycle, recipes.size())); + MinecraftServer server = this.level instanceof ServerLevel serverLevel ? serverLevel.getServer() : null; - if (recipe != null && (!this.level.getGameRules().getBoolean(GameRules.RULE_LIMITED_CRAFTING) || ((ServerPlayer) this.player).getRecipeBook().contains(recipe.id()))) { + if (recipe != null && server != null && (!server.getGameRules().get(GameRules.LIMITED_CRAFTING) || ((ServerPlayer) this.player).getRecipeBook().contains(recipe.id()))) { this.tinkerResult.setRecipeUsed(recipe); - this.tinkerResult.setItem(0, recipe.value().assemble(input, this.level.registryAccess())); + this.tinkerResult.setItem(0, recipe.value().assemble(input)); } else { this.tinkerResult.setItem(0, ItemStack.EMPTY); } @@ -369,8 +386,13 @@ private static boolean isValidMatchForInput(ItemStack inputStack, ItemStack resu return true; } - if (inputStack.getItem() instanceof ArmorItem input && resultStack.getItem() instanceof ArmorItem result) { - return input.getEquipmentSlot() == result.getEquipmentSlot(); + if (inputStack.has(DataComponents.EQUIPPABLE) && resultStack.has(DataComponents.EQUIPPABLE)) { + Equippable inputEquip = inputStack.get(DataComponents.EQUIPPABLE); + Equippable resultEquip = resultStack.get(DataComponents.EQUIPPABLE); + + if (inputEquip != null && resultEquip != null) { + return inputEquip.slot() == resultEquip.slot(); + } } return false; @@ -407,7 +429,7 @@ private int calculateRecraftingCost() { } // okay, if we're here the input item must be enchanted, and we are repairing or recrafting it - if (!output.getItem().isEnchantable(output)) return 0; // Assuming the above comment is correct, we check this here and return 0 if true + if (!output.isEnchantable()) return 0; // Assuming the above comment is correct, we check this here and return 0 if true int cost = 0; @@ -456,13 +478,13 @@ private static int getWeightModifier(Enchantment ench) { } @Override - public void clicked(int slotNum, int mouseButton, ClickType clickType, Player player) { + public void clicked(int slotNum, int mouseButton, ContainerInput clickType, Player player) { // if the player is trying to take an item out of the assembly grid, and the assembly grid is empty, take the item from the uncrafting grid. if (slotNum > 0 && this.getSlotContainer(slotNum) == this.assemblyMatrix && player.containerMenu.getCarried().isEmpty() && !this.slots.get(slotNum).hasItem()) { // is the assembly matrix empty? - if (this.assemblyMatrix.isEmpty() && (clickType != ClickType.SWAP || player.getInventory().getItem(mouseButton).isEmpty())) { + if (this.assemblyMatrix.isEmpty() && (clickType != ContainerInput.SWAP || player.getInventory().getItem(mouseButton).isEmpty())) { slotNum -= 9; } } @@ -501,7 +523,6 @@ public void clicked(int slotNum, int mouseButton, ClickType clickType, Player pl } } - @NotNull private Container getSlotContainer(int slotNum) { return this.slots.get(slotNum).container; } @@ -554,7 +575,7 @@ public ItemStack quickMoveStack(Player player, int slotNum) { } slot.onQuickCraft(itemstack1, itemstack); } else if (slotNum == 1) { - this.positionData.execute((p_39378_, p_39379_) -> itemstack1.getItem().onCraftedBy(itemstack1, p_39378_, player)); + this.positionData.execute((_, _) -> itemstack1.getItem().onCraftedBy(itemstack1, player)); if (!this.moveItemStackTo(itemstack1, 20, 56, true)) { return ItemStack.EMPTY; } @@ -599,10 +620,10 @@ public void removed(Player player) { } private ItemStack[] getIngredients(Recipe recipe) { - ItemStack[] stacks = new ItemStack[recipe.getIngredients().size()]; + ItemStack[] stacks = new ItemStack[recipe.placementInfo().ingredients().size()]; - for (int i = 0; i < recipe.getIngredients().size(); i++) { - ItemStack[] matchingStacks = Arrays.stream(recipe.getIngredients().get(i).getItems()).filter(s -> !s.is(TFItemTags.BANNED_UNCRAFTING_INGREDIENTS)).toArray(ItemStack[]::new); + for (int i = 0; i < recipe.placementInfo().ingredients().size(); i++) { + ItemStack[] matchingStacks = recipe.placementInfo().ingredients().get(i).getValues().stream().filter(s -> !s.is(TFItemTags.BANNED_UNCRAFTING_INGREDIENTS)).map(h -> h.value().getDefaultInstance()).toArray(ItemStack[]::new); stacks[i] = matchingStacks.length > 0 ? matchingStacks[Math.floorMod(this.ingredientsInCycle, matchingStacks.length)] : ItemStack.EMPTY; } @@ -615,55 +636,17 @@ public boolean stillValid(Player player) { } @Override - public void fillCraftSlotsStackedContents(StackedContents stackedContents) { - this.assemblyMatrix.fillStackedContents(stackedContents); - } - - @Override - public void clearCraftingContent() { - this.tinkerInput.clearContent(); - this.assemblyMatrix.clearContent(); - this.tinkerResult.clearContent(); - } - - @Override - public int getResultSlotIndex() { - return 1; // tinkerResult slot - } - - @Override - public int getGridWidth() { - return this.assemblyMatrix.getWidth(); + public PostPlaceAction handlePlacement(boolean b, boolean b1, RecipeHolder recipeHolder, ServerLevel serverLevel, Inventory inventory) { + return PostPlaceAction.PLACE_GHOST_RECIPE; } @Override - public int getGridHeight() { - return this.assemblyMatrix.getHeight(); - } - - @Override - public int getSize() { - return 20; + public void fillCraftSlotsStackedContents(StackedItemContents stackedItemContents) { + this.assemblyMatrix.fillStackedContents(stackedItemContents); } @Override public RecipeBookType getRecipeBookType() { return RecipeBookType.CRAFTING; } - - @Override - public boolean shouldMoveToInventory(int slot) { - return slot == 0 || (11 <= slot && slot <= 19); - } - - @Override - public boolean recipeMatches(RecipeHolder> recipeHolder) { - return recipeHolder.value().matches(this.assemblyMatrix.asCraftInput(), this.player.level()); - } - - @SuppressWarnings({"unchecked", "rawtypes", "RedundantSuppression"}) - @Override - public void handlePlacement(boolean placeAll, RecipeHolder recipe, ServerPlayer player) { - new UncrafterPlaceRecipe<>(this).recipeClicked(player, (RecipeHolder>) recipe, placeAll); - } } diff --git a/src/main/java/twilightforest/inventory/UncraftingPlaceRecipe.java b/src/main/java/twilightforest/inventory/UncraftingPlaceRecipe.java index ea4976282d..1b642b76b3 100644 --- a/src/main/java/twilightforest/inventory/UncraftingPlaceRecipe.java +++ b/src/main/java/twilightforest/inventory/UncraftingPlaceRecipe.java @@ -1,25 +1,28 @@ package twilightforest.inventory; -import net.minecraft.recipebook.PlaceRecipe; +import net.minecraft.recipebook.PlaceRecipeHelper; import net.minecraft.util.Mth; -import net.minecraft.world.item.crafting.RecipeHolder; +import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.ShapedRecipe; import java.util.Iterator; //modified version of PlaceRecipe that uses the correct slots for the uncrafting table -public interface UncraftingPlaceRecipe extends PlaceRecipe { +public interface UncraftingPlaceRecipe extends PlaceRecipeHelper { // Slots 0 & 1 are Uncrafting input & crafting output // Slots 2 to 10 are Uncrafting matrix // Slots 11 to 19 are Crafting matrix int matrixOffset = 11; - @Override - default void placeRecipe(int width, int height, int outputSlot, RecipeHolder recipe, Iterator ingredients, int maxAmount) { + void addItemToSlot(C ingredient, int slotIndex, int gridY, int gridX); + + default void placeRecipe(int width, int height, Recipe recipe, Iterable entries, Output output) { int widthModified = width; int heightModified = height; - if (recipe.value() instanceof ShapedRecipe shapedRecipe) { + Iterator ingredients = entries.iterator(); + + if (recipe instanceof ShapedRecipe shapedRecipe) { widthModified = shapedRecipe.getWidth(); heightModified = shapedRecipe.getHeight(); } @@ -49,7 +52,7 @@ default void placeRecipe(int width, int height, int outputSlot, RecipeHolder } if (xOverfitted) { - this.addItemToSlot(ingredients.next(), slotIndex, maxAmount, gridY, gridX); + this.addItemToSlot(ingredients.next(), slotIndex, gridY, gridX); } else if (o == gridX) { slotIndex += width - gridX; break; diff --git a/src/main/java/twilightforest/inventory/slot/UncraftingResultSlot.java b/src/main/java/twilightforest/inventory/slot/UncraftingResultSlot.java index f28f7f7c8e..0d789220af 100644 --- a/src/main/java/twilightforest/inventory/slot/UncraftingResultSlot.java +++ b/src/main/java/twilightforest/inventory/slot/UncraftingResultSlot.java @@ -6,10 +6,7 @@ import net.minecraft.world.inventory.CraftingContainer; import net.minecraft.world.inventory.ResultSlot; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.crafting.CraftingInput; -import net.minecraft.world.item.crafting.CraftingRecipe; -import net.minecraft.world.item.crafting.RecipeHolder; -import net.minecraft.world.item.crafting.RecipeType; +import net.minecraft.world.item.crafting.*; import net.neoforged.neoforge.common.CommonHooks; import twilightforest.inventory.UncraftingContainer; import twilightforest.inventory.InventoryUtil; @@ -37,14 +34,16 @@ public UncraftingResultSlot(Player player, Container input, Container uncrafting @Override public void onTake(Player player, ItemStack stack) { + if (!(player.level().recipeAccess() instanceof RecipeManager recipeManager)) return; + // let's see, if the assembly matrix can produce this item, then it's a normal recipe, if not, it's combined. Will that work? boolean combined = true; //clear the temp map, just in case this.tempRemainderMap.clear(); - for (RecipeHolder recipe : player.level().getRecipeManager().getRecipesFor(RecipeType.CRAFTING, this.assemblyMatrix.asCraftInput(), this.player.level())) { - if (ItemStack.isSameItemSameComponents(recipe.value().getResultItem(player.level().registryAccess()), stack)) { + for (RecipeHolder recipe : recipeManager.recipeMap().getRecipesFor(RecipeType.CRAFTING, this.assemblyMatrix.asCraftInput(), this.player.level()).toList()) { + if (ItemStack.isSameItemSameComponents(recipe.value().assemble(this.assemblyMatrix.asCraftInput()), stack)) { combined = false; break; } @@ -78,7 +77,7 @@ public void onTake(Player player, ItemStack stack) { int i = positioned.left(); int j = positioned.top(); CommonHooks.setCraftingPlayer(player); - NonNullList remainingItems = player.level().getRecipeManager().getRemainingItemsFor(RecipeType.CRAFTING, input, player.level()); + NonNullList remainingItems = recipeManager.getRecipeFor(RecipeType.CRAFTING, input, player.level()).get().value().getRemainingItems(input); CommonHooks.setCraftingPlayer(null); for (int k = 0; k < input.height(); k++) {