Search in sources :

Example 1 with Trap

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());
}
Also used : Managers(me.earth.earthhack.impl.managers.Managers) EntityEnderCrystal(net.minecraft.entity.item.EntityEnderCrystal) BooleanSetting(me.earth.earthhack.api.setting.settings.BooleanSetting) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ObbyListenerModule(me.earth.earthhack.impl.util.helpers.blocks.ObbyListenerModule) BlockUtil(me.earth.earthhack.impl.util.minecraft.blocks.BlockUtil) HoleUtil(me.earth.earthhack.impl.util.minecraft.blocks.HoleUtil) Setting(me.earth.earthhack.api.setting.Setting) HashMap(java.util.HashMap) Trap(me.earth.earthhack.impl.modules.combat.autotrap.util.Trap) ArrayList(java.util.ArrayList) MathUtil(me.earth.earthhack.impl.util.math.MathUtil) PositionUtil(me.earth.earthhack.impl.util.math.position.PositionUtil) Vec3i(net.minecraft.util.math.Vec3i) Category(me.earth.earthhack.api.module.util.Category) Map(java.util.Map) TrapTarget(me.earth.earthhack.impl.modules.combat.autotrap.modes.TrapTarget) Entity(net.minecraft.entity.Entity) TargetResult(me.earth.earthhack.impl.util.helpers.blocks.util.TargetResult) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) NumberSetting(me.earth.earthhack.api.setting.settings.NumberSetting) DamageUtil(me.earth.earthhack.impl.util.minecraft.DamageUtil) Collectors(java.util.stream.Collectors) List(java.util.List) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EnumSetting(me.earth.earthhack.api.setting.settings.EnumSetting) Comparator(java.util.Comparator) EntityUtil(me.earth.earthhack.impl.util.minecraft.entity.EntityUtil) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) BlockUtil(me.earth.earthhack.impl.util.minecraft.blocks.BlockUtil)

Example 2 with Trap

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;
}
Also used : Managers(me.earth.earthhack.impl.managers.Managers) EntityEnderCrystal(net.minecraft.entity.item.EntityEnderCrystal) BooleanSetting(me.earth.earthhack.api.setting.settings.BooleanSetting) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ObbyListenerModule(me.earth.earthhack.impl.util.helpers.blocks.ObbyListenerModule) BlockUtil(me.earth.earthhack.impl.util.minecraft.blocks.BlockUtil) HoleUtil(me.earth.earthhack.impl.util.minecraft.blocks.HoleUtil) Setting(me.earth.earthhack.api.setting.Setting) HashMap(java.util.HashMap) Trap(me.earth.earthhack.impl.modules.combat.autotrap.util.Trap) ArrayList(java.util.ArrayList) MathUtil(me.earth.earthhack.impl.util.math.MathUtil) PositionUtil(me.earth.earthhack.impl.util.math.position.PositionUtil) Vec3i(net.minecraft.util.math.Vec3i) Category(me.earth.earthhack.api.module.util.Category) Map(java.util.Map) TrapTarget(me.earth.earthhack.impl.modules.combat.autotrap.modes.TrapTarget) Entity(net.minecraft.entity.Entity) TargetResult(me.earth.earthhack.impl.util.helpers.blocks.util.TargetResult) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) NumberSetting(me.earth.earthhack.api.setting.settings.NumberSetting) DamageUtil(me.earth.earthhack.impl.util.minecraft.DamageUtil) Collectors(java.util.stream.Collectors) List(java.util.List) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EnumSetting(me.earth.earthhack.api.setting.settings.EnumSetting) Comparator(java.util.Comparator) EntityUtil(me.earth.earthhack.impl.util.minecraft.entity.EntityUtil) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

ArrayList (java.util.ArrayList)2 Comparator (java.util.Comparator)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Category (me.earth.earthhack.api.module.util.Category)2 Setting (me.earth.earthhack.api.setting.Setting)2 BooleanSetting (me.earth.earthhack.api.setting.settings.BooleanSetting)2 EnumSetting (me.earth.earthhack.api.setting.settings.EnumSetting)2 NumberSetting (me.earth.earthhack.api.setting.settings.NumberSetting)2 Managers (me.earth.earthhack.impl.managers.Managers)2 TrapTarget (me.earth.earthhack.impl.modules.combat.autotrap.modes.TrapTarget)2 Trap (me.earth.earthhack.impl.modules.combat.autotrap.util.Trap)2 ObbyListenerModule (me.earth.earthhack.impl.util.helpers.blocks.ObbyListenerModule)2 TargetResult (me.earth.earthhack.impl.util.helpers.blocks.util.TargetResult)2 MathUtil (me.earth.earthhack.impl.util.math.MathUtil)2 PositionUtil (me.earth.earthhack.impl.util.math.position.PositionUtil)2 DamageUtil (me.earth.earthhack.impl.util.minecraft.DamageUtil)2 BlockUtil (me.earth.earthhack.impl.util.minecraft.blocks.BlockUtil)2