Another bugfix hopefully
This commit is contained in:
		| @@ -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 | ||||
|  | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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); | ||||
|         } | ||||
|   | ||||
| @@ -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); | ||||
|         } | ||||
|   | ||||
| @@ -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 { | ||||
|   | ||||
| @@ -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<ItemStack, Integer> itemStackMap; | ||||
|     public Map<ItemStack, Integer> 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<HardDriveContainerBlockEntity> driveContainers = new ArrayList<>(); | ||||
|         List<StorageInterfaceBlockEntity> storageInterfaceBlockEntities = new ArrayList<>(); | ||||
|         List<InventoryInterfaceBlockEntity> inventoryInterfaceBlockEntities = new ArrayList<>(); | ||||
| @@ -78,6 +88,19 @@ public class StorageNetwork { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public ItemStack findSimilarStack(ItemStack stack){ | ||||
|         if (!stack.isEmpty()) { | ||||
|             for (Map.Entry<ItemStack, Integer> 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<HardDriveContainerBlockEntity> driveContainers, List<StorageInterfaceBlockEntity> storageInterfaceBlockEntities, List<InventoryInterfaceBlockEntity> inventoryInterfaceBlockEntities, List<HardDrive> drives, Set<BlockPos> visited) { | ||||
|         if (visited.contains(pos)) { | ||||
|             return; | ||||
| @@ -180,6 +203,7 @@ public class StorageNetwork { | ||||
|     } | ||||
|  | ||||
|     public boolean canRemove(ItemStack stackToRemove) { | ||||
|  | ||||
|         return canRemoveRemainingCount(stackToRemove, itemStackMap) == 0; | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -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(); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user