Начинающий
- Статус
- Оффлайн
- Регистрация
- 25 Окт 2024
- Сообщения
- 11
- Реакции
- 0
- Выберите загрузчик игры
- Forge
Всем привет, думаю кому-то понадобиться AutoSwap как в пульсе (из luminar visual)
Java:
public class AutoSwap extends Function
{
public ModeSetting from;
public ModeSetting to;
public BindSetting swapKey;
public SliderSetting delay;
boolean swap;
boolean opened;
TimerUtil timer;
TimerUtil timer2;
public AutoSwap() {
super("AutoSwap", Category.Utils);
this.from = new ModeSetting("Свап с", "Тотем", new String[] { "Тотем", "Сфера" });
this.to = new ModeSetting("Свап на", "Тотем", new String[] { "Тотем", "Сфера" });
this.swapKey = new BindSetting("Кнопка свапа", -1);
this.delay = new SliderSetting("Задержка", 150.0f, 100.0f, 250.0f, 25.0f);
this.timer = new TimerUtil();
this.timer2 = new TimerUtil();
this.addSettings(new Setting[] { this.from, this.to, this.swapKey, this.delay });
}
public void onKey(final int key) {
if (this.swapKey.get() == key && this.timer.passed(250L)) {
this.swap = true;
this.timer.reset();
this.timer2.reset();
}
}
@Subscribe
public void onUpdate(final EventUpdate e) {
if (PlayerUtils.connectedTo("space-times")) {
this.print("Эта функция запрещена на сервере Space-Times!");
this.toggle();
return;
}
final ItemStack offhandItemStack = AutoSwap.mc.player.getOffhandItem();
final Item currentItem = offhandItemStack.getItem();
final boolean isHoldingSwapItem = currentItem == this.getSwapItem();
final boolean isHoldingSelectedItem = currentItem == this.getSelectedItem();
final int selectedItemSlot = this.getBestSlotForItem(this.getSelectedItem());
final int swapItemSlot = this.getBestSlotForItem(this.getSwapItem());
final boolean isSameItem = this.getSwapItem() == this.getSelectedItem();
final KeyBinding[] pressedKeys = { AutoSwap.mc.options.keyUp, AutoSwap.mc.options.keyDown, AutoSwap.mc.options.keyLeft, AutoSwap.mc.options.keyRight, AutoSwap.mc.options.keyJump, AutoSwap.mc.options.keySprint };
if (!this.opened) {
this.updateKeyBindingState(pressedKeys);
}
if (!this.swap) {
return;
}
if (isSameItem) {
if (selectedItemSlot >= 0) {
if (!isHoldingSelectedItem || (isSameItem && isHoldingSwapItem)) {
if (!this.opened) {
if (selectedItemSlot <= 35) {
AutoSwap.mc.setScreen((Screen)new InventoryScreen((PlayerEntity)AutoSwap.mc.player));
}
else {
for (final KeyBinding keyBinding : pressedKeys) {
keyBinding.setDown(false);
}
}
this.opened = true;
}
if (this.timer2.passed(this.delay.get().longValue())) {
InventoryUtil.moveItem(selectedItemSlot, 45);
if (selectedItemSlot <= 35) {
AutoSwap.mc.setScreen((Screen)null);
}
this.swap = false;
this.opened = false;
}
}
}
else if (swapItemSlot >= 0) {
if (!isHoldingSwapItem || (isSameItem && isHoldingSelectedItem)) {
if (!this.opened) {
if (swapItemSlot <= 35) {
AutoSwap.mc.setScreen((Screen)new InventoryScreen((PlayerEntity)AutoSwap.mc.player));
}
else {
for (final KeyBinding keyBinding : pressedKeys) {
keyBinding.setDown(false);
}
}
this.opened = true;
}
if (this.timer2.passed(this.delay.get().longValue())) {
InventoryUtil.moveItem(swapItemSlot, 45);
if (swapItemSlot <= 35) {
AutoSwap.mc.setScreen((Screen)null);
}
this.swap = false;
this.opened = false;
}
}
}
else {
this.swap = false;
}
}
else {
if (selectedItemSlot >= 0 && (!isHoldingSelectedItem || (isSameItem && isHoldingSwapItem))) {
if (!this.opened) {
if (selectedItemSlot <= 35) {
AutoSwap.mc.setScreen((Screen)new InventoryScreen((PlayerEntity)AutoSwap.mc.player));
}
else {
for (final KeyBinding keyBinding : pressedKeys) {
keyBinding.setDown(false);
}
}
this.opened = true;
}
if (this.timer2.passed(this.delay.get().longValue())) {
InventoryUtil.moveItem(selectedItemSlot, 45);
if (selectedItemSlot <= 35) {
AutoSwap.mc.setScreen((Screen)null);
}
this.swap = false;
this.opened = false;
}
}
if (swapItemSlot >= 0 && (!isHoldingSwapItem || (isSameItem && isHoldingSelectedItem))) {
if (!this.opened) {
if (swapItemSlot <= 35) {
AutoSwap.mc.setScreen((Screen)new InventoryScreen((PlayerEntity)AutoSwap.mc.player));
}
else {
for (final KeyBinding keyBinding : pressedKeys) {
keyBinding.setDown(false);
}
}
this.opened = true;
}
if (this.timer2.passed(this.delay.get().longValue())) {
InventoryUtil.moveItem(swapItemSlot, 45);
if (swapItemSlot <= 35) {
AutoSwap.mc.setScreen((Screen)null);
}
this.swap = false;
this.opened = false;
}
}
}
}
private void updateKeyBindingState(final KeyBinding[] keyBindings) {
for (final KeyBinding keyBinding : keyBindings) {
final boolean isKeyPressed = InputMappings.isKeyDown(AutoSwap.mc.getWindow().getWindow(), keyBinding.getKey().getValue());
keyBinding.setDown(isKeyPressed);
}
}
private Item getSwapItem() {
return this.getItemByType(this.to.get());
}
private Item getSelectedItem() {
return this.getItemByType(this.from.get());
}
private Item getItemByType(final String itemType) {
Item item = null;
switch (itemType) {
case "\u0422\u043e\u0442\u0435\u043c": {
item = Items.TOTEM_OF_UNDYING;
break;
}
case "\u0421\u0444\u0435\u0440\u0430": {
item = Items.PLAYER_HEAD;
break;
}
default: {
item = Items.AIR;
break;
}
}
return item;
}
private int getBestSlotForItem(final Item item) {
for (int i = 0; i < 9; ++i) {
if (AutoSwap.mc.player.inventory.getItem(i).getItem() == item) {
return i + 36;
}
}
for (int i = 9; i < 36; ++i) {
final ItemStack stack = AutoSwap.mc.player.inventory.getItem(i);
if (stack.getItem() == item && stack.isEnchanted()) {
return i;
}
}
for (int i = 9; i < 36; ++i) {
if (AutoSwap.mc.player.inventory.getItem(i).getItem() == item) {
return i;
}
}
return -1;
}
public void onEnable() {
super.onEnable();
}
}