Search in sources :

Example 6 with Pair

use of net.minecraft.util.Pair in project VeinMining by TheIllusiveC4.

the class VeinMiningLogic method startVeinMining.

public static void startVeinMining(ServerPlayerEntity playerEntity, BlockPos pos, BlockState source) {
    ServerWorld world = playerEntity.getWorld();
    ItemStack stack = playerEntity.getMainHandStack();
    if (!VeinMiningPlayers.canVeinMine(playerEntity)) {
        return;
    }
    boolean ineffective = VeinMiningConfig.VeinMining.requireEffectiveTool && stack.getMiningSpeedMultiplier(source) <= 1.0F;
    if (ineffective) {
        return;
    }
    int veiningLevels = EnchantmentHelper.getLevel(VeinMiningMod.VEIN_MINING, stack);
    int maxBlocks = VeinMiningConfig.VeinMining.maxBlocksBase + VeinMiningConfig.VeinMining.maxBlocksPerLevel * veiningLevels;
    int maxDistance = VeinMiningConfig.VeinMining.maxDistanceBase + VeinMiningConfig.VeinMining.maxDistancePerLevel * veiningLevels;
    if (maxBlocks <= 0 || maxDistance <= 0) {
        return;
    }
    int blocks = 0;
    Set<BlockPos> visited = Sets.newHashSet(pos);
    LinkedList<Pair<BlockPos, Integer>> candidates = new LinkedList<>();
    addValidNeighbors(candidates, pos, 1);
    Block sourceBlock = source.getBlock();
    while (!candidates.isEmpty() && blocks < maxBlocks) {
        Pair<BlockPos, Integer> candidate = candidates.poll();
        BlockPos blockPos = candidate.getLeft();
        int blockDistance = candidate.getRight();
        if (stopVeining(stack)) {
            return;
        }
        BlockState state = world.getBlockState(blockPos);
        if (visited.add(blockPos) && BlockProcessor.isValidTarget(state, world, blockPos, sourceBlock) && harvest(playerEntity, blockPos, pos)) {
            if (blockDistance < maxDistance) {
                addValidNeighbors(candidates, blockPos, blockDistance + 1);
            }
            blocks++;
        }
    }
}
Also used : LinkedList(java.util.LinkedList) ServerWorld(net.minecraft.server.world.ServerWorld) BlockState(net.minecraft.block.BlockState) CommandBlock(net.minecraft.block.CommandBlock) Block(net.minecraft.block.Block) JigsawBlock(net.minecraft.block.JigsawBlock) StructureBlock(net.minecraft.block.StructureBlock) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) Pair(net.minecraft.util.Pair)

Example 7 with Pair

use of net.minecraft.util.Pair in project meteor-client by MeteorDevelopment.

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 : WTextBox(meteordevelopment.meteorclient.gui.widgets.input.WTextBox) Setting(meteordevelopment.meteorclient.settings.Setting) Pair(net.minecraft.util.Pair) GuiTheme(meteordevelopment.meteorclient.gui.GuiTheme) WPressable(meteordevelopment.meteorclient.gui.widgets.pressable.WPressable) Collection(java.util.Collection) Cell(meteordevelopment.meteorclient.gui.utils.Cell) WTable(meteordevelopment.meteorclient.gui.widgets.containers.WTable) Registry(net.minecraft.util.registry.Registry) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) List(java.util.List) WindowScreen(meteordevelopment.meteorclient.gui.WindowScreen) Comparator(java.util.Comparator) WWidget(meteordevelopment.meteorclient.gui.widgets.WWidget) Utils(meteordevelopment.meteorclient.utils.Utils) WPressable(meteordevelopment.meteorclient.gui.widgets.pressable.WPressable) WTable(meteordevelopment.meteorclient.gui.widgets.containers.WTable) ArrayList(java.util.ArrayList) Pair(net.minecraft.util.Pair)

Example 8 with Pair

use of net.minecraft.util.Pair in project meteor-client by MeteorDevelopment.

the class LeftRightListSettingScreen method initWidgets.

private void initWidgets(Registry<T> registry) {
    // Left (all)
    WTable left = abc(pairs -> registry.forEach(t -> {
        if (skipValue(t) || collection.contains(t))
            return;
        int words = Utils.search(getValueName(t), filterText);
        if (words > 0)
            pairs.add(new Pair<>(t, words));
    }), true, t -> {
        addValue(registry, t);
        T v = getAdditionalValue(t);
        if (v != null)
            addValue(registry, v);
    });
    if (left.cells.size() > 0)
        table.add(theme.verticalSeparator()).expandWidgetY();
    // Right (selected)
    abc(pairs -> {
        for (T value : collection) {
            if (skipValue(value))
                continue;
            int words = Utils.search(getValueName(value), filterText);
            if (words > 0)
                pairs.add(new Pair<>(value, words));
        }
    }, false, t -> {
        removeValue(registry, t);
        T v = getAdditionalValue(t);
        if (v != null)
            removeValue(registry, v);
    });
}
Also used : WTextBox(meteordevelopment.meteorclient.gui.widgets.input.WTextBox) Setting(meteordevelopment.meteorclient.settings.Setting) Pair(net.minecraft.util.Pair) GuiTheme(meteordevelopment.meteorclient.gui.GuiTheme) WPressable(meteordevelopment.meteorclient.gui.widgets.pressable.WPressable) Collection(java.util.Collection) Cell(meteordevelopment.meteorclient.gui.utils.Cell) WTable(meteordevelopment.meteorclient.gui.widgets.containers.WTable) Registry(net.minecraft.util.registry.Registry) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) List(java.util.List) WindowScreen(meteordevelopment.meteorclient.gui.WindowScreen) Comparator(java.util.Comparator) WWidget(meteordevelopment.meteorclient.gui.widgets.WWidget) Utils(meteordevelopment.meteorclient.utils.Utils) WTable(meteordevelopment.meteorclient.gui.widgets.containers.WTable) Pair(net.minecraft.util.Pair)

Example 9 with Pair

use of net.minecraft.util.Pair in project ImmersivePortalsMod by qouteall.

the class NetherPortalMatcher method findEmptyObsidianFrame.

// ------------------------------------------------------------
// detect existing obsidian frame
// @Nullable
public static ObsidianFrame findEmptyObsidianFrame(IWorld world, BlockPos searchingCenter, Direction.Axis normalAxis, Predicate<IntegerAABBInclusive> filter, int findingRadius) {
    Pair<Direction.Axis, Direction.Axis> anotherTwoAxis = Helper.getAnotherTwoAxis(normalAxis);
    Direction roughTestObsidianFace1 = Direction.get(Direction.AxisDirection.POSITIVE, anotherTwoAxis.getLeft());
    Direction roughTestObsidianFace2 = Direction.get(Direction.AxisDirection.POSITIVE, anotherTwoAxis.getRight());
    Optional<ObsidianFrame> result = fromNearToFarWithinHeightLimit(searchingCenter, findingRadius, heightLimitOverworld).filter(blockPos -> isAirOnObsidian(world, blockPos, roughTestObsidianFace1, roughTestObsidianFace2)).map(blockPos -> detectFrameFromInnerPos(world, blockPos, normalAxis, filter)).filter(Objects::nonNull).findFirst();
    return result.orElse(null);
}
Also used : IntStream(java.util.stream.IntStream) Pair(net.minecraft.util.Pair) Arrays(java.util.Arrays) Predicate(java.util.function.Predicate) IWorld(net.minecraft.world.IWorld) BlockPos(net.minecraft.util.math.BlockPos) Helper(com.qouteall.immersive_portals.Helper) IntegerAABBInclusive(com.qouteall.immersive_portals.my_util.IntegerAABBInclusive) Blocks(net.minecraft.block.Blocks) Direction(net.minecraft.util.math.Direction) Objects(java.util.Objects) Vec3i(net.minecraft.util.math.Vec3i) Stream(java.util.stream.Stream) DimensionType(net.minecraft.world.dimension.DimensionType) Optional(java.util.Optional) Direction(net.minecraft.util.math.Direction)

Example 10 with Pair

use of net.minecraft.util.Pair in project ImmersivePortalsMod by qouteall.

the class NetherPortalMatcher method detectInnerArea.

private static IntegerAABBInclusive detectInnerArea(IWorld world, BlockPos innerPos, Direction.Axis normalAxis, Pair<Direction.Axis, Direction.Axis> anotherTwoAxis) {
    IntegerAABBInclusive stick1 = detectStick(world, innerPos, anotherTwoAxis.getLeft(), blockPos -> isAirOrFire(world, blockPos), 1);
    if (stick1 == null)
        return null;
    IntegerAABBInclusive stick2 = detectStick(world, innerPos, anotherTwoAxis.getRight(), blockPos -> isAirOrFire(world, blockPos), 1);
    if (stick2 == null)
        return null;
    IntegerAABBInclusive innerArea = IntegerAABBInclusive.getContainingBox(stick1, stick2);
    assert Math.abs(Helper.getCoordinate(innerArea.getSize(), normalAxis)) == 1;
    // check inner air
    if (!innerArea.stream().allMatch(blockPos -> isAirOrFire(world, blockPos))) {
        return null;
    }
    return innerArea;
}
Also used : IntStream(java.util.stream.IntStream) Pair(net.minecraft.util.Pair) Arrays(java.util.Arrays) Predicate(java.util.function.Predicate) IWorld(net.minecraft.world.IWorld) BlockPos(net.minecraft.util.math.BlockPos) Helper(com.qouteall.immersive_portals.Helper) IntegerAABBInclusive(com.qouteall.immersive_portals.my_util.IntegerAABBInclusive) Blocks(net.minecraft.block.Blocks) Direction(net.minecraft.util.math.Direction) Objects(java.util.Objects) Vec3i(net.minecraft.util.math.Vec3i) Stream(java.util.stream.Stream) DimensionType(net.minecraft.world.dimension.DimensionType) Optional(java.util.Optional) IntegerAABBInclusive(com.qouteall.immersive_portals.my_util.IntegerAABBInclusive)

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