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++;
}
}
}
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;
}
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);
});
}
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);
}
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;
}
Aggregations