Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Aug 7, 2024
1 parent d8d266e commit 80e449d
Showing 1 changed file with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,17 @@
import net.minecraft.block.CrafterBlock;
import net.minecraft.block.entity.CrafterBlockEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.inventory.SimpleInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.CraftingRecipe;
import net.minecraft.recipe.RecipeEntry;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;

import net.fabricmc.fabric.api.transfer.v1.item.InventoryStorage;
import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage;
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
import net.fabricmc.fabric.api.transfer.v1.storage.Storage;
import net.fabricmc.fabric.api.transfer.v1.storage.StorageUtil;
import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction;

@Mixin(CrafterBlock.class)
public class CrafterBlockMixin {
Expand All @@ -59,15 +57,14 @@ private void transferOrSpawnStack(ServerWorld world, BlockPos pos, CrafterBlockE

if (target != null) {
// Attempt to move the entire stack, and decrement the size of success moves.
long moved = StorageUtil.move(
InventoryStorage.of(new SimpleInventory(itemStack.copy()), null),
target,
iv -> true,
itemStack.getCount(),
null
);
try (Transaction transaction = Transaction.openOuter()) {
long moved = target.insert(ItemVariant.of(itemStack), inputStack.getCount(), transaction);

itemStack.decrement((int) moved);
if (moved > 0) {
itemStack.decrement((int) moved);
transaction.commit();
}
}
}

// Any remaining will be dropped in the world by vanilla logic
Expand Down

0 comments on commit 80e449d

Please sign in to comment.