-
Автор темы
- #1
ElytraSwap - Одевает элитры при включении модуля
Java:
package wtf.chatgpt.client.modules.impl.player;
import net.minecraft.inventory.container.ClickType;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import org.lwjgl.glfw.GLFW;
import wtf.chatgpt.client.event.Event;
import wtf.chatgpt.client.event.impl.player.EventUpdate;
import wtf.chatgpt.client.modules.Module;
import wtf.chatgpt.client.modules.ModuleAnnotation;
import wtf.chatgpt.client.modules.Type;
import wtf.chatgpt.client.util.ChatUtility;
@ModuleAnnotation(name = "ElytraSwap", type = Type.PLAYER)
public class ElytraSwap extends Module {
private int item;
public ElytraSwap() {
this.bind = GLFW.GLFW_KEY_G;
}
@Override
public void onEvent(Event event) {
if (event instanceof EventUpdate) {
if (!hasElytraEquipped()) {
equipElytra();
}
}
}
@Override
public boolean onEnable() {
if (!hasElytraEquipped()) {
equipElytra();
if (!hasElytraEquipped()) {
setState(false);
return false;
}
}
return super.onEnable();
}
@Override
public void onDisable() {
super.onDisable();
unequipElytra();
}
private void equipElytra() {
int elytra = getHotbarSlotOfItem();
if (elytra != -1) {
item = elytra;
mc.playerController.windowClick(0, elytra, 1, ClickType.PICKUP, mc.player);
mc.playerController.windowClick(0, 6, 1, ClickType.PICKUP, mc.player);
mc.playerController.windowClick(0, item, 1, ClickType.PICKUP, mc.player);
} else {
sendMessage("Элитра не найдена!");
}
}
private void unequipElytra() {
int elytra = getHotbarSlotOfItem();
if (elytra == -2) {
mc.playerController.windowClick(0, 6, 1, ClickType.PICKUP, mc.player);
mc.playerController.windowClick(0, this.item, 1, ClickType.PICKUP, mc.player);
mc.playerController.windowClick(0, 6, 1, ClickType.PICKUP, mc.player);
}
}
private boolean hasElytraEquipped() {
for (ItemStack stack : mc.player.getArmorInventoryList()) {
if (stack.getItem() == Items.ELYTRA) {
return true;
}
}
return false;
}
private static int getHotbarSlotOfItem() {
for (ItemStack stack : mc.player.getArmorInventoryList()) {
if (stack.getItem() == Items.ELYTRA) {
return -2;
}
}
int slot = -1;
for (int i = 0; i < 36; i++) {
ItemStack s = mc.player.inventory.getStackInSlot(i);
if (s.getItem() == Items.ELYTRA) {
slot = i;
break;
}
}
if (slot < 9 && slot != -1) {
slot += 36;
}
return slot;
}
public void sendMessage(String message) {
ChatUtility.addChatMessage(message);
}
}