Fix filtering

This commit is contained in:
Bruno Rybársky 2024-07-04 19:00:44 +02:00
parent 71a391b9c9
commit 460a499307
2 changed files with 10 additions and 6 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.0 mod_version=3.0.1
maven_group=systems.brn maven_group=systems.brn
archives_base_name=Server_storage archives_base_name=Server_storage

@ -61,15 +61,15 @@ public class StorageScreen extends PagedGui {
@Override @Override
protected int getPageAmount() { protected int getPageAmount() {
return Math.ceilDivExact(blockEntity.network.itemStackMap.size(), 9 * 6); return Math.ceilDivExact(blockEntity.network.filteredItemStackMap.size(), 9 * 6);
} }
@Override @Override
protected DisplayElement getElement(int id) { protected DisplayElement getElement(int id) {
if (blockEntity.network.itemStackMap.size() > id) { if (blockEntity.network.filteredItemStackMap.size() > id) {
ItemStack itemStackKey = (ItemStack) blockEntity.network.itemStackMap.keySet().toArray()[id]; ItemStack itemStackKey = (ItemStack) blockEntity.network.filteredItemStackMap.keySet().toArray()[id];
ItemStack aestheticStack = itemStackKey.copy(); ItemStack aestheticStack = itemStackKey.copy();
int count = blockEntity.network.itemStackMap.get(itemStackKey); int count = blockEntity.network.filteredItemStackMap.get(itemStackKey);
aestheticStack.setCount(Math.min(aestheticStack.getMaxCount(), count)); aestheticStack.setCount(Math.min(aestheticStack.getMaxCount(), count));
ItemStack newStack = addCountToLore(count, aestheticStack, null); ItemStack newStack = addCountToLore(count, aestheticStack, null);
GuiElementBuilder guiElement = new GuiElementBuilder(newStack); GuiElementBuilder guiElement = new GuiElementBuilder(newStack);
@ -137,9 +137,13 @@ public class StorageScreen extends PagedGui {
@Override @Override
protected DisplayElement search() { protected DisplayElement search() {
String searchString = blockEntity.searchString;
if (searchString == null || searchString.isEmpty() || searchString.equals("*")) {
searchString = "Filter not set";
}
return DisplayElement.of( return DisplayElement.of(
new GuiElementBuilder(Items.PLAYER_HEAD) new GuiElementBuilder(Items.PLAYER_HEAD)
.setName(Text.translatable("itemGroup.search").formatted(Formatting.WHITE)) .setName(Text.literal(searchString).formatted(Formatting.WHITE))
.hideDefaultTooltip().noDefaults() .hideDefaultTooltip().noDefaults()
.setSkullOwner(GUI_QUESTION_MARK) .setSkullOwner(GUI_QUESTION_MARK)
.setCallback((x, y, z) -> { .setCallback((x, y, z) -> {