Skip to content

Commit

Permalink
wip: API rewrite, big refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Jan 9, 2024
1 parent 8f84cb2 commit daf6270
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@

public class CookingForBlockheads {

// TODO everything is nofilter right now
// TODO Received invalid craft request, unprocessable recipe minecraft:bread should be blocked clientside
// TODO preservation upgrade and ice unit for fridge

public static final String MOD_ID = "cookingforblockheads";
public static final Logger logger = LogManager.getLogger(MOD_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
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;
import net.blay09.mods.cookingforblockheads.tag.ModBlockTags;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.player.Player;
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.RecipeType;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
Expand All @@ -25,18 +29,21 @@ public class KitchenImpl implements Kitchen {

private final ItemStack activatingItemStack;
private final BlockState activatingBlockState;
private final BlockEntity activatingBlockEntity;
private final Set<BlockPos> checkedPos = new HashSet<>();
private final List<KitchenItemProvider> itemProviderList = new ArrayList<>();
private final List<KitchenItemProcessor> itemProcessorList = new ArrayList<>();

public KitchenImpl(ItemStack itemStack) {
activatingItemStack = itemStack;
activatingBlockState = Blocks.AIR.defaultBlockState();
activatingBlockEntity = null;
}

public KitchenImpl(Level level, BlockPos pos) {
activatingBlockState = level.getBlockState(pos);
activatingItemStack = ItemStack.EMPTY;
activatingBlockEntity = level.getBlockEntity(pos);
findNeighbourCraftingBlocks(level, pos, true);
}

Expand Down Expand Up @@ -95,4 +102,12 @@ public boolean canProcess(RecipeType<?> recipeType) {
return itemProcessorList.stream().anyMatch(it -> it.canProcess(recipeType));
}

public boolean isRecipeAvailable(RecipeHolder<Recipe<?>> recipe, CraftingOperation operation) {
final var isNoFilter = activatingItemStack.is(ModItems.noFilterBook) || (activatingBlockEntity instanceof CookingTableBlockEntity cookingTable && cookingTable.hasNoFilterBook());
if (isNoFilter) {
return true;
}

return operation.canCraft();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import net.blay09.mods.balm.api.container.DefaultContainer;
import net.blay09.mods.cookingforblockheads.CookingForBlockheads;
import net.blay09.mods.cookingforblockheads.api.Kitchen;
import net.blay09.mods.cookingforblockheads.api.KitchenItemProcessor;
import net.blay09.mods.cookingforblockheads.crafting.CraftingContext;
import net.blay09.mods.cookingforblockheads.crafting.KitchenImpl;
import net.blay09.mods.cookingforblockheads.crafting.RecipeWithStatus;
Expand All @@ -27,7 +26,6 @@
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.RecipeType;
import org.jetbrains.annotations.Nullable;

import java.util.*;
Expand Down Expand Up @@ -249,6 +247,10 @@ public List<RecipeWithStatus> getAvailableCraftables() {
}

final var operation = context.createOperation(recipe).prepare();
if (!kitchen.isRecipeAvailable(recipe, operation)) {
continue;
}

final var recipeWithStatus = new RecipeWithStatus(recipe.id(),
resultItem,
operation.getMissingIngredients(),
Expand Down

0 comments on commit daf6270

Please sign in to comment.