Начинающий
Начинающий
- Статус
- Оффлайн
- Регистрация
- 21 Мар 2025
- Сообщения
- 2
- Реакции
- 0
Всем привет,я знаю что на югейме нету нормальный авто свапов на 3.1,и пастерам нужно как-то выживвать,поэтому решил вам слить авто свап,который можно взять под базу и дописать сделав его хорошим
GuiMove.java:
@FunctionRegister(
name = "GuiMove",
type = Category.Movement,
desc = "Бег с открытым инвентарем"
)
public class GuiMove extends Function {
public static GuiMove INSTANCE;
public static final StopWatch SYNC_WATCH = new StopWatch();
public static boolean SYNC_ACTIVE = false;
private final ModeSetting mode = new ModeSetting(
"Режим",
"Spooky",
"Обычный",
"Spooky",
"FunTime"
);
private final List<IPacket<?>> packets = new ArrayList<>();
private final StopWatch wait = new StopWatch();
public GuiMove() {
INSTANCE = this;
addSettings(mode);
}
public static long getGlobalDelay() {
if (INSTANCE == null) return 0;
return switch (INSTANCE.mode.get()) {
case "FunTime" -> 60;
case "Spooky" -> 120;
default -> 0;
};
}
@Subscribe
public void onUpdate(EventUpdate e) {
if (mc.player == null) return;
KeyBinding[] keys = {
mc.gameSettings.keyBindForward,
mc.gameSettings.keyBindBack,
mc.gameSettings.keyBindLeft,
mc.gameSettings.keyBindRight,
mc.gameSettings.keyBindJump,
mc.gameSettings.keyBindSprint
};
if (mc.currentScreen instanceof ChatScreen
|| mc.currentScreen instanceof EditSignScreen) {
return;
}
if (SYNC_ACTIVE && !SYNC_WATCH.isReached(getGlobalDelay())) {
for (KeyBinding key : keys) {
key.setPressed(false);
}
return;
}
if (!mode.is("Обычный")) {
if (!wait.isReached(getDelay())) {
for (KeyBinding key : keys) {
key.setPressed(false);
}
return;
}
}
updateKeyBindingState(keys);
}
@Subscribe
public void onPacket(EventPacket e) {
if (mode.is("Обычный")) return;
if (!(e.getPacket() instanceof CClickWindowPacket p)) return;
if (!MoveUtils.isMoving()) return;
if (mc.currentScreen instanceof InventoryScreen) {
packets.add(p);
e.cancel();
}
}
@Subscribe
public void onClose(InventoryCloseEvent e) {
if (mode.is("Обычный")) return;
if (!(mc.currentScreen instanceof InventoryScreen)) return;
if (packets.isEmpty()) return;
if (!MoveUtils.isMoving()) return;
new Thread(() -> {
wait.reset();
SYNC_ACTIVE = true;
SYNC_WATCH.reset();
try {
Thread.sleep(getDelay());
} catch (InterruptedException ignored) {}
for (IPacket<?> p : packets) {
mc.player.connection.sendPacketWithoutEvent(p);
}
packets.clear();
SYNC_ACTIVE = false;
}).start();
e.cancel();
}
private long getDelay() {
return switch (mode.get()) {
case "FunTime" -> 60;
case "Spooky" -> 120;
default -> 0;
};
}
private void updateKeyBindingState(KeyBinding[] keyBindings) {
for (KeyBinding key : keyBindings) {
boolean pressed = InputMappings.isKeyDown(
mc.getMainWindow().getHandle(),
key.getDefault().getKeyCode()
);
key.setPressed(pressed);
}
}
@Override
public boolean onDisable() {
packets.clear();
SYNC_ACTIVE = false;
return super.onDisable();
}
}
AutoSwap.java:
@FieldDefaults(level = AccessLevel.PRIVATE)
@FunctionRegister(name = "AutoSwap", type = Category.Combat, desc = "Свапает предмет")
public class AutoSwap extends Function {
final ModeSetting itemType = new ModeSetting("Предмет", "Щит", "Щит", "Геплы", "Тотем", "Шар");
final ModeSetting swapType = new ModeSetting("Свапать на", "Геплы", "Щит", "Геплы", "Тотем", "Шар");
final BindSetting keyToSwap = new BindSetting("Кнопка", -1);
final BooleanSetting notify = new BooleanSetting("Оповещать", true);
final Animation notificationAlpha = new DecelerateAnimation(200, 255);
final Animation notificationY = new DecelerateAnimation(200, 10);
String currentMessage = "";
Item displayItem = Items.AIR;
long lastSwapTime = 0;
boolean isSwapping = false;
public AutoSwap() {
addSettings(itemType, swapType, keyToSwap, notify);
}
@Subscribe
private void onUpdate(EventUpdate e) {
if (mc.player == null) return;
handleNotifications();
}
@Subscribe
private void onKey(EventKey e) {
if (mc.player == null || !e.isKeyDown(keyToSwap.get()) || isSwapping)
return;
isSwapping = true;
GuiMove.SYNC_ACTIVE = true;
GuiMove.SYNC_WATCH.reset();
new Thread(() -> {
try {
Thread.sleep(GuiMove.getGlobalDelay());
} catch (InterruptedException ignored) {}
mc.enqueue(() -> {
handleSwap();
isSwapping = false;
GuiMove.SYNC_ACTIVE = false;
});
}).start();
}
private void handleSwap() {
Item offhandItem = mc.player.getHeldItemOffhand().getItem();
Item selected = getItemByType(itemType.get());
Item target = getItemByType(swapType.get());
Item need = offhandItem == selected ? target : selected;
int slot = getSlot(need);
if (slot < 0) return;
if (!mc.player.inventory.getItemStack().isEmpty()) {
mc.playerController.windowClick(0, slot, 0, ClickType.PICKUP, mc.player);
}
mc.playerController.windowClick(0, slot, 0, ClickType.PICKUP, mc.player);
mc.playerController.windowClick(0, 45, 0, ClickType.PICKUP, mc.player);
if (!mc.player.inventory.getItemStack().isEmpty()) {
mc.playerController.windowClick(0, slot, 0, ClickType.PICKUP, mc.player);
}
mc.player.connection.sendPacket(new CPlayerTryUseItemPacket(Hand.OFF_HAND));
showNotification(need);
}
@Subscribe
private void onDisplay(EventDisplay e) {
if (e.getType() != EventDisplay.Type.POST || !notify.get() || currentMessage.isEmpty()) return;
int alpha = (int) notificationAlpha.getOutput();
MatrixStack ms = e.getMatrixStack();
float iconSize = 16;
float textWidth = Fonts.montserrat.getWidth(currentMessage, 5.5f) + 6;
float height = 16;
float gap = 2;
float totalWidth = iconSize + gap + textWidth;
float x = (mc.getMainWindow().getScaledWidth() - totalWidth) / 2f;
float y = mc.getMainWindow().getScaledHeight() / 2f + 50 - (float) notificationY.getOutput();
DisplayUtils.drawRoundedRect(x, y, iconSize, height, 2, ColorUtils.rgba(0, 0, 0, alpha));
DisplayUtils.drawRoundedRect(x + iconSize + gap, y, textWidth, height, 2, ColorUtils.rgba(0, 0, 0, alpha));
Fonts.montserrat.drawText(ms, currentMessage,
x + iconSize + gap + 3,
y + 5.5f,
ColorUtils.rgba(255, 255, 255, alpha),
5.5f);
if (displayItem != Items.AIR) {
RenderSystem.pushMatrix();
RenderSystem.translatef(x, y, 0);
RenderSystem.scalef(0.85f, 0.85f, 0.85f);
RenderHelper.enableStandardItemLighting();
mc.getItemRenderer().renderItemAndEffectIntoGUI(new ItemStack(displayItem), 1, 1);
RenderHelper.disableStandardItemLighting();
RenderSystem.popMatrix();
}
}
private void handleNotifications() {
if (currentMessage.isEmpty()) return;
if (System.currentTimeMillis() - lastSwapTime > 1500) {
notificationAlpha.setDirection(Direction.BACKWARDS);
notificationY.setDirection(Direction.BACKWARDS);
if (notificationAlpha.finished(Direction.BACKWARDS))
currentMessage = "";
} else {
notificationAlpha.setDirection(Direction.FORWARDS);
notificationY.setDirection(Direction.FORWARDS);
}
}
private void showNotification(Item item) {
if (!notify.get()) return;
currentMessage = item.getName().getString();
displayItem = item;
lastSwapTime = System.currentTimeMillis();
notificationAlpha.setDirection(Direction.FORWARDS);
notificationY.setDirection(Direction.FORWARDS);
}
private Item getItemByType(String type) {
return switch (type) {
case "Щит" -> Items.SHIELD;
case "Тотем" -> Items.TOTEM_OF_UNDYING;
case "Геплы" -> Items.GOLDEN_APPLE;
case "Шар" -> Items.PLAYER_HEAD;
default -> Items.AIR;
};
}
private int getSlot(Item item) {
for (int i = 0; i < 36; i++) {
ItemStack s = mc.player.inventory.getStackInSlot(i);
if (s.getItem() == item)
return i < 9 ? i + 36 : i;
}
return -1;
}
@Override
public boolean onDisable() {
isSwapping = false;
GuiMove.SYNC_ACTIVE = false;
return super.onDisable();
}
}