diff --git a/src/main/java/blusunrize/immersiveengineering/common/blocks/metal/CrafterPatternInventory.java b/src/main/java/blusunrize/immersiveengineering/common/blocks/metal/CrafterPatternInventory.java index 3b38fbb26b..bd706d67fd 100644 --- a/src/main/java/blusunrize/immersiveengineering/common/blocks/metal/CrafterPatternInventory.java +++ b/src/main/java/blusunrize/immersiveengineering/common/blocks/metal/CrafterPatternInventory.java @@ -10,6 +10,7 @@ import blusunrize.immersiveengineering.api.tool.assembler.AssemblerHandler; import blusunrize.immersiveengineering.api.tool.assembler.RecipeQuery; +import blusunrize.immersiveengineering.common.util.InventoryCraftingFalse; import blusunrize.immersiveengineering.common.util.Utils; import net.minecraft.core.HolderLookup.Provider; import net.minecraft.core.NonNullList; @@ -36,7 +37,7 @@ public void recalculateOutput(@Nullable Level level) { if(level==null) return; - CraftingInput invC = Utils.InventoryCraftingFalse.createFilledCraftingInventory(3, 3, inv).asCraftInput(); + CraftingInput invC = InventoryCraftingFalse.createFilledCraftingInventory(3, 3, inv); this.recipe = Utils.findCraftingRecipe(invC, level).map(RecipeHolder::value).orElse(null); this.inv.set(9, recipe!=null?recipe.assemble(invC, level.registryAccess()): ItemStack.EMPTY); } diff --git a/src/main/java/blusunrize/immersiveengineering/common/blocks/multiblocks/logic/AssemblerLogic.java b/src/main/java/blusunrize/immersiveengineering/common/blocks/multiblocks/logic/AssemblerLogic.java index dba02bd37b..5d1d4668b2 100644 --- a/src/main/java/blusunrize/immersiveengineering/common/blocks/multiblocks/logic/AssemblerLogic.java +++ b/src/main/java/blusunrize/immersiveengineering/common/blocks/multiblocks/logic/AssemblerLogic.java @@ -27,6 +27,7 @@ import blusunrize.immersiveengineering.common.config.IEServerConfig; import blusunrize.immersiveengineering.common.fluids.ArrayFluidHandler; import blusunrize.immersiveengineering.common.util.IESounds; +import blusunrize.immersiveengineering.common.util.InventoryCraftingFalse; import blusunrize.immersiveengineering.common.util.Utils; import blusunrize.immersiveengineering.common.util.inventory.SlotwiseItemHandler; import blusunrize.immersiveengineering.common.util.inventory.SlotwiseItemHandler.IOConstraint; @@ -148,7 +149,7 @@ private List craftRecipes(IMultiblockContext ctx) this.consumeIngredients(state, queries, availableStacks, true, sources); NonNullList remainingItems = pattern.recipe.getRemainingItems( - Utils.InventoryCraftingFalse.createFilledCraftingInventory(3, 3, sources.gridItems).asCraftInput() + InventoryCraftingFalse.createFilledCraftingInventory(3, 3, sources.gridItems) ); for(int i = 0; i < remainingItems.size(); i++) { diff --git a/src/main/java/blusunrize/immersiveengineering/common/crafting/DefaultAssemblerAdapter.java b/src/main/java/blusunrize/immersiveengineering/common/crafting/DefaultAssemblerAdapter.java index 82530b5871..2a0f3b5cd8 100644 --- a/src/main/java/blusunrize/immersiveengineering/common/crafting/DefaultAssemblerAdapter.java +++ b/src/main/java/blusunrize/immersiveengineering/common/crafting/DefaultAssemblerAdapter.java @@ -12,7 +12,7 @@ import blusunrize.immersiveengineering.api.tool.assembler.AssemblerHandler.IRecipeAdapter; import blusunrize.immersiveengineering.api.tool.assembler.RecipeQuery; import blusunrize.immersiveengineering.common.util.FakePlayerUtil; -import blusunrize.immersiveengineering.common.util.Utils; +import blusunrize.immersiveengineering.common.util.InventoryCraftingFalse; import net.minecraft.core.NonNullList; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.CraftingInput; @@ -31,27 +31,25 @@ public class DefaultAssemblerAdapter implements IRecipeAdapter getQueriedInputs(Recipe recipe, NonNullList input, Level world) { NonNullList ingred = recipe.getIngredients(); + CraftingInput craftingInput = InventoryCraftingFalse.createFilledCraftingInventory(3, 3, input); // Check that the ingredients roughly match what the recipe actually requires. // This is necessary to prevent infinite crafting for recipes like FireworkRocketRecipe which don't return // meaningful values in getIngredients. NonNullList ingredientsForMatching = NonNullList.create(); - List inputList = input.subList(0, input.size()-1); for(Ingredient i : ingred) if(!i.isEmpty()) ingredientsForMatching.add(i); - while(ingredientsForMatching.size() < inputList.size()) + while(ingredientsForMatching.size() < craftingInput.size()) ingredientsForMatching.add(Ingredient.EMPTY); CommonHooks.setCraftingPlayer(FakePlayerUtil.getFakePlayer(world)); - int[] ingredientAssignment = RecipeMatcher.findMatches(inputList, ingredientsForMatching); + int[] ingredientAssignment = RecipeMatcher.findMatches(craftingInput.items(), ingredientsForMatching); CommonHooks.setCraftingPlayer(null); // Collect remaining items - NonNullList remains = recipe.getRemainingItems( - Utils.InventoryCraftingFalse.createFilledCraftingInventory(3, 3, input).asCraftInput() - ); + NonNullList remains = recipe.getRemainingItems(craftingInput); List queries = new ArrayList<>(); - for(int i = 0; i < inputList.size(); i++) + for(int i = 0; i < craftingInput.size(); i++) { final RecipeQuery query; if(ingredientAssignment!=null) @@ -63,7 +61,7 @@ public List getQueriedInputs(Recipe recipe, NonNullL ); else // Otherwise request the exact stacks used in the input - query = AssemblerHandler.createQueryFromItemStack(input.get(i), remains.get(i)); + query = AssemblerHandler.createQueryFromItemStack(craftingInput.getItem(i), remains.get(i)); if(query!=null) queries.add(query); } diff --git a/src/main/java/blusunrize/immersiveengineering/common/crafting/MetalPressPackingRecipes.java b/src/main/java/blusunrize/immersiveengineering/common/crafting/MetalPressPackingRecipes.java index 173173b018..d4b1df9c60 100644 --- a/src/main/java/blusunrize/immersiveengineering/common/crafting/MetalPressPackingRecipes.java +++ b/src/main/java/blusunrize/immersiveengineering/common/crafting/MetalPressPackingRecipes.java @@ -17,7 +17,7 @@ import blusunrize.immersiveengineering.api.crafting.TagOutput; import blusunrize.immersiveengineering.api.crafting.cache.CachedRecipeList; import blusunrize.immersiveengineering.common.register.IEItems.Molds; -import blusunrize.immersiveengineering.common.util.Utils; +import blusunrize.immersiveengineering.common.util.InventoryCraftingFalse; import com.mojang.datafixers.util.Pair; import net.minecraft.core.NonNullList; import net.minecraft.core.RegistryAccess; @@ -206,9 +206,9 @@ else if(UNPACK_ID.equals(id)) public static Pair, ItemStack> getPackedOutput(int gridSize, ItemStack stack, Level world) { - CraftingInput invC = Utils.InventoryCraftingFalse.createFilledCraftingInventory( + CraftingInput invC = InventoryCraftingFalse.createFilledCraftingInventory( gridSize, gridSize, NonNullList.withSize(gridSize*gridSize, stack.copy()) - ).asCraftInput(); + ); return world.getRecipeManager() .getRecipeFor(RecipeType.CRAFTING, invC, world) .map(recipe -> Pair.of(recipe, recipe.value().assemble(invC, world.registryAccess()))) diff --git a/src/main/java/blusunrize/immersiveengineering/common/util/InventoryCraftingFalse.java b/src/main/java/blusunrize/immersiveengineering/common/util/InventoryCraftingFalse.java new file mode 100644 index 0000000000..bf8eb59b96 --- /dev/null +++ b/src/main/java/blusunrize/immersiveengineering/common/util/InventoryCraftingFalse.java @@ -0,0 +1,53 @@ +/* + * BluSunrize + * Copyright (c) 2024 + * + * This code is licensed under "Blu's License of Common Sense" + * Details can be found in the license file in the root folder of this project + */ + +package blusunrize.immersiveengineering.common.util; + +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.CraftingContainer; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.TransientCraftingContainer; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.CraftingInput; + +import javax.annotation.Nonnull; +import java.util.List; + +public class InventoryCraftingFalse +{ + private static final AbstractContainerMenu NULL_CONTAINER = new AbstractContainerMenu(MenuType.CRAFTING, 0) + { + @Override + public ItemStack quickMoveStack(Player p_38941_, int p_38942_) + { + return ItemStack.EMPTY; + } + + @Override + public void slotsChanged(Container paramIInventory) + { + } + + @Override + public boolean stillValid(@Nonnull Player playerIn) + { + return false; + } + }; + + public static CraftingInput createFilledCraftingInventory(int w, int h, List stacks) + { + CraftingContainer invC = new TransientCraftingContainer(NULL_CONTAINER, w, h); + for(int j = 0; j < w*h; j++) + if(!stacks.get(j).isEmpty()) + invC.setItem(j, stacks.get(j).copy()); + return invC.asCraftInput(); + } +} diff --git a/src/main/java/blusunrize/immersiveengineering/common/util/Utils.java b/src/main/java/blusunrize/immersiveengineering/common/util/Utils.java index 77a1a201bb..493e947de3 100644 --- a/src/main/java/blusunrize/immersiveengineering/common/util/Utils.java +++ b/src/main/java/blusunrize/immersiveengineering/common/util/Utils.java @@ -41,17 +41,12 @@ import net.minecraft.tags.TagKey; import net.minecraft.util.Mth; import net.minecraft.util.RandomSource; -import net.minecraft.world.Container; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.HumanoidArm; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.monster.Monster; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.inventory.CraftingContainer; -import net.minecraft.world.inventory.MenuType; -import net.minecraft.world.inventory.TransientCraftingContainer; import net.minecraft.world.item.*; import net.minecraft.world.item.component.FireworkExplosion; import net.minecraft.world.item.component.FireworkExplosion.Shape; @@ -626,43 +621,6 @@ public static Vec3 withCoordinate(Vec3 vertex, Axis axis, double value) return vertex; } - public static class InventoryCraftingFalse extends TransientCraftingContainer - { - private static final AbstractContainerMenu nullContainer = new AbstractContainerMenu(MenuType.CRAFTING, 0) - { - @Override - public ItemStack quickMoveStack(Player p_38941_, int p_38942_) - { - return ItemStack.EMPTY; - } - - @Override - public void slotsChanged(Container paramIInventory) - { - } - - @Override - public boolean stillValid(@Nonnull Player playerIn) - { - return false; - } - }; - - public InventoryCraftingFalse(int w, int h) - { - super(nullContainer, w, h); - } - - public static CraftingContainer createFilledCraftingInventory(int w, int h, List stacks) - { - CraftingContainer invC = new Utils.InventoryCraftingFalse(w, h); - for(int j = 0; j < w*h; j++) - if(!stacks.get(j).isEmpty()) - invC.setItem(j, stacks.get(j).copy()); - return invC; - } - } - public static BlockPos rayTraceForFirst(Vec3 start, Vec3 end, Level w, Set ignore) { Set trace = Raytracer.rayTrace(start, end, w);