use of me.earth.earthhack.impl.util.minecraft.blocks.BlockUtil in project 3arthh4ck by 3arthqu4ke.
the class AutoTrap method getPositions.
/**
* Gets the positions to trap
* for the given player. Takes extend
* and the noScaffold... etc. settings into
* account.
*
* @param player the player to trap.
* @return trapping positions.
*/
private List<BlockPos> getPositions(EntityPlayer player) {
List<BlockPos> blocked = new ArrayList<>();
BlockPos playerPos = new BlockPos(player);
if (HoleUtil.isHole(playerPos, false)[0] || extend.getValue() == 1) {
blocked.add(playerPos.up());
} else {
List<BlockPos> unfiltered = new ArrayList<>(PositionUtil.getBlockedPositions(player)).stream().sorted(Comparator.comparingDouble(BlockUtil::getDistanceSq)).collect(Collectors.toList());
List<BlockPos> filtered = new ArrayList<>(unfiltered).stream().filter(pos -> mc.world.getBlockState(pos).getMaterial().isReplaceable() && mc.world.getBlockState(pos.up()).getMaterial().isReplaceable()).collect(Collectors.toList());
if (extend.getValue() == 3 && filtered.size() == 2 && unfiltered.size() == 4) {
/*
Prevents that a pos like this
(x == block, o == air, i = player):
o x x
x i can extend to this: x o x
x i
*/
if (unfiltered.get(0).equals(filtered.get(0)) && unfiltered.get(3).equals(filtered.get(1))) {
filtered.clear();
}
}
if (extend.getValue() == 2 && filtered.size() > 2 || extend.getValue() == 3 && filtered.size() == 3) {
/*
Prevents that a pos like this
(x == block, o == air, i = player):
x o x
i can extend to this: x o x
x i x
x x
we should, unless he phased in, be able to place on o
*/
while (filtered.size() > 2) {
filtered.remove(filtered.size() - 1);
}
}
for (BlockPos pos : filtered) {
blocked.add(pos.up());
}
}
if (blocked.isEmpty()) {
blocked.add(playerPos.up());
}
List<BlockPos> positions = positionsFromBlocked(blocked);
// sort so we start placing behind (furthest away) first.
positions.sort(Comparator.comparingDouble(pos -> -BlockUtil.getDistanceSq(pos)));
// sort by y so we start placing from bottom up.
positions.sort(Comparator.comparingInt(Vec3i::getY));
return positions.stream().filter(pos -> BlockUtil.getDistanceSq(pos) <= MathUtil.square(range.getValue())).collect(Collectors.toList());
}
Aggregations