use of me.earth.earthhack.impl.modules.combat.autotrap.util.Trap 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());
}
use of me.earth.earthhack.impl.modules.combat.autotrap.util.Trap in project 3arthh4ck by 3arthqu4ke.
the class AutoTrap method positionsFromBlocked.
/**
* Creates trapping positions
* from a list of positions that
* are blocked by a player.
*
* @param blockedIn the positions to trap.
* @return trapping positions.
*/
private List<BlockPos> positionsFromBlocked(List<BlockPos> blockedIn) {
List<BlockPos> positions = new ArrayList<>();
if (!noStep.getValue() && !blockedIn.isEmpty()) {
BlockPos[] helping = findTopHelping(blockedIn, true);
for (int i = 0; i < helping.length; i++) {
BlockPos pos = helping[i];
if (pos != null) {
if (i == 1 && !upperBody.getValue() && (!blockedIn.contains(PositionUtil.getPosition().up()) || !upperFace.getValue()) && helping[5] != null) {
positions.add(helping[5]);
}
positions.add(helping[i]);
break;
}
}
}
boolean scaffold = noScaffold.getValue();
if (top.getValue()) {
blockedIn.forEach(pos -> positions.addAll(applyOffsets(pos, Trap.TOP, positions)));
} else if (blockedIn.size() == 1 && smartTop.getValue() && scaffold && mc.world.getBlockState(blockedIn.get(0).add(Trap.TOP[0])).getMaterial().isReplaceable() && mc.world.getBlockState(blockedIn.get(0).add(Trap.NO_SCAFFOLD[0])).getMaterial().isReplaceable() && mc.world.getBlockState(blockedIn.get(0).add(Trap.NO_SCAFFOLD_P[0])).getMaterial().isReplaceable()) {
blockedIn.forEach(pos -> positions.addAll(applyOffsets(pos, Trap.TOP, positions)));
if (noScaffoldPlus.getValue()) {
blockedIn.forEach(pos -> positions.addAll(applyOffsets(pos, Trap.NO_SCAFFOLD_P, positions)));
}
scaffold = false;
blockedIn.forEach(pos -> positions.addAll(applyOffsets(pos, Trap.NO_SCAFFOLD, positions)));
}
if (upperBody.getValue() || upperFace.getValue() && blockedIn.contains(PositionUtil.getPosition().up())) {
blockedIn.forEach(pos -> positions.addAll(applyOffsets(pos, Trap.OFFSETS, positions)));
}
// Only apply these if we dont need to extend, otherwise overkill
if (blockedIn.size() == 1 || bigExtend.getValue()) {
if (scaffold) {
blockedIn.forEach(pos -> positions.addAll(applyOffsets(pos, Trap.NO_SCAFFOLD, positions)));
}
if (noStep.getValue()) {
blockedIn.forEach(pos -> positions.addAll(applyOffsets(pos, Trap.NO_STEP, positions)));
}
if (legs.getValue()) {
blockedIn.forEach(pos -> positions.addAll(applyOffsets(pos, Trap.LEGS, positions)));
}
if (platform.getValue()) {
blockedIn.forEach(pos -> positions.addAll(applyOffsets(pos, Trap.PLATFORM, positions)));
}
if (noDrop.getValue()) {
blockedIn.forEach(pos -> positions.addAll(applyOffsets(pos, Trap.NO_DROP, positions)));
}
}
return positions;
}
Aggregations