Search in sources :

Example 16 with Pair

use of net.minecraft.util.Pair in project Biome-Makeover by Lemonszz.

the class LivingEntityMixin method tick.

@Inject(at = @At("TAIL"), method = "tick")
public void tick(CallbackInfo cbi) {
    if (!getEntityWorld().isClient()) {
        Iterator<Pair<EquipmentSlot, ItemStack>> it = attributeStacks.iterator();
        while (it.hasNext()) {
            Pair<EquipmentSlot, ItemStack> pair = it.next();
            ItemStack st = pair.getRight();
            if (!hasStackEquipInSlot(st, pair.getLeft())) {
                ItemUtil.forEachEnchantment((en, stack, lvl) -> {
                    if (en instanceof BMEnchantment) {
                        ((BMEnchantment) en).removeAttributes((LivingEntity) (Object) this, pair.getLeft());
                    }
                }, st, true);
                it.remove();
            }
        }
        for (EquipmentSlot slot : EquipmentSlot.values()) {
            ItemStack stack = getEquippedStack(slot);
            if (!stack.isEmpty()) {
                ItemUtil.forEachEnchantment((en, st, lvl) -> {
                    if (en instanceof BMEnchantment) {
                        ((BMEnchantment) en).onTick((LivingEntity) (Object) this, st, lvl);
                        if (!hasAttributeStack(st) && ((BMEnchantment) en).addAttributes((LivingEntity) (Object) this, st, slot, lvl)) {
                            attributeStacks.add(new Pair<>(slot, st));
                        }
                    }
                }, stack);
            }
        }
        if (slideTime > 0) {
            slideTime--;
            if (slideTime <= 0) {
                syncSlideTime();
            }
        } else {
            if (random.nextInt(500) == 0) {
                slideTime = 250 + random.nextInt(800);
                syncSlideTime();
            }
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) EquipmentSlot(net.minecraft.entity.EquipmentSlot) ItemStack(net.minecraft.item.ItemStack) BMEnchantment(party.lemons.biomemakeover.enchantments.BMEnchantment) Pair(net.minecraft.util.Pair)

Example 17 with Pair

use of net.minecraft.util.Pair in project Client by MatHax.

the class LeftRightListSettingScreen method abc.

private WTable abc(Consumer<List<Pair<T, Integer>>> addValues, boolean isLeft, Consumer<T> buttonAction) {
    // Create
    Cell<WTable> cell = this.table.add(theme.table()).top();
    WTable table = cell.widget();
    Consumer<T> forEach = t -> {
        if (!includeValue(t))
            return;
        table.add(getValueWidget(t));
        WPressable button = table.add(isLeft ? theme.plus() : theme.minus()).expandCellX().right().widget();
        button.action = () -> buttonAction.accept(t);
        table.row();
    };
    // Sort
    List<Pair<T, Integer>> values = new ArrayList<>();
    addValues.accept(values);
    if (!filterText.isEmpty())
        values.sort(Comparator.comparingInt(value -> -value.getRight()));
    for (Pair<T, Integer> pair : values) forEach.accept(pair.getLeft());
    if (table.cells.size() > 0)
        cell.expandX();
    return table;
}
Also used : Utils(mathax.client.utils.Utils) Pair(net.minecraft.util.Pair) GuiTheme(mathax.client.gui.GuiTheme) Collection(java.util.Collection) Registry(net.minecraft.util.registry.Registry) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) Cell(mathax.client.gui.utils.Cell) WTable(mathax.client.gui.widgets.containers.WTable) List(java.util.List) Setting(mathax.client.settings.Setting) WTextBox(mathax.client.gui.widgets.input.WTextBox) WPressable(mathax.client.gui.widgets.pressable.WPressable) Comparator(java.util.Comparator) WindowScreen(mathax.client.gui.WindowScreen) WWidget(mathax.client.gui.widgets.WWidget) WPressable(mathax.client.gui.widgets.pressable.WPressable) WTable(mathax.client.gui.widgets.containers.WTable) ArrayList(java.util.ArrayList) Pair(net.minecraft.util.Pair)

Aggregations

Pair (net.minecraft.util.Pair)17 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Collection (java.util.Collection)4 Comparator (java.util.Comparator)4 Consumer (java.util.function.Consumer)4 ItemStack (net.minecraft.item.ItemStack)4 Registry (net.minecraft.util.registry.Registry)4 BlockPos (net.minecraft.util.math.BlockPos)3 Direction (net.minecraft.util.math.Direction)3 Helper (com.qouteall.immersive_portals.Helper)2 IntegerAABBInclusive (com.qouteall.immersive_portals.my_util.IntegerAABBInclusive)2 Arrays (java.util.Arrays)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Predicate (java.util.function.Predicate)2 IntStream (java.util.stream.IntStream)2 Stream (java.util.stream.Stream)2 GuiTheme (mathax.client.gui.GuiTheme)2 WindowScreen (mathax.client.gui.WindowScreen)2