Search in sources :

Example 1 with IPlayerControllerMP

use of cope.cosmos.asm.mixins.accessor.IPlayerControllerMP in project cosmos by momentumdevelopment.

the class AutoCrystalModule method explodeCrystal.

/**
 * Explodes the ideal crystal
 */
public void explodeCrystal() {
    if (explodeCrystal != null) {
        if (!rotate.getValue().equals(Rotate.NONE) && (rotateWhen.getValue().equals(When.BREAK) || rotateWhen.getValue().equals(When.BOTH))) {
            // our last interaction will be the attack on the crystal
            interactVector = explodeCrystal.getCrystal().getPositionVector();
            if (rotate.getValue().equals(Rotate.CLIENT)) {
                Rotation explodeAngles = AngleUtil.calculateAngles(interactVector);
                // update our players rotation
                mc.player.rotationYaw = explodeAngles.getYaw();
                mc.player.rotationYawHead = explodeAngles.getYaw();
                mc.player.rotationPitch = explodeAngles.getPitch();
            }
        }
        if (!explodeWeakness.getValue().equals(Switch.NONE)) {
            // strength and weakness effects on the player
            PotionEffect weaknessEffect = mc.player.getActivePotionEffect(MobEffects.WEAKNESS);
            PotionEffect strengthEffect = mc.player.getActivePotionEffect(MobEffects.STRENGTH);
            // verify that we cannot break the crystal due to weakness
            if (weaknessEffect != null && (strengthEffect == null || strengthEffect.getAmplifier() < weaknessEffect.getAmplifier())) {
                // find the slots of our tools
                int swordSlot = getCosmos().getInventoryManager().searchSlot(Items.DIAMOND_SWORD, InventoryRegion.HOTBAR);
                int pickSlot = getCosmos().getInventoryManager().searchSlot(Items.DIAMOND_SWORD, InventoryRegion.HOTBAR);
                if (!InventoryUtil.isHolding(Items.DIAMOND_SWORD) || !InventoryUtil.isHolding(Items.DIAMOND_PICKAXE)) {
                    // log the previous slot
                    previousSlot = mc.player.inventory.currentItem;
                    // prefer the sword over a pickaxe
                    if (swordSlot != -1) {
                        getCosmos().getInventoryManager().switchToSlot(swordSlot, explodeWeakness.getValue());
                        // sync item
                        if (placeSwitch.getValue().equals(Switch.PACKET)) {
                            ((IPlayerControllerMP) mc.playerController).hookSyncCurrentPlayItem();
                        }
                    } else if (pickSlot != -1) {
                        getCosmos().getInventoryManager().switchToSlot(pickSlot, explodeWeakness.getValue());
                        // sync item
                        if (placeSwitch.getValue().equals(Switch.PACKET)) {
                            ((IPlayerControllerMP) mc.playerController).hookSyncCurrentPlayItem();
                        }
                    }
                }
            }
        }
        if (explodeTimer.passedTime(explodeDelay.getValue().longValue() + ThreadLocalRandom.current().nextInt(explodeRandom.getValue().intValue() + 1), Format.MILLISECONDS) && switchTimer.passedTime(explodeSwitch.getValue().longValue(), Format.MILLISECONDS)) {
            // explode the crystal
            explodeCrystal(explodeCrystal.getCrystal(), explodePacket.getValue());
            swingCrystal(explodeHand.getValue());
            explodeTimer.resetTime();
            // add crystal to our list of attempted explosions and resetTime the clearance
            attemptedExplosions.put(explodeCrystal.getCrystal().getEntityId(), attemptedExplosions.containsKey(explodeCrystal.getCrystal().getEntityId()) ? attemptedExplosions.get(explodeCrystal.getCrystal().getEntityId()) + 1 : 1);
            // remove the crystal after we break -> i.e. instantly
            if (sync.getValue().equals(Sync.INSTANT)) {
                mc.world.removeEntityDangerously(explodeCrystal.getCrystal());
            }
            // switch to our previous slot
            if (explodeWeakness.getValue().equals(Switch.PACKET) && previousSlot != -1) {
                getCosmos().getInventoryManager().switchToSlot(previousSlot, explodeWeakness.getValue());
                // reset our previous slot
                previousSlot = -1;
            }
        }
    }
}
Also used : IPlayerControllerMP(cope.cosmos.asm.mixins.accessor.IPlayerControllerMP) PotionEffect(net.minecraft.potion.PotionEffect) Rotation(cope.cosmos.util.holder.Rotation)

Example 2 with IPlayerControllerMP

use of cope.cosmos.asm.mixins.accessor.IPlayerControllerMP in project cosmos by momentumdevelopment.

the class AutoCrystalModule method placeCrystal.

/**
 * Places a crystal at the searched placement position
 */
public void placeCrystal() {
    if (placePosition != null) {
        if (!rotate.getValue().equals(Rotate.NONE) && (rotateWhen.getValue().equals(When.PLACE) || rotateWhen.getValue().equals(When.BOTH))) {
            // our last interaction will be the placement on the block
            interactVector = new Vec3d(placePosition.getPosition()).addVector(0.5, 0.5, 0.5);
            if (rotate.getValue().equals(Rotate.CLIENT)) {
                Rotation placeAngles = AngleUtil.calculateAngles(interactVector);
                // update our players rotation
                mc.player.rotationYaw = placeAngles.getYaw();
                mc.player.rotationYawHead = placeAngles.getYaw();
                mc.player.rotationPitch = placeAngles.getPitch();
            }
        }
        // log our previous slot and hand, we'll switch back after placing
        if (placeSwitch.getValue().equals(Switch.PACKET)) {
            previousSlot = mc.player.inventory.currentItem;
        }
        // pause switch to account for eating
        if (PlayerUtil.isEating()) {
            switchTicks = 0;
        }
        // sync item
        if (placeSwitch.getValue().equals(Switch.NORMAL)) {
            ((IPlayerControllerMP) mc.playerController).hookSyncCurrentPlayItem();
        }
        switchTicks++;
        // switch to crystals if needed
        if (!InventoryUtil.isHolding(Items.END_CRYSTAL)) {
            // wait for switch pause
            if (switchTicks <= 10 && placeSwitch.getValue().equals(Switch.NORMAL)) {
                return;
            }
            getCosmos().getInventoryManager().switchToItem(Items.END_CRYSTAL, placeSwitch.getValue());
            // sync item
            if (placeSwitch.getValue().equals(Switch.PACKET)) {
                ((IPlayerControllerMP) mc.playerController).hookSyncCurrentPlayItem();
            }
        }
        if (placeTimer.passedTime(placeDelay.getValue().longValue(), Format.MILLISECONDS) && (InventoryUtil.isHolding(Items.END_CRYSTAL) || placeSwitch.getValue().equals(Switch.PACKET))) {
            // directions of placement
            double facingX = 0;
            double facingY = 0;
            double facingZ = 0;
            // assume the face is visible
            EnumFacing facingDirection = EnumFacing.UP;
            // the angles to the last interaction
            Rotation vectorAngles = AngleUtil.calculateAngles(interactVector);
            // vector from the angles
            Vec3d placeVector = AngleUtil.getVectorForRotation(new Rotation(vectorAngles.getYaw(), vectorAngles.getPitch()));
            RayTraceResult vectorResult = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1), mc.player.getPositionEyes(1).addVector(placeVector.x * placeRange.getValue(), placeVector.y * placeRange.getValue(), placeVector.z * placeRange.getValue()), false, false, true);
            // make sure the direction we are facing is consistent with our rotations
            switch(placeInteraction.getValue()) {
                case NONE:
                    facingDirection = EnumFacing.DOWN;
                    facingX = 0.5;
                    facingY = 0.5;
                    facingZ = 0.5;
                    break;
                case NORMAL:
                    // find the direction to place against
                    RayTraceResult laxResult = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1), interactVector);
                    if (laxResult != null && laxResult.typeOfHit.equals(RayTraceResult.Type.BLOCK)) {
                        facingDirection = laxResult.sideHit;
                        // if we're at world height, we can still place a crystal if we interact with the bottom of the block, this doesn't work on strict servers
                        if (placePosition.getPosition().getY() >= (mc.world.getActualHeight() - 1)) {
                            facingDirection = EnumFacing.DOWN;
                        }
                    }
                    // find rotations based on the placement
                    if (vectorResult != null && vectorResult.hitVec != null) {
                        facingX = vectorResult.hitVec.x - placePosition.getPosition().getX();
                        facingY = vectorResult.hitVec.y - placePosition.getPosition().getY();
                        facingZ = vectorResult.hitVec.z - placePosition.getPosition().getZ();
                    }
                    break;
                case STRICT:
                    // if the place position is likely out of sight
                    if (placePosition.getPosition().getY() > mc.player.posY + mc.player.getEyeHeight()) {
                        // the place vectors lowest bounds
                        Vec3d strictVector = new Vec3d(placePosition.getPosition());
                        // our nearest visible face
                        Pair<Double, EnumFacing> closestDirection = Pair.of(Double.MAX_VALUE, EnumFacing.UP);
                        // iterate through all points on the block
                        for (float x = 0; x <= 1; x += 0.05) {
                            for (float y = 0; y <= 1; y += 0.05) {
                                for (float z = 0; z <= 1; z += 0.05) {
                                    // find the vector to raytrace to
                                    Vec3d traceVector = strictVector.addVector(x, y, z);
                                    // check visibility, raytrace to the current point
                                    RayTraceResult strictResult = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1), traceVector, false, true, false);
                                    // if our raytrace is a block, check distances
                                    if (strictResult != null && strictResult.typeOfHit.equals(RayTraceResult.Type.BLOCK)) {
                                        // distance to face
                                        double directionDistance = mc.player.getDistance(traceVector.x, traceVector.y, traceVector.z);
                                        // if the face is the closest to the player and trace distance is reasonably close, then we have found a new ideal visible side to place against
                                        if (directionDistance < closestDirection.first()) {
                                            closestDirection = Pair.of(directionDistance, strictResult.sideHit);
                                        }
                                    }
                                }
                            }
                        }
                        facingDirection = closestDirection.second();
                    }
                    // find rotations based on the placement
                    if (vectorResult != null && vectorResult.hitVec != null) {
                        facingX = vectorResult.hitVec.x - placePosition.getPosition().getX();
                        facingY = vectorResult.hitVec.y - placePosition.getPosition().getY();
                        facingZ = vectorResult.hitVec.z - placePosition.getPosition().getZ();
                    }
                    break;
            }
            // place the crystal
            placeCrystal(placePosition.getPosition(), facingDirection, new Vec3d(facingX, facingY, facingZ), placePacket.getValue());
            swingCrystal(placeHand.getValue());
            // switch back after placing, should only switch serverside
            if (placeSwitch.getValue().equals(Switch.PACKET)) {
                getCosmos().getInventoryManager().switchToSlot(previousSlot, placeSwitch.getValue());
                // reset previous slot
                previousSlot = -1;
            }
            placeTimer.resetTime();
            // add placement to our list of attempted placement and resetTime clearance
            attemptedPlacements.put(placePosition.getPosition(), attemptedPlacements.containsKey(placePosition.getPosition()) ? attemptedPlacements.get(placePosition.getPosition()) + 1 : 1);
        }
    }
}
Also used : IPlayerControllerMP(cope.cosmos.asm.mixins.accessor.IPlayerControllerMP) EnumFacing(net.minecraft.util.EnumFacing) Rotation(cope.cosmos.util.holder.Rotation)

Example 3 with IPlayerControllerMP

use of cope.cosmos.asm.mixins.accessor.IPlayerControllerMP in project cosmos by momentumdevelopment.

the class AutoCrystalModule method onPacketReceive.

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onPacketReceive(PacketEvent.PacketReceiveEvent event) {
    // packet for crystal spawns
    if (event.getPacket() instanceof SPacketSpawnObject && ((SPacketSpawnObject) event.getPacket()).getType() == 51) {
        // position of the placed crystal
        BlockPos linearPosition = new BlockPos(((SPacketSpawnObject) event.getPacket()).getX(), ((SPacketSpawnObject) event.getPacket()).getY(), ((SPacketSpawnObject) event.getPacket()).getZ());
        // our place position
        if (attemptedPlacements.containsKey(linearPosition.down())) {
            // mark the place time
            startTime = System.currentTimeMillis();
            // since it's been confirmed that the crystal spawned, we can move on to our next process
            if (timing.getValue().equals(Timing.SEQUENTIAL)) {
                // clear our timer
                if (!explodeTimer.passedTime(explodeDelay.getValue().longValue(), Format.MILLISECONDS)) {
                    explodeTimer.setTime(explodeDelay.getValue().longValue(), Format.MILLISECONDS);
                }
            }
            // clear our attempts
            attemptedPlacements.clear();
        }
        if ((timing.getValue().equals(Timing.LINEAR) || timing.getValue().equals(Timing.UNIFORM)) && explode.getValue()) {
            // if the block above the one we can't see through is air, then NCP won't flag us for placing at normal ranges
            boolean wallLinear = RaytraceUtil.isNotVisible(linearPosition, placeRaytrace.getValue().getOffset());
            // if it is a wall placement, use our wall ranges
            double distance = mc.player.getDistance(linearPosition.getX() + 0.5, linearPosition.getY() + 1, linearPosition.getZ() + 0.5);
            if (distance > explodeWall.getValue() && wallLinear) {
                return;
            }
            // make sure it doesn't do too much dmg to us or kill us
            float localDamage = mc.player.capabilities.isCreativeMode ? 0 : ExplosionUtil.getDamageFromExplosion(linearPosition.getX() + 0.5, linearPosition.getY() + 1, linearPosition.getZ() + 0.5, mc.player, ignoreTerrain.getValue(), false);
            if (localDamage > explodeLocal.getValue() || (localDamage + 1 > PlayerUtil.getHealth() && pauseSafety.getValue())) {
                return;
            }
            TreeMap<Float, Integer> linearMap = new TreeMap<>();
            for (EntityPlayer calculatedTarget : mc.world.playerEntities) {
                // make sure the target is not dead or the local player
                if (calculatedTarget.equals(mc.player) || EnemyUtil.isDead(calculatedTarget)) {
                    continue;
                }
                // make sure target's within our specified target range
                float targetDistance = mc.player.getDistance(calculatedTarget);
                if (targetDistance > targetRange.getValue()) {
                    continue;
                }
                // calculate the damage this crystal will do to each target, we can verify if it meets our requirements later
                float targetDamage = ExplosionUtil.getDamageFromExplosion(linearPosition.getX() + 0.5, linearPosition.getY() + 1, linearPosition.getZ() + 0.5, calculatedTarget, ignoreTerrain.getValue(), false);
                // scale based on our damage heuristic
                float damageHeuristic;
                switch(logic.getValue()) {
                    case DAMAGE:
                    default:
                        damageHeuristic = targetDamage;
                        break;
                    case MINIMAX:
                        damageHeuristic = targetDamage - localDamage;
                        break;
                    case UNIFORM:
                        damageHeuristic = (float) (targetDamage - localDamage - distance);
                        break;
                }
                // add the linear crystal to our map
                linearMap.put(damageHeuristic, ((SPacketSpawnObject) event.getPacket()).getEntityID());
            }
            if (!linearMap.isEmpty()) {
                Map.Entry<Float, Integer> idealLinear = linearMap.lastEntry();
                // make sure it meets requirements
                if (idealLinear.getKey() > explodeDamage.getValue()) {
                    if (!rotate.getValue().equals(Rotate.NONE) && (rotateWhen.getValue().equals(When.BREAK) || rotateWhen.getValue().equals(When.BOTH))) {
                        // our last interaction will be the attack on the crystal
                        interactVector = new Vec3d(linearPosition).addVector(0.5, 0.5, 0.5);
                        if (rotate.getValue().equals(Rotate.CLIENT)) {
                            Rotation linearAngles = AngleUtil.calculateAngles(interactVector);
                            // update our players rotation
                            mc.player.rotationYaw = linearAngles.getYaw();
                            mc.player.rotationYawHead = linearAngles.getYaw();
                            mc.player.rotationPitch = linearAngles.getPitch();
                        }
                    }
                    if (!explodeWeakness.getValue().equals(Switch.NONE)) {
                        // strength and weakness effects on the player
                        PotionEffect weaknessEffect = mc.player.getActivePotionEffect(MobEffects.WEAKNESS);
                        PotionEffect strengthEffect = mc.player.getActivePotionEffect(MobEffects.STRENGTH);
                        // verify that we cannot break the crystal due to weakness
                        if (weaknessEffect != null && (strengthEffect == null || strengthEffect.getAmplifier() < weaknessEffect.getAmplifier())) {
                            // find the slots of our tools
                            int swordSlot = getCosmos().getInventoryManager().searchSlot(Items.DIAMOND_SWORD, InventoryRegion.HOTBAR);
                            int pickSlot = getCosmos().getInventoryManager().searchSlot(Items.DIAMOND_SWORD, InventoryRegion.HOTBAR);
                            if (!InventoryUtil.isHolding(Items.DIAMOND_SWORD) || !InventoryUtil.isHolding(Items.DIAMOND_PICKAXE)) {
                                // log the previous slot
                                previousSlot = mc.player.inventory.currentItem;
                                // prefer the sword over a pickaxe
                                if (swordSlot != -1) {
                                    getCosmos().getInventoryManager().switchToSlot(swordSlot, explodeWeakness.getValue());
                                    // sync item
                                    if (placeSwitch.getValue().equals(Switch.PACKET)) {
                                        ((IPlayerControllerMP) mc.playerController).hookSyncCurrentPlayItem();
                                    }
                                } else if (pickSlot != -1) {
                                    getCosmos().getInventoryManager().switchToSlot(pickSlot, explodeWeakness.getValue());
                                    // sync item
                                    if (placeSwitch.getValue().equals(Switch.PACKET)) {
                                        ((IPlayerControllerMP) mc.playerController).hookSyncCurrentPlayItem();
                                    }
                                }
                            }
                        }
                    }
                    // explode the linear crystal
                    explodeCrystal(idealLinear.getValue());
                    swingCrystal(explodeHand.getValue());
                    // add crystal to our list of attempted explosions
                    attemptedExplosions.put(((SPacketSpawnObject) event.getPacket()).getEntityID(), attemptedExplosions.containsKey(((SPacketSpawnObject) event.getPacket()).getEntityID()) ? attemptedExplosions.get(((SPacketSpawnObject) event.getPacket()).getEntityID()) + 1 : 1);
                    // remove the crystal after we break -> i.e. instantly
                    if (sync.getValue().equals(Sync.INSTANT)) {
                        mc.world.removeEntityFromWorld(idealLinear.getValue());
                    }
                    // switch to our previous slot
                    if (explodeWeakness.getValue().equals(Switch.PACKET) && previousSlot != -1) {
                        getCosmos().getInventoryManager().switchToSlot(previousSlot, explodeWeakness.getValue());
                        // reset our previous slot
                        previousSlot = -1;
                    }
                }
            }
        }
    }
    // packet that confirms entity removal
    if (event.getPacket() instanceof SPacketDestroyEntities) {
        for (int entityId : ((SPacketDestroyEntities) event.getPacket()).getEntityIDs()) {
            if (attemptedExplosions.containsKey(entityId)) {
                // time since place
                responseTime = System.currentTimeMillis() - startTime;
                // since it's been confirmed that the crystal exploded, we can move on to our next process
                if (timing.getValue().equals(Timing.SEQUENTIAL) || timing.getValue().equals(Timing.UNIFORM)) {
                    // clear our timer
                    if (!placeTimer.passedTime(placeDelay.getValue().longValue(), Format.MILLISECONDS)) {
                        placeTimer.setTime(placeDelay.getValue().longValue(), Format.MILLISECONDS);
                    }
                }
                // clear our attempts
                attemptedExplosions.clear();
                break;
            }
        }
    }
    // packet for crystal explosions
    if (event.getPacket() instanceof SPacketSoundEffect && ((SPacketSoundEffect) event.getPacket()).getSound().equals(SoundEvents.ENTITY_GENERIC_EXPLODE) && ((SPacketSoundEffect) event.getPacket()).getCategory().equals(SoundCategory.BLOCKS)) {
        // clear our old inhibit entities
        inhibitExplosions.clear();
        // schedule to main mc thread
        mc.addScheduledTask(() -> {
            for (Iterator<Entity> entityList = mc.world.loadedEntityList.iterator(); entityList.hasNext(); ) {
                // next entity in the world
                Entity entity = entityList.next();
                // make sure it's a crystal
                if (!(entity instanceof EntityEnderCrystal) || entity.isDead) {
                    continue;
                }
                // make sure the crystal is in range from the sound to be destroyed
                double soundDistance = entity.getDistance(((SPacketSoundEffect) event.getPacket()).getX(), ((SPacketSoundEffect) event.getPacket()).getY(), ((SPacketSoundEffect) event.getPacket()).getZ());
                if (soundDistance > 6) {
                    continue;
                }
                // going to be exploded anyway, so don't attempt explosion
                if (explodeInhibit.getValue()) {
                    inhibitExplosions.add((EntityEnderCrystal) entity);
                }
                // the world sets the crystal dead one tick after this packet, but we can speed up the placements by setting it dead here
                if (sync.getValue().equals(Sync.SOUND)) {
                    mc.world.removeEntityDangerously(entity);
                }
            }
        });
    }
}
Also used : IPlayerControllerMP(cope.cosmos.asm.mixins.accessor.IPlayerControllerMP) SPacketSoundEffect(net.minecraft.network.play.server.SPacketSoundEffect) CPacketUseEntity(net.minecraft.network.play.client.CPacketUseEntity) ICPacketUseEntity(cope.cosmos.asm.mixins.accessor.ICPacketUseEntity) Entity(net.minecraft.entity.Entity) PotionEffect(net.minecraft.potion.PotionEffect) SPacketSpawnObject(net.minecraft.network.play.server.SPacketSpawnObject) EntityEnderCrystal(net.minecraft.entity.item.EntityEnderCrystal) Rotation(cope.cosmos.util.holder.Rotation) SPacketDestroyEntities(net.minecraft.network.play.server.SPacketDestroyEntities) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with IPlayerControllerMP

use of cope.cosmos.asm.mixins.accessor.IPlayerControllerMP in project cosmos by momentumdevelopment.

the class AuraModule method onUpdate.

@Override
public void onUpdate() {
    if (strictTicks > 0) {
        strictTicks--;
    } else {
        // prefer a player if there is one in range
        boolean playerBias = false;
        // pause if needed
        if (pause.getValue()) {
            // pause if the player is doing something else
            if (PlayerUtil.isEating() && pauseEating.getValue() || PlayerUtil.isMining() && pauseMining.getValue() || PlayerUtil.isMending() && pauseMending.getValue()) {
                return;
            } else // pause if the player is at a critical health
            if (PlayerUtil.getHealth() <= pauseHealth.getValue()) {
                return;
            }
        }
        // map for potential targets
        TreeMap<Double, Entity> attackTargets = new TreeMap<>();
        // find our target
        for (Entity entity : mc.world.loadedEntityList) {
            // make sure the entity is valid to attack
            if (entity == null || entity.equals(mc.player) || EnemyUtil.isDead(entity) || getCosmos().getSocialManager().getSocial(entity.getName()).equals(Relationship.FRIEND)) {
                continue;
            }
            // crystal aura should be delegated to the AutoCrystal
            if (entity instanceof EntityEnderCrystal) {
                continue;
            }
            // should not be attacking items
            if (entity instanceof EntityItem || entity instanceof EntityExpBottle || entity instanceof EntityXPOrb) {
                continue;
            }
            // verify target
            if (entity instanceof EntityPlayer && !targetPlayers.getValue() || EntityUtil.isPassiveMob(entity) && !targetPassives.getValue() || EntityUtil.isNeutralMob(entity) && !targetNeutrals.getValue() || EntityUtil.isHostileMob(entity) && !targetHostiles.getValue()) {
                continue;
            }
            // distance to the entity
            double distance = mc.player.getDistance(entity);
            // vector to trace to
            double traceOffset = 0;
            // scale by bone
            switch(rotateBone.getValue()) {
                case EYES:
                    traceOffset = entity.getEyeHeight();
                    break;
                case BODY:
                    traceOffset = (entity.height / 2);
                    break;
                case FEET:
                    break;
            }
            // check if it's in range
            boolean wallAttack = RaytraceUtil.isNotVisible(entity, traceOffset) && raytrace.getValue();
            if (distance > (wallAttack ? wallsRange.getValue() : range.getValue())) {
                continue;
            }
            // make sure the entity is truly visible, useful for strict anticheats
            Rotation attackAngles = AngleUtil.calculateAngles(entity.getPositionVector());
            if ((Math.abs(mc.player.rotationYaw - attackAngles.getYaw()) % 180) > fov.getValue()) {
                continue;
            }
            // make sure the target has existed in the world for at least a certain number of ticks
            if (entity.ticksExisted < delayTicksExisted.getValue()) {
                continue;
            }
            // there is at least one player that is attackable
            if (!playerBias && entity instanceof EntityPlayer) {
                playerBias = true;
            }
            // calculate priority (minimize)
            double heuristic = 0;
            switch(target.getValue()) {
                case LOWEST_HEALTH:
                    heuristic = EnemyUtil.getHealth(entity);
                    break;
                case LOWEST_ARMOR:
                    heuristic = EnemyUtil.getArmor(entity);
                    break;
                case CLOSEST:
                    heuristic = distance;
                    break;
            }
            // add potential target to our map
            attackTargets.put(heuristic, entity);
        }
        if (!attackTargets.isEmpty()) {
            // find the nearest player
            if (playerBias) {
                // check distance
                AtomicDouble closestPlayer = new AtomicDouble(Double.MAX_VALUE);
                attackTargets.forEach((distance, entity) -> {
                    if (entity instanceof EntityPlayer) {
                        if (distance <= closestPlayer.get()) {
                            // update our closest target
                            auraTarget = entity;
                            closestPlayer.set(distance);
                        }
                    }
                });
            } else {
                // best target is the first entry
                auraTarget = attackTargets.firstEntry().getValue();
            }
        }
        // if we found a target to attack, then attack
        if (auraTarget != null) {
            // vector to trace to
            double traceOffset = 0;
            // scale by bone
            switch(rotateBone.getValue()) {
                case EYES:
                    traceOffset = auraTarget.getEyeHeight();
                    break;
                case BODY:
                    traceOffset = (auraTarget.height / 2);
                    break;
                case FEET:
                    break;
            }
            /*
                 * check our distance to the entity as it could have changed since we last calculated our target
                 * we also check if the Aura target is dead, which will also make the target invalid
                 */
            boolean wallAttack = RaytraceUtil.isNotVisible(auraTarget, traceOffset) && raytrace.getValue();
            if (auraTarget.isDead || mc.player.getDistance(auraTarget) > (wallAttack ? wallsRange.getValue() : range.getValue())) {
                // set our target to null, as it is now invalid
                auraTarget = null;
                return;
            }
            // pause switch to account for eating
            if (PlayerUtil.isEating()) {
                switchTicks = 0;
            }
            // sync item
            ((IPlayerControllerMP) mc.playerController).hookSyncCurrentPlayItem();
            switchTicks++;
            // switch to our weapon
            if (!InventoryUtil.isHolding(weapon.getValue().getItem()) && switchTicks > 10) {
                getCosmos().getInventoryManager().switchToItem(weapon.getValue().getItem(), autoSwitch.getValue());
            }
            // make sure we are holding our weapon
            if (!InventoryUtil.isHolding(weapon.getValue().getItem()) && weaponOnly.getValue() || InventoryUtil.getHighestEnchantLevel() <= 1000 && weaponThirtyTwoK.getValue()) {
                return;
            }
            // teleport to our target, rarely works on an actual server
            if (teleport.getValue()) {
                mc.player.setVelocity(0, 0, 0);
                mc.player.setPosition(auraTarget.posX, auraTarget.posY, auraTarget.posZ);
                mc.player.connection.sendPacket(new CPacketPlayer.Position(auraTarget.posX, auraTarget.posY, auraTarget.posZ, true));
            }
            if (!rotate.getValue().equals(Rotate.NONE)) {
                // vector to rotate to
                attackVector = auraTarget.getPositionVector();
                // scale rotation vector by bone
                switch(rotateBone.getValue()) {
                    case EYES:
                        attackVector.addVector(0, auraTarget.getEyeHeight(), 0);
                        break;
                    case BODY:
                        attackVector.addVector(0, (auraTarget.height / 2), 0);
                        break;
                    case FEET:
                        break;
                }
                // update client rotations
                if (rotate.getValue().equals(Rotate.CLIENT)) {
                    Rotation attackAngles = AngleUtil.calculateAngles(attackVector);
                    // update our players rotation
                    mc.player.rotationYaw = attackAngles.getYaw();
                    mc.player.rotationYawHead = attackAngles.getYaw();
                    mc.player.rotationPitch = attackAngles.getPitch();
                }
            }
            // if holding a shield then automatically block before attacking
            if (weaponBlock.getValue() && InventoryUtil.isHolding(Items.SHIELD)) {
                mc.player.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.RELEASE_USE_ITEM, BlockPos.ORIGIN, mc.player.getHorizontalFacing()));
            }
            // stops sprinting before attacking
            boolean sprint = mc.player.isSprinting();
            if (stopSprint.getValue()) {
                mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.STOP_SPRINTING));
                mc.player.setSprinting(false);
            }
            // stops sneaking before attacking
            boolean sneak = mc.player.isSneaking();
            if (stopSneak.getValue()) {
                mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.STOP_SNEAKING));
                mc.player.setSneaking(false);
            }
            // save old fall states
            boolean onGround = mc.player.onGround;
            float fallDistance = mc.player.fallDistance;
            // whether or not we are cleared to attack
            boolean attackCleared = false;
            // randomized delay
            long randomFactor = 0;
            if (delayRandom.getValue() > 0) {
                Random attackRandom = new Random();
                // scale delay by random based on delay mode
                switch(delayMode.getValue()) {
                    case SWING:
                    case TPS:
                        randomFactor = (long) (attackRandom.nextFloat() * (delayRandom.getValue().longValue() / delayRandom.getMax().longValue()));
                        break;
                    case MILLISECONDS:
                        randomFactor = (long) (attackRandom.nextFloat() * delayRandom.getValue().longValue());
                        break;
                    case TICK:
                        randomFactor = (long) (attackRandom.nextFloat() * (delayRandom.getValue().longValue() / 50F));
                        break;
                }
                // negative or positive?
                if (attackRandom.nextBoolean()) {
                    randomFactor *= -1;
                }
            }
            // scale delay based on delay mode
            switch(delayMode.getValue()) {
                case SWING:
                    attackCleared = mc.player.getCooledAttackStrength(0) >= delayFactor.getValue() + randomFactor;
                    break;
                case TPS:
                    attackCleared = mc.player.getCooledAttackStrength(delayTPS.getValue().equals(TPS.NONE) ? 0 : 20 - getCosmos().getTickManager().getTPS(delayTPS.getValue())) >= delayFactor.getValue() + randomFactor;
                    break;
                case MILLISECONDS:
                    attackCleared = auraTimer.passedTime(delayMilliseconds.getValue().longValue() + randomFactor, Format.MILLISECONDS);
                    break;
                case TICK:
                    attackCleared = auraTimer.passedTime(delayTicks.getValue().longValue() + randomFactor, Format.TICKS);
                    break;
                case NONE:
                    attackCleared = true;
                    break;
            }
            // check hurt resistance time
            if (timing.getValue().equals(Timing.SEQUENTIAL)) {
                if (auraTarget.hurtResistantTime > 11) {
                    return;
                }
            }
            // if we are cleared to attack, then attack
            if (attackCleared) {
                // make sure our switch timer has cleared it's time, attacking right after switching flags Updated NCP
                if (switchTimer.passedTime(delaySwitch.getValue().longValue(), Format.MILLISECONDS)) {
                    // if we passed our critical time, then we can attempt a critical attack
                    if (interact.getValue().equals(Interact.NORMAL) && criticalTimer.passedTime(300, Format.MILLISECONDS)) {
                        // spoof our fall state to simulate a critical attack
                        mc.player.fallDistance = 0.1F;
                        mc.player.onGround = false;
                        // make sure we only try to land a critical attack every 300 milliseconds
                        criticalTimer.resetTime();
                    }
                    // attack the target
                    for (int i = 0; i < iterations.getValue(); i++) {
                        getCosmos().getInteractionManager().attackEntity(auraTarget, packet.getValue(), variation.getValue());
                    }
                    // swing our hand
                    switch(swing.getValue()) {
                        case MAINHAND:
                            mc.player.swingArm(EnumHand.MAIN_HAND);
                            break;
                        case OFFHAND:
                            mc.player.swingArm(EnumHand.OFF_HAND);
                            break;
                        case PACKET:
                            mc.player.connection.sendPacket(new CPacketAnimation(mc.player.getHeldItemMainhand().getItem().equals(Items.END_CRYSTAL) ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND));
                            break;
                        case NONE:
                            break;
                    }
                    // reset fall state
                    if (interact.getValue().equals(Interact.NORMAL)) {
                        mc.player.fallDistance = fallDistance;
                        mc.player.onGround = onGround;
                    }
                }
                // reset sneak state
                if (stopSneak.getValue() && sneak) {
                    mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING));
                    mc.player.setSneaking(true);
                }
                // reset sprint state
                if (stopSprint.getValue() && sprint) {
                    mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SPRINTING));
                    mc.player.setSprinting(true);
                }
                // reset the client ticks
                getCosmos().getTickManager().setClientTicks(1);
                // reset our aura timer
                auraTimer.resetTime();
            }
        }
    }
}
Also used : IPlayerControllerMP(cope.cosmos.asm.mixins.accessor.IPlayerControllerMP) Entity(net.minecraft.entity.Entity) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) EntityEnderCrystal(net.minecraft.entity.item.EntityEnderCrystal) TreeMap(java.util.TreeMap) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) Rotation(cope.cosmos.util.holder.Rotation) EntityExpBottle(net.minecraft.entity.item.EntityExpBottle) Random(java.util.Random) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityItem(net.minecraft.entity.item.EntityItem) EntityXPOrb(net.minecraft.entity.item.EntityXPOrb)

Example 5 with IPlayerControllerMP

use of cope.cosmos.asm.mixins.accessor.IPlayerControllerMP in project cosmos by momentumdevelopment.

the class SpeedMineModule method onUpdate.

@Override
public void onUpdate() {
    // no reason to speedmine in creative mode, blocks break instantly
    if (!mc.player.capabilities.isCreativeMode) {
        if (strictReMine.getValue()) {
            // limit re-mines
            if (mineBreaks > 3) {
                // reset our block info
                minePosition = null;
                mineFacing = null;
                mineDamage = 0;
                mineBreaks = 0;
            }
        }
        if (mode.getValue().equals(Mode.DAMAGE)) {
            // if the damage is greater than our specified damage, set the block to full damage
            if (((IPlayerControllerMP) mc.playerController).getCurrentBlockDamage() > damage.getValue().floatValue()) {
                ((IPlayerControllerMP) mc.playerController).setCurrentBlockDamage(1);
                // destroy the block
                mc.playerController.onPlayerDestroyBlock(minePosition);
            }
        } else if (mode.getValue().equals(Mode.PACKET)) {
            if (minePosition != null) {
                // if the block is broken
                if (mineDamage >= 1) {
                    // break block
                    mc.player.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, minePosition, mineFacing));
                    // save our current slot
                    if (previousSlot != -1) {
                        // switch to our previous slot
                        mc.player.connection.sendPacket(new CPacketHeldItemChange(previousSlot));
                        // reset previous slot
                        previousSlot = -1;
                    }
                }
                // update block damage
                mineDamage += getBlockStrength(mc.world.getBlockState(minePosition), minePosition);
            }
        } else if (mode.getValue().equals(Mode.VANILLA)) {
            // add haste and set the block hit delay to 0
            ((IPlayerControllerMP) mc.playerController).setBlockHitDelay(0);
            mc.player.addPotionEffect(new PotionEffect(MobEffects.HASTE.setPotionName("SpeedMine"), 80950, 1, false, false));
        }
    }
}
Also used : IPlayerControllerMP(cope.cosmos.asm.mixins.accessor.IPlayerControllerMP) CPacketPlayerDigging(net.minecraft.network.play.client.CPacketPlayerDigging) PotionEffect(net.minecraft.potion.PotionEffect) CPacketHeldItemChange(net.minecraft.network.play.client.CPacketHeldItemChange)

Aggregations

IPlayerControllerMP (cope.cosmos.asm.mixins.accessor.IPlayerControllerMP)5 Rotation (cope.cosmos.util.holder.Rotation)4 PotionEffect (net.minecraft.potion.PotionEffect)3 Entity (net.minecraft.entity.Entity)2 EntityEnderCrystal (net.minecraft.entity.item.EntityEnderCrystal)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 AtomicDouble (com.google.common.util.concurrent.AtomicDouble)1 ICPacketUseEntity (cope.cosmos.asm.mixins.accessor.ICPacketUseEntity)1 Random (java.util.Random)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 EntityExpBottle (net.minecraft.entity.item.EntityExpBottle)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityXPOrb (net.minecraft.entity.item.EntityXPOrb)1 CPacketHeldItemChange (net.minecraft.network.play.client.CPacketHeldItemChange)1 CPacketPlayerDigging (net.minecraft.network.play.client.CPacketPlayerDigging)1 CPacketUseEntity (net.minecraft.network.play.client.CPacketUseEntity)1 SPacketDestroyEntities (net.minecraft.network.play.server.SPacketDestroyEntities)1 SPacketSoundEffect (net.minecraft.network.play.server.SPacketSoundEffect)1 SPacketSpawnObject (net.minecraft.network.play.server.SPacketSpawnObject)1