Search in sources :

Example 1 with Pair

use of de.budschie.bmorph.util.Pair in project BudschieMorphMod by Budschie.

the class FilteredSimpleMorphGui method showGui.

@Override
public void showGui() {
    @SuppressWarnings("resource") LazyOptional<IMorphCapability> cap = Minecraft.getInstance().player.getCapability(MorphCapabilityAttacher.MORPH_CAP);
    if (cap.isPresent()) {
        IMorphCapability resolved = cap.resolve().get();
        // Create a list of indices of morphs
        List<Integer> morphList = new ArrayList<>();
        // This is dumb
        for (int i = 0; i < resolved.getMorphList().getMorphArrayList().size(); i++) {
            if (filter.test(resolved, i))
                morphList.add(i);
        }
        morphWidgets.add(new MorphWidget(null, false, -1));
        HashMap<EntityType<?>, Pair<MorphWidget, Integer>> currentWidgetHeads = new HashMap<>();
        for (int i = 0; i < morphList.size(); i++) {
            int indexOfMorph = morphList.get(i);
            MorphItem item = resolved.getMorphList().getMorphArrayList().get(indexOfMorph);
            MorphWidget widget = new MorphWidget(item, resolved.getFavouriteList().containsMorphItem(item), indexOfMorph);
            Pair<MorphWidget, Integer> currentWidgetHead = currentWidgetHeads.get(widget.morphItem.getEntityType());
            // Check if there is a head.
            if (currentWidgetHead != null) {
                // There is a head, add to head
                MorphWidget head = currentWidgetHead.getA();
                head.child = widget;
            } else {
                // No head, add to widget list
                morphWidgets.add(widget);
            }
            // Set as new entity head
            currentWidgetHeads.put(widget.morphItem.getEntityType(), new Pair<>(widget, currentWidgetHead == null ? 0 : currentWidgetHead.getB() + 1));
        }
        for (int i = 1; i < morphWidgets.size(); i++) {
            MorphWidget widget = morphWidgets.get(i);
            Pair<MorphWidget, Integer> currentWidgetHead = currentWidgetHeads.get(widget.morphItem.getEntityType());
            widget.depth = currentWidgetHead.getB();
        }
    }
}
Also used : IMorphCapability(de.budschie.bmorph.capabilities.IMorphCapability) MorphItem(de.budschie.bmorph.morph.MorphItem) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EntityType(net.minecraft.entity.EntityType) Pair(de.budschie.bmorph.util.Pair)

Aggregations

IMorphCapability (de.budschie.bmorph.capabilities.IMorphCapability)1 MorphItem (de.budschie.bmorph.morph.MorphItem)1 Pair (de.budschie.bmorph.util.Pair)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 EntityType (net.minecraft.entity.EntityType)1