Another bugfix hopefully

This commit is contained in:
Bruno Rybársky 2024-07-06 10:56:18 +02:00
parent 2a6c9f26f9
commit f1a2e54f41
8 changed files with 43 additions and 7 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.4 mod_version=3.0.5
maven_group=systems.brn maven_group=systems.brn
archives_base_name=Server_storage archives_base_name=Server_storage

@ -12,6 +12,7 @@ import net.minecraft.text.Text;
import net.minecraft.util.collection.DefaultedList; import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import systems.brn.server_storage.items.HardDrive; import systems.brn.server_storage.items.HardDrive;
import systems.brn.server_storage.lib.StorageNetwork;
import systems.brn.server_storage.screenhandlers.DriveContainerScreenHandler; import systems.brn.server_storage.screenhandlers.DriveContainerScreenHandler;
import java.util.ArrayList; import java.util.ArrayList;
@ -27,6 +28,7 @@ public class HardDriveContainerBlockEntity extends LootableContainerBlockEntity
private int totalSlots; private int totalSlots;
private int usedSlots; private int usedSlots;
private int availableSlots; private int availableSlots;
public StorageNetwork network;
public HardDriveContainerBlockEntity(BlockPos pos, BlockState state) { public HardDriveContainerBlockEntity(BlockPos pos, BlockState state) {
super(HARD_DRIVE_CONTAINER_BLOCK_ENTITY, pos, state); super(HARD_DRIVE_CONTAINER_BLOCK_ENTITY, pos, state);

@ -42,7 +42,8 @@ public class InventoryInterfaceBlockEntity extends BlockEntity {
public void reindexDrives() { public void reindexDrives() {
if (this.network != null) { if (this.network != null) {
this.network.reindexNetwork(world, this.pos, false, query); this.network.searchString = query;
this.network.reindexNetwork();
} else { } else {
this.network = new StorageNetwork(world, this.pos, false, query); this.network = new StorageNetwork(world, this.pos, false, query);
} }

@ -29,7 +29,9 @@ public class StorageInterfaceBlockEntity extends BlockEntity {
public void reindexDrives() { public void reindexDrives() {
if (this.network != null) { if (this.network != null) {
this.network.reindexNetwork(world, this.pos, sortAlphabetically, searchString); this.network.searchString = searchString;
this.network.sortAlphabetically = sortAlphabetically;
this.network.reindexNetwork();
} else { } else {
this.network = new StorageNetwork(world, this.pos, sortAlphabetically, searchString); 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 net.minecraft.world.World;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import systems.brn.server_storage.blockentities.HardDriveContainerBlockEntity; import systems.brn.server_storage.blockentities.HardDriveContainerBlockEntity;
import systems.brn.server_storage.lib.StorageNetwork;
import static systems.brn.server_storage.ServerStorage.*; import static systems.brn.server_storage.ServerStorage.*;
@ -82,8 +83,11 @@ public class HardDriveContainerBlock extends ConnectedBlock implements PolymerTe
if (!world.isClient && !player.isSpectator()) { if (!world.isClient && !player.isSpectator()) {
if (!player.isSneaking()) { if (!player.isSneaking()) {
BlockEntity storageBlockEntity = world.getBlockEntity(pos); BlockEntity storageBlockEntity = world.getBlockEntity(pos);
if (storageBlockEntity instanceof HardDriveContainerBlockEntity) { if (storageBlockEntity instanceof HardDriveContainerBlockEntity driveContainerBlockEntity) {
player.openHandledScreen((HardDriveContainerBlockEntity) storageBlockEntity); if (driveContainerBlockEntity.network == null){
driveContainerBlockEntity.network = new StorageNetwork(world, pos, false, "");
}
player.openHandledScreen(driveContainerBlockEntity);
} }
} else { } else {

@ -16,6 +16,7 @@ import systems.brn.server_storage.blocks.InventoryInterfaceBlock;
import systems.brn.server_storage.blocks.StorageInterfaceBlock; import systems.brn.server_storage.blocks.StorageInterfaceBlock;
import systems.brn.server_storage.items.HardDrive; import systems.brn.server_storage.items.HardDrive;
import java.security.KeyStore;
import java.util.*; import java.util.*;
import static systems.brn.server_storage.ServerStorage.DRIVES; import static systems.brn.server_storage.ServerStorage.DRIVES;
@ -30,6 +31,11 @@ public class StorageNetwork {
public Map<ItemStack, Integer> itemStackMap; public Map<ItemStack, Integer> itemStackMap;
public Map<ItemStack, Integer> filteredItemStackMap; 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 driveContainerCount;
public int drivesCount; public int drivesCount;
public int driveTotalSlots; public int driveTotalSlots;
@ -37,10 +43,14 @@ public class StorageNetwork {
public int driveFreeSlots; public int driveFreeSlots;
public StorageNetwork(World world, BlockPos startPos, boolean sortAlphabetically, String searchString) { 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<HardDriveContainerBlockEntity> driveContainers = new ArrayList<>();
List<StorageInterfaceBlockEntity> storageInterfaceBlockEntities = new ArrayList<>(); List<StorageInterfaceBlockEntity> storageInterfaceBlockEntities = new ArrayList<>();
List<InventoryInterfaceBlockEntity> inventoryInterfaceBlockEntities = 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) { 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)) { if (visited.contains(pos)) {
return; return;
@ -180,6 +203,7 @@ public class StorageNetwork {
} }
public boolean canRemove(ItemStack stackToRemove) { public boolean canRemove(ItemStack stackToRemove) {
return canRemoveRemainingCount(stackToRemove, itemStackMap) == 0; return canRemoveRemainingCount(stackToRemove, itemStackMap) == 0;
} }

@ -8,6 +8,7 @@ import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.ScreenHandlerType; import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.screen.slot.Slot; import net.minecraft.screen.slot.Slot;
import systems.brn.server_storage.blockentities.HardDriveContainerBlockEntity; import systems.brn.server_storage.blockentities.HardDriveContainerBlockEntity;
import systems.brn.server_storage.lib.StorageNetwork;
public class DriveContainerScreenHandler extends ScreenHandler { public class DriveContainerScreenHandler extends ScreenHandler {
private final Inventory inventory; private final Inventory inventory;
@ -86,5 +87,6 @@ public class DriveContainerScreenHandler extends ScreenHandler {
super.onClosed(player); super.onClosed(player);
this.inventory.onClose(player); this.inventory.onClose(player);
blockEntity.indexDrives(); blockEntity.indexDrives();
blockEntity.network.reindexNetwork();
} }
} }

@ -85,6 +85,7 @@ public class StorageScreen extends PagedGui {
if (clickedElement != null && cursorStack.isEmpty()) { if (clickedElement != null && cursorStack.isEmpty()) {
ItemStack clickedItem = clickedElement.getItemStack(); ItemStack clickedItem = clickedElement.getItemStack();
ItemStack noLoreStack = removeCountFromLore(clickedItem); ItemStack noLoreStack = removeCountFromLore(clickedItem);
noLoreStack = blockEntity.network.findSimilarStack(noLoreStack);
if (type.isRight) { if (type.isRight) {
if (!type.shift) { if (!type.shift) {
noLoreStack.setCount(Math.min(noLoreStack.getMaxCount(), noLoreStack.getCount() / 2)); //half stack noLoreStack.setCount(Math.min(noLoreStack.getMaxCount(), noLoreStack.getCount() / 2)); //half stack