Начинающий
- Статус
- Оффлайн
- Регистрация
- 21 Дек 2024
- Сообщения
- 50
- Реакции
- 0
короче такая штука вроде иногда автототем сейвит а на элитрах вообще очень плохо все код снизу
public class AutoTotemTHModule extends Module {
private final FloatSetting health = (FloatSetting) new FloatSetting("Здоровье").range(1.0f, 20.0f, 0.5f).setValue(4.0f);
private final FloatSetting healthelytra = (FloatSetting) new FloatSetting("Здоровье на элитрах").range(1.0f, 20.0f, 0.5f).setValue(7.5f);
private final FloatSetting healthbronya = (FloatSetting) new FloatSetting("Без полной брони").range(1.0f, 20.0f, 0.5f).setValue(7.5f);
private final MultiSelectSetting mode = new MultiSelectSetting("Проверки на").setValue("Золотые сердца", "Кристаллы", "Падение", "Якорь");
private final BooleanSetting swapBack = new BooleanSetting("Возвращать предмет").setValue(true);
private final BooleanSetting noBallSwitch = new BooleanSetting("Не сменять шар").setValue(false);
private final BooleanSetting saveEnchanted = new BooleanSetting("Сохранять зачарованный").setValue(true);
private final SelectSetting rcGap = new SelectSetting("Правый клик яблоко");
private final StopWatch stopWatch = new StopWatch();
private ItemStack currentStack = ItemStack.EMPTY;
private int nonEnchantedTotems;
private boolean totemIsUsed;
private int totemCount;
private int oldItem = -1;
private final StopWatch cacheTimer = new StopWatch();
private int cachedTotemSlot = -1;
public AutoTotemTHModule() {
super("AutoTotemTH", "Продвинутый автототем с RCGapple и доп. проверками", "Advanced totem with RCGapple and extras", ModuleCategory.Combat);
rcGap.setValue("Выкл", "Всегда", "Только безопасно");
registerComponent(mode, health, healthelytra, healthbronya, swapBack, noBallSwitch, saveEnchanted, rcGap);
}
public boolean isRcGapEnabled() {
return !"Выкл".equals(rcGap.getValue());
}
@EventHandler
public void onSpawnEntity(EntitySpawnEvent event) {
Entity entity = event.getEntity();
if (entity instanceof EnderCrystalEntity && this.swapBack.getValue()) {
if (entity.getDistance(mc.player) <= 6.0F) {
this.swapToTotem();
}
}
}
@EventHandler
public void onUpdate(TickEvent event) {
if (ManualBindMode.isEnabled() && !ManualBindMode.shouldWorkAutomatically(getKey())) {
return;
}
handleRightClickGapple();
// Критический фолбек: при 1 сердечке (<=2.0) или половине (<=1.0) всегда ставим тотем, даже если сейчас едим
float hp = mc.player != null ? mc.player.getHealth() : 20.0F;
if (hp <= 2.0F) {
int slot = this.getSlotInInventory();
if (slot != -1 && !this.isTotemInHands()) {
// принудительно остановим текущее использование, чтобы не мешало свопу
mc.gameSettings.keyBindUseItem.setPressed(false);
if (mc.player.isHandActive()) {
mc.playerController.onStoppedUsingItem(mc.player);
}
Client.instance.moduleCoordinator.notifySwitching(true, getName());
// безопасный перенос предмета в оффхенд через прямой move в слот 45
InventoryUtil.moveItem(slot, 45, true);
Client.instance.moduleCoordinator.notifySwitching(false, getName());
}
// при критическом HP не продолжаем обычную логику, чтобы избежать гонок
return;
}
// Высокоприоритетный контекст: полёт на элитрах / падение / близкие кристаллы/якорь — игнорировать defer и прервать поедание
boolean highPriority = (mc.player != null && (mc.player.isElytraFlying() || this.checkFall() || this.checkAnchor() || this.checkCrystal()));
if (Client.instance.moduleCoordinator.shouldDeferAutoTotem() && !highPriority) {
return;
}
this.totemCount = this.countTotems(true);
this.nonEnchantedTotems = (int) IntStream.range(0, 36)
.mapToObj(i -> mc.player.inventory.getStackInSlot(i))
.filter(s -> s.getItem() == Items.TOTEM_OF_UNDYING && !s.isEnchanted())
.count();
int slot = this.getSlotInInventory();
boolean handNotNull = !(mc.player.getHeldItemOffhand().getItem() instanceof AirItem);
if (this.shouldToSwapTotem()) {
if (slot != -1 && !this.isTotemInHands()) {
// В highPriority прерываем поедание и обходим блокировку координатора
if (highPriority) {
mc.gameSettings.keyBindUseItem.setPressed(false);
if (mc.player.isHandActive()) mc.playerController.onStoppedUsingItem(mc.player);
Client.instance.moduleCoordinator.notifyGappleEating(false, getName());
Client.instance.moduleCoordinator.notifySwitching(true, getName());
InventoryUtil.moveItem(slot, 45, true);
Client.instance.moduleCoordinator.notifySwitching(false, getName());
if (handNotNull && this.oldItem == -1) this.oldItem = slot;
} else if (Client.instance.moduleCoordinator.beginAction(getName(), ModuleCoordinator.ActionType.EQUIP_TOTEM)) {
Client.instance.moduleCoordinator.notifySwitching(true, getName());
InventoryUtil.moveItem(slot, 45, true);
Client.instance.moduleCoordinator.notifySwitching(false, getName());
Client.instance.moduleCoordinator.endAction(getName(), ModuleCoordinator.ActionType.EQUIP_TOTEM);
if (handNotNull && this.oldItem == -1) {
this.oldItem = slot;
}
}
}
} else if (this.oldItem != -1 && this.swapBack.getValue()) {
InventoryUtil.moveItem(this.oldItem, 45, true);
this.oldItem = -1;
}
this.prepareTotemHotbar();
}
@EventHandler
public void onPacket(PacketEvent.Receive event) {
IPacket packet = event.getPacket();
if (packet instanceof SEntityStatusPacket) {
SEntityStatusPacket statusPacket = (SEntityStatusPacket) packet;
if (statusPacket.getOpCode() == 35) {
Entity entity = statusPacket.getEntity(mc.world);
if (entity == mc.player) {
this.totemIsUsed = true;
}
}
}
}
private void handleRightClickGapple() {
String modeVal = rcGap.getValue();
if ("Выкл".equals(modeVal)) return;
if (mc.player == null || mc.world == null) return;
Item main = mc.player.getHeldItemMainhand().getItem();
boolean isSword = main instanceof SwordItem;
boolean usingKey = mc.gameSettings.keyBindUseItem.isKeyDown();
boolean offhandIsShield = mc.player.getHeldItemOffhand().getItem() instanceof ShieldItem;
if (!isSword || !usingKey || offhandIsShield) return;
float currentHealth = mc.player.getHealth();
if (this.mode.isSelected("Золотые сердца")) {
currentHealth += mc.player.isPotionActive(Effects.ABSORPTION) ? mc.player.getAbsorptionAmount() : 0.0F;
}
if ("Только безопасно".equals(modeVal)) {
float threshold = this.health.getValue();
if (currentHealth <= threshold) return;
}
int slot = getPreferredAppleSlot();
if (slot == -1) return;
Item off = mc.player.getHeldItemOffhand().getItem();
if (off == Items.GOLDEN_APPLE || off == Items.ENCHANTED_GOLDEN_APPLE) return;
Client.instance.moduleCoordinator.notifySwitching(true, getName());
this.swapHand(slot, Hand.OFF_HAND, false);
Client.instance.moduleCoordinator.notifySwitching(false, getName());
}
private int getPreferredAppleSlot() {
int e = InventoryUtil.getItemSlot(Items.ENCHANTED_GOLDEN_APPLE);
if (e != -1) return e;
return InventoryUtil.getItemSlot(Items.GOLDEN_APPLE);
}
private void swapHand(int slotId, Hand hand, boolean packet) {
if (slotId != -1) {
int button = hand.equals(Hand.MAIN_HAND) ? mc.player.inventory.currentItem : 40;
this.clickSlotId(slotId, button, ClickType.SWAP, packet);
}
}
private void clickSlotId(int slotId, int buttonId, ClickType clickType, boolean packet) {
this.clickSlotId(mc.player.openContainer.windowId, slotId, buttonId, clickType, packet);
}
private void clickSlotId(int windowId, int slotId, int buttonId, ClickType clickType, boolean packet) {
if (packet) {
mc.player.connection.sendPacket(new net.minecraft.network.play.client.CClickWindowPacket(windowId, slotId, buttonId, clickType, ItemStack.EMPTY, mc.player.openContainer.getNextTransactionID(mc.player.inventory)));
} else {
mc.playerController.windowClick(windowId, slotId, buttonId, clickType, mc.player);
}
}
private void swapToTotem() {
int totemSlot = this.getSlotInInventory();
if (totemSlot == -1) return;
this.stopWatch.reset();
Item offhandItem = mc.player.getHeldItemOffhand().getItem();
if (offhandItem != Items.TOTEM_OF_UNDYING) {
this.swapHand(totemSlot, Hand.OFF_HAND, false);
}
}
private int countTotems(boolean includeEnchanted) {
return (int) IntStream.range(0, mc.player.inventory.getSizeInventory())
.mapToObj(i -> mc.player.inventory.getStackInSlot(i))
.filter(s -> s.getItem() == Items.TOTEM_OF_UNDYING && (includeEnchanted || !s.isEnchanted()))
.count();
}
private boolean isTotemInHands() {
for (Hand hand : Hand.values()) {
ItemStack heldItem = mc.player.getHeldItem(hand);
if (heldItem.getItem() == Items.TOTEM_OF_UNDYING && !this.isSaveEnchanted(heldItem)) {
return true;
}
}
return false;
}
private boolean isSaveEnchanted(ItemStack itemStack) {
return this.saveEnchanted.getValue() && itemStack.isEnchanted() && this.nonEnchantedTotems > 0;
}
private boolean shouldToSwapTotem() {
this.currentStack = mc.player.getItemStackFromSlot(EquipmentSlotType.CHEST);
float absorptionAmount = mc.player.isPotionActive(Effects.ABSORPTION) ? mc.player.getAbsorptionAmount() : 0.0F;
float currentHealth = mc.player.getHealth();
if (this.mode.isSelected("Золотые сердца")) {
currentHealth += absorptionAmount;
}
boolean hasFullArmor = true;
for (ItemStack armor : mc.player.inventory.armorInventory) {
if (armor.isEmpty()) {
hasFullArmor = false;
break;
}
}
float healthThreshold = hasFullArmor ? this.health.getValue() : this.healthbronya.getValue();
return !this.isOffhandItemBall() && this.isInDangerousSituation() ||
currentHealth <= (this.currentStack.getItem() == Items.ELYTRA ? this.healthelytra.getValue() : healthThreshold) ||
this.checkFall();
}
private boolean isInDangerousSituation() {
return this.checkCrystal() || this.checkAnchor() || this.checkFall();
}
private boolean checkAnchor() {
if (!this.mode.isSelected("Якорь")) {
return false;
}
BlockPos anchor = this.getBlock(6.0F, Blocks.RESPAWN_ANCHOR);
return anchor != null;
}
private boolean checkFall() {
if (!this.mode.isSelected("Падение")) {
return false;
}
if (mc.player.isInWater() || mc.player.isElytraFlying()) {
return false;
}
float fallDistance = mc.player.fallDistance;
float fallDamage = this.calculateFallDamage(fallDistance);
float currentHealth = mc.player.getHealth();
return fallDamage >= currentHealth / 1.92F;
}
private float calculateFallDamage(float fallDistance) {
if (fallDistance <= 3.0F) {
return 0.0F;
}
float fallDamage = (fallDistance - 3.0F) / 2.0F;
float armorReduction = 0.0F;
for (ItemStack armor : mc.player.inventory.armorInventory) {
if (armor.getItem() instanceof ArmorItem) {
armorReduction += ((ArmorItem) armor.getItem()).getDamageReductionAmount();
}
}
ItemStack boots = mc.player.inventory.armorInventory.get(0);
if (boots.getItem() instanceof ArmorItem) {
int featherFallingLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.FEATHER_FALLING, boots);
if (featherFallingLevel > 0) {
float reductionFactor = 1.0F - (float) Math.min(featherFallingLevel, 4) * 0.171F;
fallDamage *= reductionFactor;
}
}
if (this.hasProtectionAura()) {
fallDamage *= 0.2F;
}
float absorption = mc.player.isPotionActive(Effects.ABSORPTION) ? mc.player.getAbsorptionAmount() : 0.0F;
fallDamage = Math.max(0.0F, fallDamage - absorption);
return Math.min(fallDamage, mc.player.getMaxHealth());
}
private boolean hasProtectionAura() {
for (int i = 0; i < mc.player.inventory.getSizeInventory(); i++) {
ItemStack stack = mc.player.inventory.getStackInSlot(i);
if (stack.hasDisplayName() && "Аура Защиты От Падения".equals(stack.getDisplayName().getString())) {
return true;
}
}
return false;
}
private boolean checkCrystal() {
if (!this.mode.isSelected("Кристаллы")) {
return false;
}
for (Entity entity : mc.world.getAllEntities()) {
if (entity instanceof EnderCrystalEntity) {
if (mc.player.getDistance(entity) <= 6.0F) {
return true;
}
}
}
return false;
}
private boolean isOffhandItemBall() {
boolean isFallingConditionMet = false;
if (this.mode.isSelected("Падение")) {
if (mc.player.fallDistance > 5.0F) {
isFallingConditionMet = true;
}
}
if (!isFallingConditionMet && this.noBallSwitch.getValue()) {
if (mc.player.getHeldItemOffhand().getItem() == Items.PLAYER_HEAD) {
return true;
}
}
return false;
}
private BlockPos getBlock(float distance, Block block) {
return this.getSphere(this.getPlayerPosLocal(), distance, 6, false, true, 0).stream()
.filter(position -> mc.world.getBlockState(position).getBlock() == block)
.min(Comparator.comparing(blockPos -> this.getDistanceOfEntityToBlock(mc.player, blockPos)))
.orElse(null);
}
private List<BlockPos> getSphere(BlockPos center, float radius, int height, boolean hollow, boolean fromBottom, int yOffset) {
List<BlockPos> positions = new ArrayList<>();
int centerX = center.getX();
int centerY = center.getY();
int centerZ = center.getZ();
for (int x = centerX - (int) radius; (float) x <= (float) centerX + radius; ++x) {
for (int z = centerZ - (int) radius; (float) z <= (float) centerZ + radius; ++z) {
int yStart = fromBottom ? centerY - (int) radius : centerY;
int yEnd = fromBottom ? centerY + (int) radius : centerY + height;
for (int y = yStart; y < yEnd; ++y) {
if (isPositionWithinSphere(centerX, centerY, centerZ, x, y, z, radius, hollow)) {
positions.add(new BlockPos(x, y + yOffset, z));
}
}
}
}
return positions;
}
private BlockPos getPlayerPosLocal() {
if (mc.player == null) {
return BlockPos.ZERO;
}
double x = Math.floor(mc.player.getPosX());
double y = Math.floor(mc.player.getPosY());
double z = Math.floor(mc.player.getPosZ());
return new BlockPos((int)x, (int)y, (int)z);
}
private double getDistanceOfEntityToBlock(Entity entity, BlockPos blockPos) {
return this.getDistance(entity.getPosX(), entity.getPosY(), entity.getPosZ(),
(double) blockPos.getX(), (double) blockPos.getY(), (double) blockPos.getZ());
}
private double getDistance(double n, double n2, double n3, double n4, double n5, double n6) {
double n7 = n - n4;
double n8 = n2 - n5;
double n9 = n3 - n6;
return (double) MathHelper.sqrt(n7 * n7 + n8 * n8 + n9 * n9);
}
private static boolean isPositionWithinSphere(int centerX, int centerY, int centerZ, int x, int y, int z, float radius, boolean hollow) {
double distanceSq = Math.pow((double) (centerX - x), 2.0D) + Math.pow((double) (centerZ - z), 2.0D) + Math.pow((double) (centerY - y), 2.0D);
return distanceSq < Math.pow((double) radius, 2.0D) && (!hollow || distanceSq >= Math.pow((double) (radius - 1.0F), 2.0D));
}
private int getSlotInInventory() {
if (!cacheTimer.finished(75) && cachedTotemSlot != -1) {
return cachedTotemSlot;
}
for (int i = 0; i < 36; ++i) {
ItemStack itemStack = mc.player.inventory.getStackInSlot(i);
if (itemStack.getItem() == Items.TOTEM_OF_UNDYING && !this.isSaveEnchanted(itemStack)) {
cachedTotemSlot = this.adjustSlotNumber(i);
cacheTimer.reset();
return cachedTotemSlot;
}
}
cachedTotemSlot = -1;
cacheTimer.reset();
return -1;
}
private void prepareTotemHotbar() {
if (mc.player == null) return;
if (InventoryUtil.doesHotbarHaveItem(Items.TOTEM_OF_UNDYING)) return;
int slotInInv = this.getSlotInInventory();
if (slotInInv == -1) return;
int targetHotbar = -1;
for (int i = 0; i < 9; i++) {
if (mc.player.inventory.getStackInSlot(i).isEmpty()) {
targetHotbar = i;
break;
}
}
if (targetHotbar == -1) {
targetHotbar = mc.player.inventory.currentItem;
}
Client.instance.moduleCoordinator.notifySwitching(true, getName());
InventoryUtil.moveItem(slotInInv, targetHotbar);
Client.instance.moduleCoordinator.notifySwitching(false, getName());
}
private int adjustSlotNumber(int slot) {
return slot < 9 ? slot + 36 : slot;
}
@override
public void disable() {
this.oldItem = -1;
super.disable();
}
}
и еще когда ем тож не свапает
public class AutoTotemTHModule extends Module {
private final FloatSetting health = (FloatSetting) new FloatSetting("Здоровье").range(1.0f, 20.0f, 0.5f).setValue(4.0f);
private final FloatSetting healthelytra = (FloatSetting) new FloatSetting("Здоровье на элитрах").range(1.0f, 20.0f, 0.5f).setValue(7.5f);
private final FloatSetting healthbronya = (FloatSetting) new FloatSetting("Без полной брони").range(1.0f, 20.0f, 0.5f).setValue(7.5f);
private final MultiSelectSetting mode = new MultiSelectSetting("Проверки на").setValue("Золотые сердца", "Кристаллы", "Падение", "Якорь");
private final BooleanSetting swapBack = new BooleanSetting("Возвращать предмет").setValue(true);
private final BooleanSetting noBallSwitch = new BooleanSetting("Не сменять шар").setValue(false);
private final BooleanSetting saveEnchanted = new BooleanSetting("Сохранять зачарованный").setValue(true);
private final SelectSetting rcGap = new SelectSetting("Правый клик яблоко");
private final StopWatch stopWatch = new StopWatch();
private ItemStack currentStack = ItemStack.EMPTY;
private int nonEnchantedTotems;
private boolean totemIsUsed;
private int totemCount;
private int oldItem = -1;
private final StopWatch cacheTimer = new StopWatch();
private int cachedTotemSlot = -1;
public AutoTotemTHModule() {
super("AutoTotemTH", "Продвинутый автототем с RCGapple и доп. проверками", "Advanced totem with RCGapple and extras", ModuleCategory.Combat);
rcGap.setValue("Выкл", "Всегда", "Только безопасно");
registerComponent(mode, health, healthelytra, healthbronya, swapBack, noBallSwitch, saveEnchanted, rcGap);
}
public boolean isRcGapEnabled() {
return !"Выкл".equals(rcGap.getValue());
}
@EventHandler
public void onSpawnEntity(EntitySpawnEvent event) {
Entity entity = event.getEntity();
if (entity instanceof EnderCrystalEntity && this.swapBack.getValue()) {
if (entity.getDistance(mc.player) <= 6.0F) {
this.swapToTotem();
}
}
}
@EventHandler
public void onUpdate(TickEvent event) {
if (ManualBindMode.isEnabled() && !ManualBindMode.shouldWorkAutomatically(getKey())) {
return;
}
handleRightClickGapple();
// Критический фолбек: при 1 сердечке (<=2.0) или половине (<=1.0) всегда ставим тотем, даже если сейчас едим
float hp = mc.player != null ? mc.player.getHealth() : 20.0F;
if (hp <= 2.0F) {
int slot = this.getSlotInInventory();
if (slot != -1 && !this.isTotemInHands()) {
// принудительно остановим текущее использование, чтобы не мешало свопу
mc.gameSettings.keyBindUseItem.setPressed(false);
if (mc.player.isHandActive()) {
mc.playerController.onStoppedUsingItem(mc.player);
}
Client.instance.moduleCoordinator.notifySwitching(true, getName());
// безопасный перенос предмета в оффхенд через прямой move в слот 45
InventoryUtil.moveItem(slot, 45, true);
Client.instance.moduleCoordinator.notifySwitching(false, getName());
}
// при критическом HP не продолжаем обычную логику, чтобы избежать гонок
return;
}
// Высокоприоритетный контекст: полёт на элитрах / падение / близкие кристаллы/якорь — игнорировать defer и прервать поедание
boolean highPriority = (mc.player != null && (mc.player.isElytraFlying() || this.checkFall() || this.checkAnchor() || this.checkCrystal()));
if (Client.instance.moduleCoordinator.shouldDeferAutoTotem() && !highPriority) {
return;
}
this.totemCount = this.countTotems(true);
this.nonEnchantedTotems = (int) IntStream.range(0, 36)
.mapToObj(i -> mc.player.inventory.getStackInSlot(i))
.filter(s -> s.getItem() == Items.TOTEM_OF_UNDYING && !s.isEnchanted())
.count();
int slot = this.getSlotInInventory();
boolean handNotNull = !(mc.player.getHeldItemOffhand().getItem() instanceof AirItem);
if (this.shouldToSwapTotem()) {
if (slot != -1 && !this.isTotemInHands()) {
// В highPriority прерываем поедание и обходим блокировку координатора
if (highPriority) {
mc.gameSettings.keyBindUseItem.setPressed(false);
if (mc.player.isHandActive()) mc.playerController.onStoppedUsingItem(mc.player);
Client.instance.moduleCoordinator.notifyGappleEating(false, getName());
Client.instance.moduleCoordinator.notifySwitching(true, getName());
InventoryUtil.moveItem(slot, 45, true);
Client.instance.moduleCoordinator.notifySwitching(false, getName());
if (handNotNull && this.oldItem == -1) this.oldItem = slot;
} else if (Client.instance.moduleCoordinator.beginAction(getName(), ModuleCoordinator.ActionType.EQUIP_TOTEM)) {
Client.instance.moduleCoordinator.notifySwitching(true, getName());
InventoryUtil.moveItem(slot, 45, true);
Client.instance.moduleCoordinator.notifySwitching(false, getName());
Client.instance.moduleCoordinator.endAction(getName(), ModuleCoordinator.ActionType.EQUIP_TOTEM);
if (handNotNull && this.oldItem == -1) {
this.oldItem = slot;
}
}
}
} else if (this.oldItem != -1 && this.swapBack.getValue()) {
InventoryUtil.moveItem(this.oldItem, 45, true);
this.oldItem = -1;
}
this.prepareTotemHotbar();
}
@EventHandler
public void onPacket(PacketEvent.Receive event) {
IPacket packet = event.getPacket();
if (packet instanceof SEntityStatusPacket) {
SEntityStatusPacket statusPacket = (SEntityStatusPacket) packet;
if (statusPacket.getOpCode() == 35) {
Entity entity = statusPacket.getEntity(mc.world);
if (entity == mc.player) {
this.totemIsUsed = true;
}
}
}
}
private void handleRightClickGapple() {
String modeVal = rcGap.getValue();
if ("Выкл".equals(modeVal)) return;
if (mc.player == null || mc.world == null) return;
Item main = mc.player.getHeldItemMainhand().getItem();
boolean isSword = main instanceof SwordItem;
boolean usingKey = mc.gameSettings.keyBindUseItem.isKeyDown();
boolean offhandIsShield = mc.player.getHeldItemOffhand().getItem() instanceof ShieldItem;
if (!isSword || !usingKey || offhandIsShield) return;
float currentHealth = mc.player.getHealth();
if (this.mode.isSelected("Золотые сердца")) {
currentHealth += mc.player.isPotionActive(Effects.ABSORPTION) ? mc.player.getAbsorptionAmount() : 0.0F;
}
if ("Только безопасно".equals(modeVal)) {
float threshold = this.health.getValue();
if (currentHealth <= threshold) return;
}
int slot = getPreferredAppleSlot();
if (slot == -1) return;
Item off = mc.player.getHeldItemOffhand().getItem();
if (off == Items.GOLDEN_APPLE || off == Items.ENCHANTED_GOLDEN_APPLE) return;
Client.instance.moduleCoordinator.notifySwitching(true, getName());
this.swapHand(slot, Hand.OFF_HAND, false);
Client.instance.moduleCoordinator.notifySwitching(false, getName());
}
private int getPreferredAppleSlot() {
int e = InventoryUtil.getItemSlot(Items.ENCHANTED_GOLDEN_APPLE);
if (e != -1) return e;
return InventoryUtil.getItemSlot(Items.GOLDEN_APPLE);
}
private void swapHand(int slotId, Hand hand, boolean packet) {
if (slotId != -1) {
int button = hand.equals(Hand.MAIN_HAND) ? mc.player.inventory.currentItem : 40;
this.clickSlotId(slotId, button, ClickType.SWAP, packet);
}
}
private void clickSlotId(int slotId, int buttonId, ClickType clickType, boolean packet) {
this.clickSlotId(mc.player.openContainer.windowId, slotId, buttonId, clickType, packet);
}
private void clickSlotId(int windowId, int slotId, int buttonId, ClickType clickType, boolean packet) {
if (packet) {
mc.player.connection.sendPacket(new net.minecraft.network.play.client.CClickWindowPacket(windowId, slotId, buttonId, clickType, ItemStack.EMPTY, mc.player.openContainer.getNextTransactionID(mc.player.inventory)));
} else {
mc.playerController.windowClick(windowId, slotId, buttonId, clickType, mc.player);
}
}
private void swapToTotem() {
int totemSlot = this.getSlotInInventory();
if (totemSlot == -1) return;
this.stopWatch.reset();
Item offhandItem = mc.player.getHeldItemOffhand().getItem();
if (offhandItem != Items.TOTEM_OF_UNDYING) {
this.swapHand(totemSlot, Hand.OFF_HAND, false);
}
}
private int countTotems(boolean includeEnchanted) {
return (int) IntStream.range(0, mc.player.inventory.getSizeInventory())
.mapToObj(i -> mc.player.inventory.getStackInSlot(i))
.filter(s -> s.getItem() == Items.TOTEM_OF_UNDYING && (includeEnchanted || !s.isEnchanted()))
.count();
}
private boolean isTotemInHands() {
for (Hand hand : Hand.values()) {
ItemStack heldItem = mc.player.getHeldItem(hand);
if (heldItem.getItem() == Items.TOTEM_OF_UNDYING && !this.isSaveEnchanted(heldItem)) {
return true;
}
}
return false;
}
private boolean isSaveEnchanted(ItemStack itemStack) {
return this.saveEnchanted.getValue() && itemStack.isEnchanted() && this.nonEnchantedTotems > 0;
}
private boolean shouldToSwapTotem() {
this.currentStack = mc.player.getItemStackFromSlot(EquipmentSlotType.CHEST);
float absorptionAmount = mc.player.isPotionActive(Effects.ABSORPTION) ? mc.player.getAbsorptionAmount() : 0.0F;
float currentHealth = mc.player.getHealth();
if (this.mode.isSelected("Золотые сердца")) {
currentHealth += absorptionAmount;
}
boolean hasFullArmor = true;
for (ItemStack armor : mc.player.inventory.armorInventory) {
if (armor.isEmpty()) {
hasFullArmor = false;
break;
}
}
float healthThreshold = hasFullArmor ? this.health.getValue() : this.healthbronya.getValue();
return !this.isOffhandItemBall() && this.isInDangerousSituation() ||
currentHealth <= (this.currentStack.getItem() == Items.ELYTRA ? this.healthelytra.getValue() : healthThreshold) ||
this.checkFall();
}
private boolean isInDangerousSituation() {
return this.checkCrystal() || this.checkAnchor() || this.checkFall();
}
private boolean checkAnchor() {
if (!this.mode.isSelected("Якорь")) {
return false;
}
BlockPos anchor = this.getBlock(6.0F, Blocks.RESPAWN_ANCHOR);
return anchor != null;
}
private boolean checkFall() {
if (!this.mode.isSelected("Падение")) {
return false;
}
if (mc.player.isInWater() || mc.player.isElytraFlying()) {
return false;
}
float fallDistance = mc.player.fallDistance;
float fallDamage = this.calculateFallDamage(fallDistance);
float currentHealth = mc.player.getHealth();
return fallDamage >= currentHealth / 1.92F;
}
private float calculateFallDamage(float fallDistance) {
if (fallDistance <= 3.0F) {
return 0.0F;
}
float fallDamage = (fallDistance - 3.0F) / 2.0F;
float armorReduction = 0.0F;
for (ItemStack armor : mc.player.inventory.armorInventory) {
if (armor.getItem() instanceof ArmorItem) {
armorReduction += ((ArmorItem) armor.getItem()).getDamageReductionAmount();
}
}
ItemStack boots = mc.player.inventory.armorInventory.get(0);
if (boots.getItem() instanceof ArmorItem) {
int featherFallingLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.FEATHER_FALLING, boots);
if (featherFallingLevel > 0) {
float reductionFactor = 1.0F - (float) Math.min(featherFallingLevel, 4) * 0.171F;
fallDamage *= reductionFactor;
}
}
if (this.hasProtectionAura()) {
fallDamage *= 0.2F;
}
float absorption = mc.player.isPotionActive(Effects.ABSORPTION) ? mc.player.getAbsorptionAmount() : 0.0F;
fallDamage = Math.max(0.0F, fallDamage - absorption);
return Math.min(fallDamage, mc.player.getMaxHealth());
}
private boolean hasProtectionAura() {
for (int i = 0; i < mc.player.inventory.getSizeInventory(); i++) {
ItemStack stack = mc.player.inventory.getStackInSlot(i);
if (stack.hasDisplayName() && "Аура Защиты От Падения".equals(stack.getDisplayName().getString())) {
return true;
}
}
return false;
}
private boolean checkCrystal() {
if (!this.mode.isSelected("Кристаллы")) {
return false;
}
for (Entity entity : mc.world.getAllEntities()) {
if (entity instanceof EnderCrystalEntity) {
if (mc.player.getDistance(entity) <= 6.0F) {
return true;
}
}
}
return false;
}
private boolean isOffhandItemBall() {
boolean isFallingConditionMet = false;
if (this.mode.isSelected("Падение")) {
if (mc.player.fallDistance > 5.0F) {
isFallingConditionMet = true;
}
}
if (!isFallingConditionMet && this.noBallSwitch.getValue()) {
if (mc.player.getHeldItemOffhand().getItem() == Items.PLAYER_HEAD) {
return true;
}
}
return false;
}
private BlockPos getBlock(float distance, Block block) {
return this.getSphere(this.getPlayerPosLocal(), distance, 6, false, true, 0).stream()
.filter(position -> mc.world.getBlockState(position).getBlock() == block)
.min(Comparator.comparing(blockPos -> this.getDistanceOfEntityToBlock(mc.player, blockPos)))
.orElse(null);
}
private List<BlockPos> getSphere(BlockPos center, float radius, int height, boolean hollow, boolean fromBottom, int yOffset) {
List<BlockPos> positions = new ArrayList<>();
int centerX = center.getX();
int centerY = center.getY();
int centerZ = center.getZ();
for (int x = centerX - (int) radius; (float) x <= (float) centerX + radius; ++x) {
for (int z = centerZ - (int) radius; (float) z <= (float) centerZ + radius; ++z) {
int yStart = fromBottom ? centerY - (int) radius : centerY;
int yEnd = fromBottom ? centerY + (int) radius : centerY + height;
for (int y = yStart; y < yEnd; ++y) {
if (isPositionWithinSphere(centerX, centerY, centerZ, x, y, z, radius, hollow)) {
positions.add(new BlockPos(x, y + yOffset, z));
}
}
}
}
return positions;
}
private BlockPos getPlayerPosLocal() {
if (mc.player == null) {
return BlockPos.ZERO;
}
double x = Math.floor(mc.player.getPosX());
double y = Math.floor(mc.player.getPosY());
double z = Math.floor(mc.player.getPosZ());
return new BlockPos((int)x, (int)y, (int)z);
}
private double getDistanceOfEntityToBlock(Entity entity, BlockPos blockPos) {
return this.getDistance(entity.getPosX(), entity.getPosY(), entity.getPosZ(),
(double) blockPos.getX(), (double) blockPos.getY(), (double) blockPos.getZ());
}
private double getDistance(double n, double n2, double n3, double n4, double n5, double n6) {
double n7 = n - n4;
double n8 = n2 - n5;
double n9 = n3 - n6;
return (double) MathHelper.sqrt(n7 * n7 + n8 * n8 + n9 * n9);
}
private static boolean isPositionWithinSphere(int centerX, int centerY, int centerZ, int x, int y, int z, float radius, boolean hollow) {
double distanceSq = Math.pow((double) (centerX - x), 2.0D) + Math.pow((double) (centerZ - z), 2.0D) + Math.pow((double) (centerY - y), 2.0D);
return distanceSq < Math.pow((double) radius, 2.0D) && (!hollow || distanceSq >= Math.pow((double) (radius - 1.0F), 2.0D));
}
private int getSlotInInventory() {
if (!cacheTimer.finished(75) && cachedTotemSlot != -1) {
return cachedTotemSlot;
}
for (int i = 0; i < 36; ++i) {
ItemStack itemStack = mc.player.inventory.getStackInSlot(i);
if (itemStack.getItem() == Items.TOTEM_OF_UNDYING && !this.isSaveEnchanted(itemStack)) {
cachedTotemSlot = this.adjustSlotNumber(i);
cacheTimer.reset();
return cachedTotemSlot;
}
}
cachedTotemSlot = -1;
cacheTimer.reset();
return -1;
}
private void prepareTotemHotbar() {
if (mc.player == null) return;
if (InventoryUtil.doesHotbarHaveItem(Items.TOTEM_OF_UNDYING)) return;
int slotInInv = this.getSlotInInventory();
if (slotInInv == -1) return;
int targetHotbar = -1;
for (int i = 0; i < 9; i++) {
if (mc.player.inventory.getStackInSlot(i).isEmpty()) {
targetHotbar = i;
break;
}
}
if (targetHotbar == -1) {
targetHotbar = mc.player.inventory.currentItem;
}
Client.instance.moduleCoordinator.notifySwitching(true, getName());
InventoryUtil.moveItem(slotInInv, targetHotbar);
Client.instance.moduleCoordinator.notifySwitching(false, getName());
}
private int adjustSlotNumber(int slot) {
return slot < 9 ? slot + 36 : slot;
}
@override
public void disable() {
this.oldItem = -1;
super.disable();
}
}
и еще когда ем тож не свапает