diff --git a/src/main/java/de/dafuqs/spectrum/blocks/chests/RestockingChestBlockEntity.java b/src/main/java/de/dafuqs/spectrum/blocks/chests/RestockingChestBlockEntity.java index 559173ba3e..7388c8c64c 100644 --- a/src/main/java/de/dafuqs/spectrum/blocks/chests/RestockingChestBlockEntity.java +++ b/src/main/java/de/dafuqs/spectrum/blocks/chests/RestockingChestBlockEntity.java @@ -5,6 +5,7 @@ import de.dafuqs.spectrum.items.magic_items.*; import de.dafuqs.spectrum.networking.*; import de.dafuqs.spectrum.registries.*; +import net.fabricmc.fabric.api.transfer.v1.transaction.*; import net.minecraft.block.*; import net.minecraft.entity.player.*; import net.minecraft.inventory.*; @@ -218,7 +219,8 @@ private boolean tryCraft(RestockingChestBlockEntity chest, int index) { } return false; } - + + @SuppressWarnings({"UnstableApiUsage", "Deprecation"}) private static boolean isRecipeValid(Recipe recipe) { return recipe instanceof ShapelessRecipe || recipe instanceof ShapedRecipe; } @@ -228,7 +230,10 @@ private boolean isRecipeCraftable(Recipe recipe, int index) { if (!InventoryHelper.hasInInventory(ingredients, this)) return false; - + + // Don't check if a recipe can be crafted when simulating insertion of its remainders. + if (Transaction.isOpen()) return true; + var remainders = InventoryHelper.getRemainders(ingredients, this); return InventoryHelper.canFitStacks(remainders, this); diff --git a/src/main/java/de/dafuqs/spectrum/blocks/pastel_network/network/ServerPastelNetwork.java b/src/main/java/de/dafuqs/spectrum/blocks/pastel_network/network/ServerPastelNetwork.java index 78ceb10d79..65fd344344 100644 --- a/src/main/java/de/dafuqs/spectrum/blocks/pastel_network/network/ServerPastelNetwork.java +++ b/src/main/java/de/dafuqs/spectrum/blocks/pastel_network/network/ServerPastelNetwork.java @@ -233,7 +233,7 @@ private void checkForNetworkSplit(BlockPos sourcePos) { disconnectedBEs.add(blockEntity.get()); blockEntities.add(blockEntity.get()); if (newNetworkUUID == null) { - newNetworkUUID = blockEntity.get().getNodeId(); + newNetworkUUID = UUID.randomUUID(); } } } diff --git a/src/main/java/de/dafuqs/spectrum/helpers/InventoryHelper.java b/src/main/java/de/dafuqs/spectrum/helpers/InventoryHelper.java index 1eaec1eb45..ae953cf771 100644 --- a/src/main/java/de/dafuqs/spectrum/helpers/InventoryHelper.java +++ b/src/main/java/de/dafuqs/spectrum/helpers/InventoryHelper.java @@ -3,6 +3,7 @@ import de.dafuqs.spectrum.api.interaction.*; import net.fabricmc.fabric.api.transfer.v1.item.*; import net.fabricmc.fabric.api.transfer.v1.storage.*; +import net.fabricmc.fabric.api.transfer.v1.transaction.*; import net.minecraft.block.*; import net.minecraft.block.entity.*; import net.minecraft.entity.*; @@ -355,7 +356,7 @@ public static List removeFromInventoryWithRemainders(List return remainders; } - @SuppressWarnings("UnstableApiUsage") + @SuppressWarnings({"UnstableApiUsage", "Deprecation"}) public static boolean canFitStacks(List stacks, Inventory inventory) { var storage = InventoryStorage.of(inventory, null); @@ -366,7 +367,11 @@ public static boolean canFitStacks(List stacks, Inventory inventory) if (stack.isEmpty()) continue; - if (StorageUtil.simulateInsert(storage, ItemVariant.of(stack), stack.getMaxCount(), null) != stack.getCount()) + // Getting the current transaction, as it will be cancelled anyway, + // and passing null can cause an exception, making the simulated insert fail, + // or crashing the entire game. + + if (StorageUtil.simulateInsert(storage, ItemVariant.of(stack), stack.getMaxCount(), Transaction.getCurrentUnsafe()) != stack.getCount()) return false; }