Skip to content

Commit

Permalink
Avoid categorizing unstackable item entities by count
Browse files Browse the repository at this point in the history
  • Loading branch information
2No2Name committed Nov 28, 2023
1 parent d356408 commit e69288e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ protected void initialize() {
}

abstract Category getCategory(T element);
abstract boolean areSubcategoriesAlwaysEmpty(Category category);
abstract boolean isSubCategoryA(T element);
abstract boolean isSubCategoryB(T element);
abstract void onElementSubcategorized(T element, int index);
Expand Down Expand Up @@ -96,7 +97,7 @@ public LazyIterationConsumer.NextIteration consumeCategory(LazyIterationConsumer

public LazyIterationConsumer.NextIteration consumeCategoryA(LazyIterationConsumer<T> elementConsumer, Category category) {
IntArrayList categoryList = this.elementsByTypeA.get(category);
if (categoryList == null) {
if (categoryList == null && !this.areSubcategoriesAlwaysEmpty(category)) {
categoryList = this.elementsByType.get(category);
}

Expand All @@ -105,7 +106,7 @@ public LazyIterationConsumer.NextIteration consumeCategoryA(LazyIterationConsume

public LazyIterationConsumer.NextIteration consumeCategoryB(LazyIterationConsumer<T> elementConsumer, Category category) {
IntArrayList categoryList = this.elementsByTypeB.get(category);
if (categoryList == null) {
if (categoryList == null && !this.areSubcategoriesAlwaysEmpty(category)) {
categoryList = this.elementsByType.get(category);
}

Expand Down Expand Up @@ -136,6 +137,10 @@ private LazyIterationConsumer.NextIteration consumeElements(LazyIterationConsume
}

private void initSubCategories(Category category, IntArrayList source) {
if (this.areSubcategoriesAlwaysEmpty(category)) {
return;
}

IntArrayList categoryListA = new IntArrayList();
IntArrayList categoryListB = new IntArrayList();
this.elementsByTypeA.put(category, categoryListA);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ Item getCategory(ItemStack itemStack) {
return ((ItemStackAccessor) (Object) itemStack).lithium$getItem();
}

@Override
boolean areSubcategoriesAlwaysEmpty(Item item) {
return item.getMaxCount() == 1;
}

// If there are enough item entities in one category, divide the item entities into 3 buckets:
// Stacks that are more than 50% full can only merge with stacks that are less than 50% full, etc.
// Buckets: A B *
Expand Down

0 comments on commit e69288e

Please sign in to comment.