diff --git a/gradle.properties b/gradle.properties index 7ce2379..70749a1 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.4 +mod_version=3.0.5 maven_group=systems.brn archives_base_name=Server_storage diff --git a/src/main/java/systems/brn/server_storage/blockentities/HardDriveContainerBlockEntity.java b/src/main/java/systems/brn/server_storage/blockentities/HardDriveContainerBlockEntity.java index 6370e04..5a081d5 100644 --- a/src/main/java/systems/brn/server_storage/blockentities/HardDriveContainerBlockEntity.java +++ b/src/main/java/systems/brn/server_storage/blockentities/HardDriveContainerBlockEntity.java @@ -12,6 +12,7 @@ import net.minecraft.text.Text; import net.minecraft.util.collection.DefaultedList; import net.minecraft.util.math.BlockPos; import systems.brn.server_storage.items.HardDrive; +import systems.brn.server_storage.lib.StorageNetwork; import systems.brn.server_storage.screenhandlers.DriveContainerScreenHandler; import java.util.ArrayList; @@ -27,6 +28,7 @@ public class HardDriveContainerBlockEntity extends LootableContainerBlockEntity private int totalSlots; private int usedSlots; private int availableSlots; + public StorageNetwork network; public HardDriveContainerBlockEntity(BlockPos pos, BlockState state) { super(HARD_DRIVE_CONTAINER_BLOCK_ENTITY, pos, state); diff --git a/src/main/java/systems/brn/server_storage/blockentities/InventoryInterfaceBlockEntity.java b/src/main/java/systems/brn/server_storage/blockentities/InventoryInterfaceBlockEntity.java index 3c691fe..502e231 100644 --- a/src/main/java/systems/brn/server_storage/blockentities/InventoryInterfaceBlockEntity.java +++ b/src/main/java/systems/brn/server_storage/blockentities/InventoryInterfaceBlockEntity.java @@ -42,7 +42,8 @@ public class InventoryInterfaceBlockEntity extends BlockEntity { public void reindexDrives() { if (this.network != null) { - this.network.reindexNetwork(world, this.pos, false, query); + this.network.searchString = query; + this.network.reindexNetwork(); } else { this.network = new StorageNetwork(world, this.pos, false, query); } diff --git a/src/main/java/systems/brn/server_storage/blockentities/StorageInterfaceBlockEntity.java b/src/main/java/systems/brn/server_storage/blockentities/StorageInterfaceBlockEntity.java index d3a29f5..276b2d4 100644 --- a/src/main/java/systems/brn/server_storage/blockentities/StorageInterfaceBlockEntity.java +++ b/src/main/java/systems/brn/server_storage/blockentities/StorageInterfaceBlockEntity.java @@ -29,7 +29,9 @@ public class StorageInterfaceBlockEntity extends BlockEntity { public void reindexDrives() { if (this.network != null) { - this.network.reindexNetwork(world, this.pos, sortAlphabetically, searchString); + this.network.searchString = searchString; + this.network.sortAlphabetically = sortAlphabetically; + this.network.reindexNetwork(); } else { this.network = new StorageNetwork(world, this.pos, sortAlphabetically, searchString); } diff --git a/src/main/java/systems/brn/server_storage/blocks/HardDriveContainerBlock.java b/src/main/java/systems/brn/server_storage/blocks/HardDriveContainerBlock.java index 5b0ad0b..d030111 100644 --- a/src/main/java/systems/brn/server_storage/blocks/HardDriveContainerBlock.java +++ b/src/main/java/systems/brn/server_storage/blocks/HardDriveContainerBlock.java @@ -25,6 +25,7 @@ import net.minecraft.util.math.Direction; import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; import systems.brn.server_storage.blockentities.HardDriveContainerBlockEntity; +import systems.brn.server_storage.lib.StorageNetwork; import static systems.brn.server_storage.ServerStorage.*; @@ -82,8 +83,11 @@ public class HardDriveContainerBlock extends ConnectedBlock implements PolymerTe if (!world.isClient && !player.isSpectator()) { if (!player.isSneaking()) { BlockEntity storageBlockEntity = world.getBlockEntity(pos); - if (storageBlockEntity instanceof HardDriveContainerBlockEntity) { - player.openHandledScreen((HardDriveContainerBlockEntity) storageBlockEntity); + if (storageBlockEntity instanceof HardDriveContainerBlockEntity driveContainerBlockEntity) { + if (driveContainerBlockEntity.network == null){ + driveContainerBlockEntity.network = new StorageNetwork(world, pos, false, ""); + } + player.openHandledScreen(driveContainerBlockEntity); } } else { 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 9cc0a0d..4e47cbb 100644 --- a/src/main/java/systems/brn/server_storage/lib/StorageNetwork.java +++ b/src/main/java/systems/brn/server_storage/lib/StorageNetwork.java @@ -16,6 +16,7 @@ import systems.brn.server_storage.blocks.InventoryInterfaceBlock; import systems.brn.server_storage.blocks.StorageInterfaceBlock; import systems.brn.server_storage.items.HardDrive; +import java.security.KeyStore; import java.util.*; import static systems.brn.server_storage.ServerStorage.DRIVES; @@ -30,6 +31,11 @@ public class StorageNetwork { public Map itemStackMap; public Map filteredItemStackMap; + public final World world; + public final BlockPos startPos; + public boolean sortAlphabetically = false; + public String searchString = ""; + public int driveContainerCount; public int drivesCount; public int driveTotalSlots; @@ -37,10 +43,14 @@ public class StorageNetwork { public int driveFreeSlots; public StorageNetwork(World world, BlockPos startPos, boolean sortAlphabetically, String searchString) { - reindexNetwork(world, startPos, sortAlphabetically, searchString); + this.world = world; + this.startPos = startPos; + this.sortAlphabetically = sortAlphabetically; + this.searchString = searchString; + reindexNetwork(); } - public void reindexNetwork(World world, BlockPos startPos, boolean sortAlphabetically, String searchString) { + public void reindexNetwork() { List driveContainers = new ArrayList<>(); List storageInterfaceBlockEntities = new ArrayList<>(); List inventoryInterfaceBlockEntities = new ArrayList<>(); @@ -78,6 +88,19 @@ public class StorageNetwork { } } + public ItemStack findSimilarStack(ItemStack stack){ + if (!stack.isEmpty()) { + for (Map.Entry entry : filteredItemStackMap.entrySet()) { + if(canCombine(entry.getKey(), stack)){ + ItemStack stackCopy = entry.getKey().copy(); + stackCopy.setCount(entry.getValue()); + return stackCopy; + } + } + } + return stack; + } + private static void scan(World world, BlockPos pos, BlockPos startPos, List driveContainers, List storageInterfaceBlockEntities, List inventoryInterfaceBlockEntities, List drives, Set visited) { if (visited.contains(pos)) { return; @@ -180,6 +203,7 @@ public class StorageNetwork { } public boolean canRemove(ItemStack stackToRemove) { + return canRemoveRemainingCount(stackToRemove, itemStackMap) == 0; } diff --git a/src/main/java/systems/brn/server_storage/screenhandlers/DriveContainerScreenHandler.java b/src/main/java/systems/brn/server_storage/screenhandlers/DriveContainerScreenHandler.java index a725c95..800ff45 100644 --- a/src/main/java/systems/brn/server_storage/screenhandlers/DriveContainerScreenHandler.java +++ b/src/main/java/systems/brn/server_storage/screenhandlers/DriveContainerScreenHandler.java @@ -8,6 +8,7 @@ import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.ScreenHandlerType; import net.minecraft.screen.slot.Slot; import systems.brn.server_storage.blockentities.HardDriveContainerBlockEntity; +import systems.brn.server_storage.lib.StorageNetwork; public class DriveContainerScreenHandler extends ScreenHandler { private final Inventory inventory; @@ -86,5 +87,6 @@ public class DriveContainerScreenHandler extends ScreenHandler { super.onClosed(player); this.inventory.onClose(player); blockEntity.indexDrives(); + blockEntity.network.reindexNetwork(); } } diff --git a/src/main/java/systems/brn/server_storage/screens/StorageScreen.java b/src/main/java/systems/brn/server_storage/screens/StorageScreen.java index a20634d..fc1355a 100644 --- a/src/main/java/systems/brn/server_storage/screens/StorageScreen.java +++ b/src/main/java/systems/brn/server_storage/screens/StorageScreen.java @@ -85,6 +85,7 @@ public class StorageScreen extends PagedGui { if (clickedElement != null && cursorStack.isEmpty()) { ItemStack clickedItem = clickedElement.getItemStack(); ItemStack noLoreStack = removeCountFromLore(clickedItem); + noLoreStack = blockEntity.network.findSimilarStack(noLoreStack); if (type.isRight) { if (!type.shift) { noLoreStack.setCount(Math.min(noLoreStack.getMaxCount(), noLoreStack.getCount() / 2)); //half stack