Search in sources :

Example 1 with SPacketSpawnObject

use of net.minecraft.network.play.server.SPacketSpawnObject 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 2 with SPacketSpawnObject

use of net.minecraft.network.play.server.SPacketSpawnObject in project 3arthh4ck by 3arthqu4ke.

the class ListenerSpawnObject method invoke.

@Override
public void invoke(PacketEvent.Receive<SPacketSpawnObject> event) {
    EntityPlayerSP player = mc.player;
    if (module.instant.getValue() && player != null && Managers.SWITCH.getLastSwitch() >= module.coolDown.getValue() && !DamageUtil.isWeaknessed() && module.timer.passed(module.delay.getValue()) && event.getPacket().getType() == 51) {
        SPacketSpawnObject packet = event.getPacket();
        LegConstellation constellation = module.constellation;
        if (constellation != null && // TODO: make it place asnyc?
        !constellation.firstNeedsObby && !constellation.secondNeedsObby && (InventoryUtil.isHolding(Items.END_CRYSTAL) || module.autoSwitch.getValue() != LegAutoSwitch.None)) {
            double x = packet.getX();
            double y = packet.getY();
            double z = packet.getZ();
            BlockPos pos = new BlockPos(x, y - 1, z);
            BlockPos previous = module.targetPos;
            if (!pos.equals(previous)) {
                return;
            }
            BlockPos targetPos = constellation.firstPos.equals(previous) ? constellation.secondPos : constellation.firstPos;
            EntityEnderCrystal entity = new EntityEnderCrystal(mc.world, x, y, z);
            if (!module.rotate.getValue().noRotate(ACRotate.Break) && !RotationUtil.isLegit(entity) || !module.rotate.getValue().noRotate(ACRotate.Place) && !RotationUtil.isLegit(targetPos)) {
                return;
            }
            RayTraceResult result = RotationUtil.rayTraceTo(targetPos, mc.world);
            if (result == null) {
                result = new RayTraceResult(new Vec3d(0.5, 1.0, 0.5), EnumFacing.UP);
            }
            entity.setUniqueId(packet.getUniqueId());
            entity.setEntityId(packet.getEntityID());
            entity.setShowBottom(false);
            int slot = InventoryUtil.findHotbarItem(Items.END_CRYSTAL);
            RayTraceResult finalResult = result;
            Locks.acquire(Locks.PLACE_SWITCH_LOCK, () -> {
                int last = player.inventory.currentItem;
                EnumHand hand = player.getHeldItemMainhand().getItem() == Items.END_CRYSTAL || slot != -2 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND;
                player.connection.sendPacket(new CPacketUseEntity(entity));
                player.connection.sendPacket(new CPacketAnimation(EnumHand.MAIN_HAND));
                InventoryUtil.switchTo(slot);
                player.connection.sendPacket(new CPacketPlayerTryUseItemOnBlock(targetPos, finalResult.sideHit, hand, (float) finalResult.hitVec.x, (float) finalResult.hitVec.y, (float) finalResult.hitVec.z));
                player.connection.sendPacket(new CPacketAnimation(hand));
                if (last != slot && module.autoSwitch.getValue() != LegAutoSwitch.Keep) {
                    InventoryUtil.switchTo(last);
                }
            });
            module.targetPos = targetPos;
            if (module.setDead.getValue()) {
                event.addPostEvent(() -> {
                    if (mc.world != null) {
                        Entity e = mc.world.getEntityByID(packet.getEntityID());
                        if (e != null) {
                            Managers.SET_DEAD.setDead(e);
                        }
                    }
                });
            }
            module.timer.reset(module.delay.getValue());
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) CPacketUseEntity(net.minecraft.network.play.client.CPacketUseEntity) SPacketSpawnObject(net.minecraft.network.play.server.SPacketSpawnObject) EntityEnderCrystal(net.minecraft.entity.item.EntityEnderCrystal) RayTraceResult(net.minecraft.util.math.RayTraceResult) CPacketAnimation(net.minecraft.network.play.client.CPacketAnimation) Vec3d(net.minecraft.util.math.Vec3d) CPacketPlayerTryUseItemOnBlock(net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock) CPacketUseEntity(net.minecraft.network.play.client.CPacketUseEntity) EnumHand(net.minecraft.util.EnumHand) BlockPos(net.minecraft.util.math.BlockPos) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP)

Example 3 with SPacketSpawnObject

use of net.minecraft.network.play.server.SPacketSpawnObject in project 3arthh4ck by 3arthqu4ke.

the class ListenerSpawnObject method invoke.

@Override
public void invoke(PacketEvent.Receive<SPacketSpawnObject> event) {
    if (event.isCancelled() || !module.items.getValue() || event.getPacket().getType() != 2) {
        return;
    }
    SPacketSpawnObject p = event.getPacket();
    Entity e = new EntityItem(mc.world, p.getX(), p.getY(), p.getZ());
    EntityTracker.updateServerPosition(e, p.getX(), p.getY(), p.getZ());
    e.rotationPitch = (p.getPitch() * 360) / 256.0f;
    e.rotationYaw = (p.getYaw() * 360) / 256.0f;
    Entity[] parts = e.getParts();
    if (parts != null) {
        int id = p.getEntityID() - e.getEntityId();
        for (Entity part : parts) {
            part.setEntityId(part.getEntityId() + id);
        }
    }
    e.setEntityId(p.getEntityID());
    e.setUniqueId(p.getUniqueId());
    if (p.getData() > 0) {
        e.setVelocity(p.getSpeedX() / 8000.0, p.getSpeedY() / 8000.0, p.getSpeedZ() / 8000.0);
    }
    event.setCancelled(true);
    mc.addScheduledTask(() -> {
        Managers.SET_DEAD.setDeadCustom(e, Long.MAX_VALUE);
        module.ids.add(p.getEntityID());
    });
}
Also used : Entity(net.minecraft.entity.Entity) SPacketSpawnObject(net.minecraft.network.play.server.SPacketSpawnObject) EntityItem(net.minecraft.entity.item.EntityItem)

Example 4 with SPacketSpawnObject

use of net.minecraft.network.play.server.SPacketSpawnObject in project 3arthh4ck by 3arthqu4ke.

the class ListenerSpawnObject method onEvent.

private void onEvent(PacketEvent.Receive<SPacketSpawnObject> event) {
    if (mc.player == null || mc.world == null || !module.spectator.getValue() && mc.player.isSpectator()) {
        return;
    }
    SPacketSpawnObject packet = event.getPacket();
    double x = packet.getX();
    double y = packet.getY();
    double z = packet.getZ();
    EntityEnderCrystal entity = new EntityEnderCrystal(mc.world, x, y, z);
    if (module.simulatePlace.getValue() != 0) {
        event.addPostEvent(() -> {
            if (mc.world == null) {
                return;
            }
            Entity e = mc.world.getEntityByID(packet.getEntityID());
            if (e instanceof EntityEnderCrystal) {
                module.crystalRender.onSpawn((EntityEnderCrystal) e);
            }
        });
    }
    if (packet.getType() != 51 || !module.instant.getValue() || module.isPingBypass() || !module.breakTimer.passed(module.breakDelay.getValue()) || ANTISURROUND.returnIfPresent(AntiSurround::isActive, false) || LEG_SWITCH.returnIfPresent(LegSwitch::isActive, false)) {
        return;
    }
    BlockPos pos = new BlockPos(x, y, z);
    CrystalTimeStamp stamp = module.placed.get(pos);
    entity.setShowBottom(false);
    entity.setEntityId(packet.getEntityID());
    entity.setUniqueId(packet.getUniqueId());
    if (!module.alwaysCalc.getValue() && stamp != null && stamp.isValid() && (stamp.getDamage() > module.slowBreakDamage.getValue() || stamp.isShield() || module.breakTimer.passed(module.slowBreakDelay.getValue()) || pos.down().equals(module.antiTotemHelper.getTargetPos()))) {
        float damage = checkPos(entity);
        if (damage <= -1000.0f) {
            MutableWrapper<Boolean> a = new MutableWrapper<>(false);
            module.rotation = module.rotationHelper.forBreaking(entity, a);
            // set it once more once we got the real entity
            event.addPostEvent(() -> {
                if (mc.world != null) {
                    Entity e = mc.world.getEntityByID(packet.getEntityID());
                    if (e != null) {
                        module.post.add(module.rotationHelper.post(e, a));
                        module.rotation = module.rotationHelper.forBreaking(e, a);
                        module.setCrystal(e);
                    }
                }
            });
            return;
        }
        if (damage < 0.0f) {
            return;
        }
        if (damage > module.shieldSelfDamage.getValue() && stamp.isShield()) {
            return;
        }
        attack(packet, event, entity, stamp.getDamage() <= module.slowBreakDamage.getValue());
    } else if (module.asyncCalc.getValue() || module.alwaysCalc.getValue()) {
        List<EntityPlayer> players = Managers.ENTITIES.getPlayers();
        if (players == null) {
            return;
        }
        float self = checkPos(entity);
        if (self < 0.0f) {
            // TODO: ROTATIONS HERE?
            return;
        }
        boolean slow = true;
        boolean attack = false;
        for (EntityPlayer player : players) {
            if (player == null || EntityUtil.isDead(player) || player.getDistanceSq(x, y, z) > 144) {
                continue;
            }
            if (Managers.FRIENDS.contains(player)) {
                if (module.antiFriendPop.getValue().shouldCalc(AntiFriendPop.Break)) {
                    if (module.damageHelper.getDamage(x, y, z, player) > EntityUtil.getHealth(player) - 0.5f) {
                        attack = false;
                        break;
                    }
                }
                continue;
            }
            float dmg = module.damageHelper.getDamage(x, y, z, player);
            if ((dmg > self || module.suicide.getValue() && dmg >= module.minDamage.getValue()) && (dmg > module.slowBreakDamage.getValue() || module.shouldDanger() || module.breakTimer.passed(module.slowBreakDelay.getValue()))) {
                slow = slow && dmg <= module.slowBreakDamage.getValue();
                attack = true;
            }
        }
        if (attack) {
            attack(packet, event, entity, (stamp == null || !stamp.isShield()) && slow);
        } else if (stamp != null && stamp.isShield() && self >= 0.0f && self <= module.shieldSelfDamage.getValue()) {
            attack(packet, event, entity, false);
        }
    }
    if (module.spawnThread.getValue()) {
        module.threadHelper.schedulePacket(event);
    }
}
Also used : CPacketUseEntity(net.minecraft.network.play.client.CPacketUseEntity) IEntity(me.earth.earthhack.impl.core.ducks.entity.IEntity) Entity(net.minecraft.entity.Entity) SPacketSpawnObject(net.minecraft.network.play.server.SPacketSpawnObject) EntityEnderCrystal(net.minecraft.entity.item.EntityEnderCrystal) CrystalTimeStamp(me.earth.earthhack.impl.modules.combat.autocrystal.util.CrystalTimeStamp) MutableWrapper(me.earth.earthhack.impl.util.misc.MutableWrapper) AntiSurround(me.earth.earthhack.impl.modules.combat.antisurround.AntiSurround) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) List(java.util.List)

Example 5 with SPacketSpawnObject

use of net.minecraft.network.play.server.SPacketSpawnObject in project 3arthh4ck by 3arthqu4ke.

the class InstantAttackListener method invoke.

@Override
public void invoke(PacketEvent.Receive<SPacketSpawnObject> event) {
    SPacketSpawnObject packet = event.getPacket();
    if (mc.player == null || packet.getType() != 51 || !module.getTimer().passed(module.getBreakDelay()) || Managers.SWITCH.getLastSwitch() < module.getCooldown() || DamageUtil.isWeaknessed()) {
        return;
    }
    EntityEnderCrystal crystal = new EntityEnderCrystal(mc.world, packet.getX(), packet.getY(), packet.getZ());
    try {
        attack(crystal);
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
Also used : SPacketSpawnObject(net.minecraft.network.play.server.SPacketSpawnObject) EntityEnderCrystal(net.minecraft.entity.item.EntityEnderCrystal)

Aggregations

SPacketSpawnObject (net.minecraft.network.play.server.SPacketSpawnObject)8 Entity (net.minecraft.entity.Entity)4 EntityEnderCrystal (net.minecraft.entity.item.EntityEnderCrystal)4 CPacketUseEntity (net.minecraft.network.play.client.CPacketUseEntity)4 BlockPos (net.minecraft.util.math.BlockPos)4 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 CPacketAnimation (net.minecraft.network.play.client.CPacketAnimation)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 ICPacketUseEntity (cope.cosmos.asm.mixins.accessor.ICPacketUseEntity)1 IPlayerControllerMP (cope.cosmos.asm.mixins.accessor.IPlayerControllerMP)1 Rotation (cope.cosmos.util.holder.Rotation)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 IEntity (me.earth.earthhack.impl.core.ducks.entity.IEntity)1 ICPacketUseEntity (me.earth.earthhack.impl.core.ducks.network.ICPacketUseEntity)1 AntiSurround (me.earth.earthhack.impl.modules.combat.antisurround.AntiSurround)1 CrystalTimeStamp (me.earth.earthhack.impl.modules.combat.autocrystal.util.CrystalTimeStamp)1 MutableWrapper (me.earth.earthhack.impl.util.misc.MutableWrapper)1 EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)1 EntityItem (net.minecraft.entity.item.EntityItem)1