package mpp.venusfr.operationsl.impl.combat; import com.google.common.eventbus.Subscribe; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; import mpp.venusfr.happening.HappeningUpdate; import mpp.venusfr.operationsl.api.Category; import mpp.venusfr.operationsl.api.Module; import mpp.venusfr.operationsl.api.ModuleRegister; import mpp.venusfr.operationsl.settings.Setting; import mpp.venusfr.operationsl.settings.impl.BooleanSetting; import mpp.venusfr.operationsl.settings.impl.SliderSetting; import mpp.venusfr.utilki.player.InventoryUtil; import mpp.venusfr.utilking.NotificationManager; import mpp.venusfr.utilking.NotificationUtil; import mpp.venusfr.utilking.NotificationManager.ImageType; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.client.network.play.ClientPlayNetHandler; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.item.Item; import net.minecraft.item.Items; import net.minecraft.network.play.client.CHeldItemChangePacket; import net.minecraft.network.play.client.CPlayerTryUseItemPacket; import net.minecraft.util.Hand; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.vector.Vector2f; @ModuleRegister(name = "ElytraTarget", type = Category.Combat) public class ElytraTarget extends Module { private long chatMessageInterval; private BooleanSetting save; private long lastChatMessageTime; private long lastFireworkTime; private Set<PlayerEntity> targetedPlayers; private BooleanSetting deadtoggle; private BooleanSetting autofirework; private boolean isTargeting; private long fireworkCooldown; private SliderSetting hptoggle; public Vector2f rotate; private SliderSetting distanse; public ElytraTarget() { super(); this.targetedPlayers = new HashSet<>(); this.isTargeting = false; this.lastFireworkTime = 0L; this.fireworkCooldown = 750L; this.lastChatMessageTime = 0L; this.chatMessageInterval = 5000L; this.rotate = new Vector2f(0.0F, 0.0F); this.save = new BooleanSetting("Безопасность", true); this.autofirework = new BooleanSetting("Авто-Фейерверк", true); this.deadtoggle = new BooleanSetting("Оключать при смерти таргета", true); this.distanse = new SliderSetting("Дистанция", 50.0F, 5.0F, 50.0F, 1.0F); this.hptoggle = new SliderSetting("Хп для отключение", 6.0F, 0.0F, 20.0F, 1.0F); this.hptoggle.setVisible(() -> (Boolean) this.save.get()); this.addSettings(new Setting[]{this.save, this.autofirework, this.deadtoggle, this.distanse, this.hptoggle}); } @Subscribe private void onUpdate(HappeningUpdate event) { ClientPlayerEntity player = Minecraft.getInstance().player; if (player.isElytraFlying()) { if (!this.isTargeting) { this.targetPlayer(); } else { this.updateRotationToPlayer(); this.useFirework(); this.checkChatMessage(); } } else if (this.isTargeting) { this.stopTargeting(); } } private void checkChatMessage() { long currentTime = System.currentTimeMillis(); if (currentTime - this.lastChatMessageTime >= this.chatMessageInterval) { this.lastChatMessageTime = currentTime; if (!this.targetedPlayers.isEmpty()) { for (PlayerEntity target : this.targetedPlayers) { if (target != null && target.getHealth() <= 0.01F) { this.targetedPlayers.clear(); NotificationUtil.NOTIFICATION_MANAGER.add("Таргет был убит! Выключаю модуль", "", 2, ImageType.FIRST_PHOTO); this.onDisable(); return; } } } Minecraft mc = Minecraft.getInstance(); ClientPlayerEntity player = mc.player; float playerHealth = player.getHealth(); if ((Boolean) this.save.get() && playerHealth < (Float) this.hptoggle.get()) { double playerX = player.getPosX(); double playerY = player.getPosY(); double playerZ = player.getPosZ(); double distanceX = playerX - mc.player.getPosX(); double distanceY = playerY - mc.player.getPosY(); double distanceZ = playerZ - mc.player.getPosZ(); double yaw = Math.toDegrees(Math.atan2(distanceZ, distanceX)) - 90.0; double pitch = -Math.toDegrees(Math.atan2(distanceY, Math.sqrt(distanceX * distanceX + distanceZ * distanceZ))); player.rotationYaw = (float) yaw; player.rotationPitch = (float) pitch; this.targetedPlayers.clear(); this.stopTargeting(); this.onDisable(); NotificationUtil.NOTIFICATION_MANAGER.add("Модуль был выключен, из-за " + playerHealth + "ХП", "", 2, ImageType.FIRST_PHOTO); } } } public void onDisable() { super.onDisable(); } private void setRotationToPlayer(PlayerEntity target) { if (target != null) { ClientPlayerEntity player = Minecraft.getInstance().player; double targetX = target.getPosX(); double targetY = target.getPosY(); double targetZ = target.getPosZ(); double playerX = player.getPosX(); double playerY = player.getPosY(); double playerZ = player.getPosZ(); double distanceX = targetX - playerX; double distanceY = targetY - playerY; double distanceZ = targetZ - playerZ; double yaw = Math.toDegrees(Math.atan2(distanceZ, distanceX)) - 90.0; double pitch = -Math.toDegrees(Math.atan2(distanceY, Math.sqrt(distanceX * distanceX + distanceZ * distanceZ))); player.rotationYaw = (float) yaw; player.rotationPitch = (float) pitch; } } public PlayerEntity[] getTargetedPlayers() { return this.targetedPlayers.toArray(new PlayerEntity[0]); } private void targetPlayer() { Minecraft mc = Minecraft.getInstance(); ClientWorld world = mc.world; if (world != null) { ClientPlayerEntity player = mc.player; AxisAlignedBB aabb = new AxisAlignedBB( player.getPosX() - 10.0, player.getPosY() - 5.0, player.getPosZ() - 10.0, player.getPosX() + 10.0, player.getPosY() + 5.0, player.getPosZ() + 10.0 ); List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(player, aabb); for (Entity entity : entities) { if (entity instanceof PlayerEntity && entity.isAlive() && !this.targetedPlayers.contains((PlayerEntity) entity)) { this.targetedPlayers.clear(); this.targetedPlayers.add((PlayerEntity) entity); this.isTargeting = true; this.setRotationToPlayer((PlayerEntity) entity); return; } } } } private void stopTargeting() { this.targetedPlayers.clear(); this.isTargeting = false; } private void useFirework() { long currentTime = System.currentTimeMillis(); if (currentTime - this.lastFireworkTime >= this.fireworkCooldown && (Boolean) this.autofirework.get()) { InventoryUtil inventoryUtil = InventoryUtil.getInstance(); int slotInInventory = inventoryUtil.getSlotInInventoryOrHotbar(Items.FIREWORK_ROCKET, true); int slotInHotbar = inventoryUtil.getSlotInInventoryOrHotbar(Items.FIREWORK_ROCKET, false); if (slotInInventory == -1 && slotInHotbar == -1) { NotificationUtil.NOTIFICATION_MANAGER.add("Феерверки не найдены", "", 2, ImageType.FIRST_PHOTO); return; } ClientPlayerEntity player = Minecraft.getInstance().player; PlayerInventory inventory = player.inventory; int currentSlot = inventory.currentItem; ClientPlayNetHandler connection = player.connection; connection.sendPacket(new CHeldItemChangePacket(slotInInventory)); connection.sendPacket(new CPlayerTryUseItemPacket(Hand.MAIN_HAND)); connection.sendPacket(new CHeldItemChangePacket(currentSlot)); this.lastFireworkTime = currentTime; for (PlayerEntity target : this.targetedPlayers) { double distance = player.getDistance(target); if (distance > (Float) this.distanse.get()) { this.fireworkCooldown = 300L; return; } } this.fireworkCooldown = 200L; } } }