Skip to content

Commit

Permalink
Fix #6
Browse files Browse the repository at this point in the history
  • Loading branch information
FakeDomi committed Nov 1, 2022
1 parent aea1a2a commit 8b3af01
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 10 additions & 1 deletion src/main/java/re/domi/easyautocrafting/CraftingDropper.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

public class CraftingDropper
{
@SuppressWarnings("UnstableApiUsage")
public static void dispense(ServerWorld world, BlockPos dispenserPos, CallbackInfo ci)
{
if (!hasTableNextToBlock(world, dispenserPos))
Expand All @@ -50,7 +51,7 @@ public static void dispense(ServerWorld world, BlockPos dispenserPos, CallbackIn
craftingInventory.setStack(i, stack);
}

@SuppressWarnings("UnstableApiUsage") Storage<ItemVariant> ingredientStorage = Config.enable3x3InventorySearching ?
Storage<ItemVariant> ingredientStorage = Config.enable3x3InventorySearching ?
InventoryUtil.getMerged3x3Storage(world, dispenserPos.offset(facing.getOpposite()), facing) :
ItemStorage.SIDED.find(world, dispenserPos.offset(facing.getOpposite()), facing);

Expand Down Expand Up @@ -88,6 +89,7 @@ public static void dispense(ServerWorld world, BlockPos dispenserPos, CallbackIn
}

Inventory inventoryInFront = HopperBlockEntity.getInventoryAt(world, dispenserPos.offset(facing));
Storage<ItemVariant> storage = ItemStorage.SIDED.find(world, dispenserPos.offset(facing), facing.getOpposite());
boolean hasCrafted = false;

if (inventoryInFront != null)
Expand All @@ -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)
Expand Down
22 changes: 20 additions & 2 deletions src/main/java/re/domi/easyautocrafting/InventoryUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ public static ItemStack singleItemOf(ItemStack stack)
return copy;
}

@SuppressWarnings("UnstableApiUsage")
public static boolean tryTakeItems(Storage<ItemVariant> storage, List<ItemStack> stacks, boolean simulate)
@SuppressWarnings("UnstableApiUsage")
public static boolean tryTakeItems(Storage<ItemVariant> storage, List<ItemStack> stacks, boolean simulate)
{
stacks = deepCopy(stacks);

Expand Down Expand Up @@ -153,6 +153,24 @@ public static boolean tryTakeItems(Storage<ItemVariant> storage, List<ItemStack>
}
}

@SuppressWarnings("UnstableApiUsage")
public static boolean tryPutItems(Storage<ItemVariant> storage, List<ItemStack> 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<ItemStack> stacks, Direction side, boolean simulate)
{
if (simulate)
Expand Down

0 comments on commit 8b3af01

Please sign in to comment.