Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -218,12 +219,18 @@ 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;
}

private boolean isRecipeCraftable(Recipe<?> recipe, int index) {
// Don't check if a recipe can be crafted when simulating insertion of its remainders.
if(Transaction.isOpen()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: for consistency, put a space between the if and condition here
also, the body is so small that it might as well not use curly braces (or even a new line, since it's overall small)

return true;
}

var ingredients = recipe.getIngredients();

if (!InventoryHelper.hasInInventory(ingredients, this))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/de/dafuqs/spectrum/helpers/InventoryHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -355,7 +356,7 @@ public static List<ItemStack> removeFromInventoryWithRemainders(List<Ingredient>
return remainders;
}

@SuppressWarnings("UnstableApiUsage")
@SuppressWarnings({"UnstableApiUsage", "Deprecation"})
public static boolean canFitStacks(List<ItemStack> stacks, Inventory inventory) {
var storage = InventoryStorage.of(inventory, null);

Expand All @@ -366,7 +367,11 @@ public static boolean canFitStacks(List<ItemStack> 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;
}

Expand Down
Loading