diff --git a/gradle.properties b/gradle.properties index 0991dac..88bced4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G loader_version=0.14.6 # Mod Properties - mod_version = 1.6+1.19 + mod_version = 1.7+1.19 maven_group = re.domi archives_base_name = easy-auto-crafting diff --git a/src/main/java/re/domi/easyautocrafting/CraftingDropper.java b/src/main/java/re/domi/easyautocrafting/CraftingDropper.java index dbe3804..cd43bf7 100644 --- a/src/main/java/re/domi/easyautocrafting/CraftingDropper.java +++ b/src/main/java/re/domi/easyautocrafting/CraftingDropper.java @@ -28,6 +28,7 @@ public class CraftingDropper { + @SuppressWarnings("UnstableApiUsage") public static void dispense(ServerWorld world, BlockPos dispenserPos, CallbackInfo ci) { if (!hasTableNextToBlock(world, dispenserPos)) @@ -50,7 +51,7 @@ public static void dispense(ServerWorld world, BlockPos dispenserPos, CallbackIn craftingInventory.setStack(i, stack); } - @SuppressWarnings("UnstableApiUsage") Storage ingredientStorage = Config.enable3x3InventorySearching ? + Storage ingredientStorage = Config.enable3x3InventorySearching ? InventoryUtil.getMerged3x3Storage(world, dispenserPos.offset(facing.getOpposite()), facing) : ItemStorage.SIDED.find(world, dispenserPos.offset(facing.getOpposite()), facing); @@ -88,6 +89,7 @@ public static void dispense(ServerWorld world, BlockPos dispenserPos, CallbackIn } Inventory inventoryInFront = HopperBlockEntity.getInventoryAt(world, dispenserPos.offset(facing)); + Storage storage = ItemStorage.SIDED.find(world, dispenserPos.offset(facing), facing.getOpposite()); boolean hasCrafted = false; if (inventoryInFront != null) @@ -98,6 +100,13 @@ public static void dispense(ServerWorld world, BlockPos dispenserPos, CallbackIn hasCrafted = true; } } + else if (storage != null) + { + if (InventoryUtil.tryPutItems(storage, craftingResults)) + { + hasCrafted = true; + } + } else { for (ItemStack craftingResult : craftingResults) diff --git a/src/main/java/re/domi/easyautocrafting/InventoryUtil.java b/src/main/java/re/domi/easyautocrafting/InventoryUtil.java index cbe2b9c..2d072a0 100644 --- a/src/main/java/re/domi/easyautocrafting/InventoryUtil.java +++ b/src/main/java/re/domi/easyautocrafting/InventoryUtil.java @@ -101,8 +101,8 @@ public static ItemStack singleItemOf(ItemStack stack) return copy; } - @SuppressWarnings("UnstableApiUsage") - public static boolean tryTakeItems(Storage storage, List stacks, boolean simulate) + @SuppressWarnings("UnstableApiUsage") + public static boolean tryTakeItems(Storage storage, List stacks, boolean simulate) { stacks = deepCopy(stacks); @@ -153,6 +153,24 @@ public static boolean tryTakeItems(Storage storage, List } } + @SuppressWarnings("UnstableApiUsage") + public static boolean tryPutItems(Storage storage, List stacks) + { + try (Transaction transaction = Transaction.openOuter()) + { + for (ItemStack stack : stacks) + { + if (storage.insert(ItemVariant.of(stack), stack.getCount(), transaction) < stack.getCount()) + { + return false; + } + } + + transaction.commit(); + return true; + } + } + public static boolean tryPutItems(Inventory inventory, List stacks, Direction side, boolean simulate) { if (simulate)