Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.client.gui.components.EditBox;
import net.minecraft.core.NonNullList;
import net.minecraft.network.chat.Component;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.Slot;
import org.cyclops.cyclopscore.client.gui.component.WidgetScrollBar;
Expand Down Expand Up @@ -62,7 +63,7 @@ public void init() {
this.scrollbar = new WidgetScrollBar(this.leftPos + getScrollX(), this.topPos + getScrollY(), getScrollHeight(),
Component.translatable("gui.cyclopscore.scrollbar"), getMenu(),
getMenu().getPageSize(), getScrollRegion());
this.scrollbar.setTotalRows(getMenu().getFilteredItemCount() / getMenu().getColumns());
this.scrollbar.setTotalRows(getTotalRows());
} else {
this.scrollbar.setX(this.leftPos + getScrollX());
this.scrollbar.setY(this.topPos + getScrollY());
Expand Down Expand Up @@ -147,10 +148,22 @@ public boolean mouseDragged(double mouseX, double mouseY, int mouseButton, doubl

protected void updateSearch(String searchString) {
getMenu().updateFilter(searchString);
this.scrollbar.setTotalRows(getMenu().getFilteredItemCount() / getMenu().getColumns());
this.scrollbar.setTotalRows(getTotalRows());
this.scrollbar.scrollTo(0);
}

/**
* The number of rows that the filtered elements occupy.
*
* This is rounded up, as a last row that is only partially filled
* must still be reachable by the scrollbar.
*
* @return The number of rows.
*/
protected int getTotalRows() {
return Mth.ceil((double) getMenu().getFilteredItemCount() / getMenu().getColumns());
}

public EditBox getSearchField() {
return searchField;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public ScrollingInventoryContainer(@Nullable MenuType<?> type, int id, Inventory
this.unfilteredItems = Lists.newArrayList(items);
this.filteredItems = Lists.newLinkedList();
this.visibleItems = (List<E>) Arrays.asList(new Object[getPageSize() * getColumns()]);
for(int i = 0; i < getPageSize(); i++) {
for(int i = 0; i < this.visibleItems.size(); i++) {
this.visibleItems.set(i, null);
}
this.itemSearchPredicate = filterer;
Expand Down Expand Up @@ -114,11 +114,11 @@ protected void enableElementAt(int visibleIndex, int elementIndex, E element) {

/**
* Check if the given element is visible.
* @param row The row the the given element is at.
* @param row The index of the given element within the visible elements.
* @return If it is visible.
*/
public boolean isElementVisible(int row) {
return row < getPageSize() && getVisibleElement(row) != null;
return row < getPageSize() * getColumns() && getVisibleElement(row) != null;
}

/**
Expand Down
Loading