From ecb926a18099bdd2e94d1641647a08ad1d78377b Mon Sep 17 00:00:00 2001 From: bruno Date: Fri, 5 Jul 2024 00:04:34 +0200 Subject: [PATCH] Fix a glitch --- gradle.properties | 2 +- .../brn/server_storage/items/HardDrive.java | 18 +++++++----------- .../brn/server_storage/lib/StorageNetwork.java | 4 ++-- .../server_storage/screens/CraftingScreen.java | 2 +- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/gradle.properties b/gradle.properties index 1ac5a24..a81be4c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,7 +11,7 @@ loader_version=0.15.11 fabric_version=0.100.4+1.21 # Mod Properties -mod_version=3.0.2 +mod_version=3.0.3 maven_group=systems.brn archives_base_name=Server_storage diff --git a/src/main/java/systems/brn/server_storage/items/HardDrive.java b/src/main/java/systems/brn/server_storage/items/HardDrive.java index 9fc6240..92cf9c4 100644 --- a/src/main/java/systems/brn/server_storage/items/HardDrive.java +++ b/src/main/java/systems/brn/server_storage/items/HardDrive.java @@ -28,10 +28,7 @@ public class HardDrive { public Map items; public void loadComponents() { - Map loadedItems = driveStack.getComponents().getOrDefault(ITEMSTACK_MAP, new HashMap<>()); - if (this.items == null) { - this.items = loadedItems; - } + this.items = driveStack.getComponents().getOrDefault(ITEMSTACK_MAP, new HashMap<>()); updateData(); } @@ -123,20 +120,19 @@ public class HardDrive { blockEntity.markDirty(); } - public ItemStack removeStackFromInventory(ItemStack stack) { - int outCount = 0; + public ItemStack removeStackFromInventoryRemains(ItemStack stack) { + int outCount = stack.getCount(); ItemStack outStack = stack.copy(); for (Map.Entry entry : items.entrySet()) { if (canCombine(entry.getKey(), stack)) { int countInDrive = entry.getValue(); - int needToRemove = stack.getCount(); - if (countInDrive <= needToRemove) { + if (countInDrive <= outCount) { items.remove(entry.getKey()); - needToRemove -= countInDrive; - outCount += needToRemove; + outCount -= countInDrive; } else { - entry.setValue(countInDrive - needToRemove); + entry.setValue(countInDrive - outCount); + outCount -= countInDrive; } break; } diff --git a/src/main/java/systems/brn/server_storage/lib/StorageNetwork.java b/src/main/java/systems/brn/server_storage/lib/StorageNetwork.java index 673a730..9cc0a0d 100644 --- a/src/main/java/systems/brn/server_storage/lib/StorageNetwork.java +++ b/src/main/java/systems/brn/server_storage/lib/StorageNetwork.java @@ -187,8 +187,8 @@ public class StorageNetwork { ItemStack outStack = stackToRemove.copy(); for (HardDrive drive : drives) { - outStack = drive.removeStackFromInventory(outStack); - if (outStack.getCount() >= stackToRemove.getCount()) { + ItemStack removedStack = drive.removeStackFromInventoryRemains(outStack); + if (removedStack.getCount() <= 0) { break; } } diff --git a/src/main/java/systems/brn/server_storage/screens/CraftingScreen.java b/src/main/java/systems/brn/server_storage/screens/CraftingScreen.java index 6c0295c..f78b0c8 100644 --- a/src/main/java/systems/brn/server_storage/screens/CraftingScreen.java +++ b/src/main/java/systems/brn/server_storage/screens/CraftingScreen.java @@ -92,6 +92,7 @@ public class CraftingScreen extends PagedGui { } private boolean canCraft(RecipeEntry recipeEntry) { + blockEntity.reindexDrives(); for (Ingredient ingredient : recipeEntry.value().getIngredients()) { if (findMatchingStack(ingredient) == null) { return false; @@ -119,7 +120,6 @@ public class CraftingScreen extends PagedGui { // Add crafted item to the appropriate inventory ItemStack outputStack = recipeEntry.value().getResult(storageScreen.getPlayer().getRegistryManager()).copy(); - int maxStackSize = outputStack.getMaxCount(); if (toPlayerInventory) { PlayerInventory playerInventory = player.getInventory();