diff --git a/src/main/java/com/simibubi/create/AllRecipeTypes.java b/src/main/java/com/simibubi/create/AllRecipeTypes.java index f39371e53..9a30a9017 100644 --- a/src/main/java/com/simibubi/create/AllRecipeTypes.java +++ b/src/main/java/com/simibubi/create/AllRecipeTypes.java @@ -1,6 +1,7 @@ package com.simibubi.create; import java.util.Optional; +import java.util.function.Predicate; import java.util.function.Supplier; import org.jetbrains.annotations.Nullable; @@ -38,6 +39,7 @@ import net.minecraft.world.item.crafting.ShapedRecipe; import net.minecraft.world.item.crafting.SimpleRecipeSerializer; import net.minecraft.world.level.Level; import net.minecraftforge.eventbus.api.IEventBus; +import net.minecraftforge.items.wrapper.RecipeWrapper; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.RegistryObject; @@ -65,6 +67,10 @@ public enum AllRecipeTypes implements IRecipeTypeInfo { TOOLBOX_DYEING(() -> new SimpleRecipeSerializer<>(ToolboxDyeingRecipe::new), () -> RecipeType.CRAFTING, false); + public static final Predicate> CAN_BE_AUTOMATED = r -> !r.getId() + .getPath() + .endsWith("_manual_only"); + private final ResourceLocation id; private final RegistryObject> serializerObject; @Nullable diff --git a/src/main/java/com/simibubi/create/compat/jei/CreateJEI.java b/src/main/java/com/simibubi/create/compat/jei/CreateJEI.java index fcdc719e7..33be8af4a 100644 --- a/src/main/java/com/simibubi/create/compat/jei/CreateJEI.java +++ b/src/main/java/com/simibubi/create/compat/jei/CreateJEI.java @@ -468,8 +468,7 @@ public class CreateJEI implements IModPlugin { } public CategoryBuilder removeNonAutomation() { - return addRecipeListConsumer(recipes -> recipes.removeIf(recipe -> - recipe.getId().getPath().contains("_manual_only"))); + return addRecipeListConsumer(recipes -> recipes.removeIf(AllRecipeTypes.CAN_BE_AUTOMATED.negate())); } public CategoryBuilder catalystStack(Supplier supplier) { diff --git a/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerBlockEntity.java b/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerBlockEntity.java index d706c73f1..8e02c54a1 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerBlockEntity.java @@ -47,7 +47,6 @@ import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Recipe; -import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.ClipContext.Block; import net.minecraft.world.level.ClipContext.Fluid; @@ -550,10 +549,7 @@ public class DeployerBlockEntity extends KineticBlockEntity { ItemStack heldItemMainhand = player.getMainHandItem(); if (heldItemMainhand.getItem() instanceof SandPaperItem) { sandpaperInv.setItem(0, stack); - Optional> sandPaperRecipe = AllRecipeTypes.SANDPAPER_POLISHING.find(sandpaperInv, level); - if (sandPaperRecipe.isPresent() && !sandPaperRecipe.get().getId().getPath().endsWith("_manual_only")) - return sandPaperRecipe.get(); - return null; + return checkRecipe(AllRecipeTypes.SANDPAPER_POLISHING, sandpaperInv, level).orElse(null); } recipeInv.setItem(0, stack); @@ -571,10 +567,7 @@ public class DeployerBlockEntity extends KineticBlockEntity { } private Optional> checkRecipe(AllRecipeTypes type, RecipeWrapper inv, Level level) { - Optional> opt = type.find(inv, level); - if (opt.isPresent() && !opt.get().getId().getPath().contains("_manual_only")) - return opt; - return Optional.empty(); + return type.find(inv, level).filter(AllRecipeTypes.CAN_BE_AUTOMATED); } public DeployerFakePlayer getPlayer() { diff --git a/src/main/java/com/simibubi/create/content/kinetics/fan/processing/AllFanProcessingTypes.java b/src/main/java/com/simibubi/create/content/kinetics/fan/processing/AllFanProcessingTypes.java index c4c8e8b38..cfa951f9e 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/fan/processing/AllFanProcessingTypes.java +++ b/src/main/java/com/simibubi/create/content/kinetics/fan/processing/AllFanProcessingTypes.java @@ -160,19 +160,19 @@ public class AllFanProcessingTypes { public boolean canProcess(ItemStack stack, Level level) { RECIPE_WRAPPER.setItem(0, stack); Optional smeltingRecipe = level.getRecipeManager() - .getRecipeFor(RecipeType.SMELTING, RECIPE_WRAPPER, level); + .getRecipeFor(RecipeType.SMELTING, RECIPE_WRAPPER, level) + .filter(AllRecipeTypes.CAN_BE_AUTOMATED); - if (smeltingRecipe.isPresent()) { - return !smeltingRecipe.get().getId().getPath().endsWith("_manual_only"); - } + if (smeltingRecipe.isPresent()) + return true; RECIPE_WRAPPER.setItem(0, stack); Optional blastingRecipe = level.getRecipeManager() - .getRecipeFor(RecipeType.BLASTING, RECIPE_WRAPPER, level); + .getRecipeFor(RecipeType.BLASTING, RECIPE_WRAPPER, level) + .filter(AllRecipeTypes.CAN_BE_AUTOMATED); - if (blastingRecipe.isPresent()) { - return !blastingRecipe.get().getId().getPath().endsWith("_manual_only"); - } + if (blastingRecipe.isPresent()) + return true; return !stack.getItem() .isFireResistant(); @@ -183,11 +183,14 @@ public class AllFanProcessingTypes { public List process(ItemStack stack, Level level) { RECIPE_WRAPPER.setItem(0, stack); Optional smokingRecipe = level.getRecipeManager() - .getRecipeFor(RecipeType.SMOKING, RECIPE_WRAPPER, level); + .getRecipeFor(RecipeType.SMOKING, RECIPE_WRAPPER, level) + .filter(AllRecipeTypes.CAN_BE_AUTOMATED); RECIPE_WRAPPER.setItem(0, stack); Optional smeltingRecipe = level.getRecipeManager() - .getRecipeFor(RecipeType.SMELTING, RECIPE_WRAPPER, level); + .getRecipeFor(RecipeType.SMELTING, RECIPE_WRAPPER, level) + .filter(AllRecipeTypes.CAN_BE_AUTOMATED); + if (!smeltingRecipe.isPresent()) { RECIPE_WRAPPER.setItem(0, stack); smeltingRecipe = level.getRecipeManager() @@ -391,8 +394,10 @@ public class AllFanProcessingTypes { public boolean canProcess(ItemStack stack, Level level) { RECIPE_WRAPPER.setItem(0, stack); Optional recipe = level.getRecipeManager() - .getRecipeFor(RecipeType.SMOKING, RECIPE_WRAPPER, level); - return recipe.isPresent() && !recipe.get().getId().getPath().endsWith("_manual_only"); + .getRecipeFor(RecipeType.SMOKING, RECIPE_WRAPPER, level) + .filter(AllRecipeTypes.CAN_BE_AUTOMATED); + + return recipe.isPresent(); } @Override @@ -400,7 +405,8 @@ public class AllFanProcessingTypes { public List process(ItemStack stack, Level level) { RECIPE_WRAPPER.setItem(0, stack); Optional smokingRecipe = level.getRecipeManager() - .getRecipeFor(RecipeType.SMOKING, RECIPE_WRAPPER, level); + .getRecipeFor(RecipeType.SMOKING, RECIPE_WRAPPER, level) + .filter(AllRecipeTypes.CAN_BE_AUTOMATED); if (smokingRecipe.isPresent()) return RecipeApplier.applyRecipeOn(stack, smokingRecipe.get());