Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring GT++ 2025-02-13 #3948

Merged
merged 12 commits into from
Feb 16, 2025
Prev Previous commit
Next Next commit
TypeCounter
  • Loading branch information
serenibyss committed Feb 13, 2025
commit 4f096ceb45ce8891f13c5624842fcedc0e88d5ad
175 changes: 0 additions & 175 deletions src/main/java/gtPlusPlus/api/objects/data/TypeCounter.java

This file was deleted.

14 changes: 10 additions & 4 deletions src/main/java/gtPlusPlus/core/util/minecraft/MaterialUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gtPlusPlus.core.util.minecraft;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
Expand All @@ -16,7 +17,6 @@
import gregtech.api.enums.TextureSet;
import gregtech.api.util.GTUtility;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.api.objects.data.TypeCounter;
import gtPlusPlus.core.client.CustomTextureSet.TextureSets;
import gtPlusPlus.core.item.base.BaseItemComponent;
import gtPlusPlus.core.item.base.BaseItemComponent.ComponentTypes;
Expand All @@ -29,6 +29,8 @@
import gtPlusPlus.core.util.Utils;
import gtPlusPlus.core.util.data.StringUtils;
import gtPlusPlus.core.util.math.MathUtils;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;

public class MaterialUtils {

Expand Down Expand Up @@ -247,17 +249,21 @@ public static String getMaterialName(Materials mat) {
}

public static TextureSet getMostCommonTextureSet(List<Material> list) {
TypeCounter<TextureSet> aCounter = new TypeCounter<>(TextureSet.class);
Object2IntMap<TextureSet> counter = new Object2IntOpenHashMap<>();
for (Material m : list) {
TextureSet t = m.getTextureSet();
if (t == null) {
t = Materials.Gold.mIconSet;
}
if (t != null) {
aCounter.add(t, t.mSetName);
counter.put(t, counter.getInt(t) + 1);
}
}
return aCounter.getResults();
return counter.object2IntEntrySet()
.stream()
.max(Comparator.comparingInt(Object2IntMap.Entry::getIntValue))
.map(Map.Entry::getKey)
.orElse(Materials.Gold.mIconSet);
}

public static Materials getMaterial(String aMaterialName, String aFallbackMaterialName) {
Expand Down