From f929a81f60eb8c785e875a7904abf459a5916743 Mon Sep 17 00:00:00 2001 From: nonstopslip Date: Sun, 3 Dec 2023 20:32:37 +0100 Subject: [PATCH] Updated mc, mappings and loader versions as well as carpet core version in gradle.properties. Fixed arising exceptions. --- gradle.properties | 11 ++++--- .../AutoCraftingTableContainer.java | 5 +-- .../CraftingTableBlockEntity.java | 32 +++++++++++-------- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/gradle.properties b/gradle.properties index 42e8f61..2e7ce48 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,14 +3,15 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/develop/ - minecraft_version=1.20 - yarn_mappings=1.20+build.1 - loader_version=0.14.21 + minecraft_version=1.20.2 + yarn_mappings=1.20.2+build.4 + loader_version=0.15.0 # check available versions on maven for the given minecraft version you are using - carpet_core_version=1.4.112+v230608 + carpet_core_version=1.4.119+v230928 + # Mod Properties - mod_version = 1.4.112 + mod_version = 1.4.119 maven_group = carpet-autocraftingtable archives_base_name = carpet-autocraftingtable diff --git a/src/main/java/carpet_autocraftingtable/AutoCraftingTableContainer.java b/src/main/java/carpet_autocraftingtable/AutoCraftingTableContainer.java index b8d0b19..71e6878 100644 --- a/src/main/java/carpet_autocraftingtable/AutoCraftingTableContainer.java +++ b/src/main/java/carpet_autocraftingtable/AutoCraftingTableContainer.java @@ -7,6 +7,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket; import net.minecraft.recipe.Recipe; +import net.minecraft.recipe.RecipeEntry; import net.minecraft.recipe.RecipeMatcher; import net.minecraft.recipe.RecipeUnlocker; import net.minecraft.recipe.book.RecipeBookCategory; @@ -59,8 +60,8 @@ public boolean canInsertIntoSlot(ItemStack stack, Slot slot) { } @Override - public boolean matches(Recipe recipe) { - return this.blockEntity.matches(recipe); + public boolean matches(RecipeEntry> recipe) { + return this.blockEntity.matches(recipe.value()); } @Override diff --git a/src/main/java/carpet_autocraftingtable/CraftingTableBlockEntity.java b/src/main/java/carpet_autocraftingtable/CraftingTableBlockEntity.java index d097b3f..6c4d187 100644 --- a/src/main/java/carpet_autocraftingtable/CraftingTableBlockEntity.java +++ b/src/main/java/carpet_autocraftingtable/CraftingTableBlockEntity.java @@ -12,13 +12,7 @@ import net.minecraft.inventory.SidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; -import net.minecraft.recipe.CraftingRecipe; -import net.minecraft.recipe.Recipe; -import net.minecraft.recipe.RecipeInputProvider; -import net.minecraft.recipe.RecipeManager; -import net.minecraft.recipe.RecipeMatcher; -import net.minecraft.recipe.RecipeType; -import net.minecraft.recipe.RecipeUnlocker; +import net.minecraft.recipe.*; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; import net.minecraft.screen.ScreenHandler; @@ -44,7 +38,7 @@ public class CraftingTableBlockEntity extends LockableContainerBlockEntity imple private static final int[] INPUT_SLOTS = {1, 2, 3, 4, 5, 6, 7, 8, 9}; public DefaultedList inventory; public ItemStack output = ItemStack.EMPTY; - private Recipe lastRecipe; + private RecipeEntry lastRecipe; private final List openContainers = new ArrayList<>(); public CraftingTableBlockEntity(BlockPos pos, BlockState state) { //this(BlockEntityType.BARREL); @@ -170,12 +164,12 @@ public void provideRecipeInputs(RecipeMatcher finder) { } @Override - public void setLastRecipe(Recipe recipe) { + public void setLastRecipe(RecipeEntry recipe) { lastRecipe = recipe; } @Override - public Recipe getLastRecipe() { + public RecipeEntry getLastRecipe() { return lastRecipe; } @@ -188,18 +182,28 @@ private Optional getCurrentRecipe() { // No need to find recipes if the inventory is empty. Cannot craft anything. if (this.world == null || this.isEmpty()) return Optional.empty(); - CraftingRecipe lastRecipe = (CraftingRecipe) getLastRecipe(); + CraftingRecipe lastRecipe; + try { + lastRecipe = (CraftingRecipe) getLastRecipe().value(); + } catch (NullPointerException e) { + lastRecipe = null; + } RecipeManager manager = this.world.getRecipeManager(); if (lastRecipe != null) { - CraftingRecipe mapRecipe = manager.getAllOfType(RecipeType.CRAFTING).get(lastRecipe); + CraftingRecipe mapRecipe; + try { + mapRecipe = manager.getAllOfType(RecipeType.CRAFTING).get(lastRecipe).value(); + } catch (NullPointerException e) { + mapRecipe = null; + } if (mapRecipe != null && mapRecipe.matches(craftingInventory, world)) { return Optional.of(lastRecipe); } } - Optional recipe = manager.getFirstMatch(RecipeType.CRAFTING, craftingInventory, world); + Optional> recipe = manager.getFirstMatch(RecipeType.CRAFTING, craftingInventory, world); recipe.ifPresent(this::setLastRecipe); - return recipe; + return recipe.map(RecipeEntry::value); } private ItemStack craft() {