Search in sources :

Example 1 with BlockUtil

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());
}
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)

Aggregations

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