Fix a glitch

This commit is contained in:
Bruno Rybársky 2024-07-05 00:04:34 +02:00
parent b85ab92097
commit ecb926a180
4 changed files with 11 additions and 15 deletions

@ -11,7 +11,7 @@ loader_version=0.15.11
fabric_version=0.100.4+1.21 fabric_version=0.100.4+1.21
# Mod Properties # Mod Properties
mod_version=3.0.2 mod_version=3.0.3
maven_group=systems.brn maven_group=systems.brn
archives_base_name=Server_storage archives_base_name=Server_storage

@ -28,10 +28,7 @@ public class HardDrive {
public Map<ItemStack, Integer> items; public Map<ItemStack, Integer> items;
public void loadComponents() { public void loadComponents() {
Map<ItemStack, Integer> loadedItems = driveStack.getComponents().getOrDefault(ITEMSTACK_MAP, new HashMap<>()); this.items = driveStack.getComponents().getOrDefault(ITEMSTACK_MAP, new HashMap<>());
if (this.items == null) {
this.items = loadedItems;
}
updateData(); updateData();
} }
@ -123,20 +120,19 @@ public class HardDrive {
blockEntity.markDirty(); blockEntity.markDirty();
} }
public ItemStack removeStackFromInventory(ItemStack stack) { public ItemStack removeStackFromInventoryRemains(ItemStack stack) {
int outCount = 0; int outCount = stack.getCount();
ItemStack outStack = stack.copy(); ItemStack outStack = stack.copy();
for (Map.Entry<ItemStack, Integer> entry : items.entrySet()) { for (Map.Entry<ItemStack, Integer> entry : items.entrySet()) {
if (canCombine(entry.getKey(), stack)) { if (canCombine(entry.getKey(), stack)) {
int countInDrive = entry.getValue(); int countInDrive = entry.getValue();
int needToRemove = stack.getCount();
if (countInDrive <= needToRemove) { if (countInDrive <= outCount) {
items.remove(entry.getKey()); items.remove(entry.getKey());
needToRemove -= countInDrive; outCount -= countInDrive;
outCount += needToRemove;
} else { } else {
entry.setValue(countInDrive - needToRemove); entry.setValue(countInDrive - outCount);
outCount -= countInDrive;
} }
break; break;
} }

@ -187,8 +187,8 @@ public class StorageNetwork {
ItemStack outStack = stackToRemove.copy(); ItemStack outStack = stackToRemove.copy();
for (HardDrive drive : drives) { for (HardDrive drive : drives) {
outStack = drive.removeStackFromInventory(outStack); ItemStack removedStack = drive.removeStackFromInventoryRemains(outStack);
if (outStack.getCount() >= stackToRemove.getCount()) { if (removedStack.getCount() <= 0) {
break; break;
} }
} }

@ -92,6 +92,7 @@ public class CraftingScreen extends PagedGui {
} }
private boolean canCraft(RecipeEntry<CraftingRecipe> recipeEntry) { private boolean canCraft(RecipeEntry<CraftingRecipe> recipeEntry) {
blockEntity.reindexDrives();
for (Ingredient ingredient : recipeEntry.value().getIngredients()) { for (Ingredient ingredient : recipeEntry.value().getIngredients()) {
if (findMatchingStack(ingredient) == null) { if (findMatchingStack(ingredient) == null) {
return false; return false;
@ -119,7 +120,6 @@ public class CraftingScreen extends PagedGui {
// Add crafted item to the appropriate inventory // Add crafted item to the appropriate inventory
ItemStack outputStack = recipeEntry.value().getResult(storageScreen.getPlayer().getRegistryManager()).copy(); ItemStack outputStack = recipeEntry.value().getResult(storageScreen.getPlayer().getRegistryManager()).copy();
int maxStackSize = outputStack.getMaxCount();
if (toPlayerInventory) { if (toPlayerInventory) {
PlayerInventory playerInventory = player.getInventory(); PlayerInventory playerInventory = player.getInventory();