package wtf.expensive.modules.impl.combat;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import javafx.scene.input.MouseButton;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityEnderCrystal;
import net.minecraft.entity.item.EntityMinecartTNT;
import net.minecraft.entity.item.EntityTNTPrimed;
import net.minecraft.init.Items;
import net.minecraft.inventory.ClickType;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemAir;
import net.minecraft.item.ItemAppleGold;
import net.minecraft.item.ItemStack;
import net.minecraft.network.Packet;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import wtf.expensive.event.EventListener;
import wtf.expensive.event.impl.player.EventUpdate;
import wtf.expensive.modules.Module;
import wtf.expensive.modules.ModuleAnnotation;
import wtf.expensive.modules.Type;
import wtf.expensive.modules.settings.imp.SliderSetting;
import wtf.expensive.utility.movement.MoveUtility;
import java.util.Comparator;
import static wtf.expensive.modules.impl.combat.AutoTotem.getSlotIDFromItem;
@ModuleAnnotation(name = "Auto GApple", type = Type.COMBAT)
public class AutoGApple extends Module {
private SliderSetting min = new SliderSetting("Trigger health", 15, 0, 19, 1);
private SliderSetting delay = new SliderSetting("Delay", 0, 0, 10, 1);
private boolean active=false;
private final EventListener<EventUpdate> onUpdate = e -> {
if(mc.world==null||mc.player==null)return;
int slot = getSlotIDFromItem(Items.GOLDEN_APPLE);
boolean InHand = mc.player.getHeldItemOffhand().getItem() == Items.GOLDEN_APPLE;
boolean handNotNull = !(mc.player.getHeldItemOffhand().getItem() instanceof ItemAir);
if (System.currentTimeMillis()/60 < delay.get()) {
return;
}
if (mc.player.getHealth()<min.get()) {
// mc.player.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, Items.GOLDEN_APPLE.func_190903_i());
// mc.playerController.updateController();
if(mc.player.getHeldItemOffhand().getItem()!=Items.GOLDEN_APPLE){
mc.playerController.windowClick(0, slot, 0, ClickType.PICKUP, mc.player);
mc.playerController.windowClick(0, 45, 0, ClickType.PICKUP, mc.player);
}
if (isGoldenApple(mc.player.getHeldItemOffhand()) && mc.player.getHealth() <= min.get()) {
active = true;
mc.gameSettings.keyBindUseItem.pressed = true;
} else if (active) {
mc.gameSettings.keyBindUseItem.pressed = false;
active = false;
}
} else if (isGoldenApple(mc.player.getHeldItemOffhand())) {
// mc.gameSettings.keyBindUseItem.pressed = false;
// active = false;
}
};
private boolean isGoldenApple(ItemStack itemStack) {
return (itemStack != null && itemStack.getItem() instanceof ItemAppleGold);
}
// private boolean condition() {
//
// float hp = mc.player.getHealth();
//
// if (min.get() >= hp) {
// return true;
// }
//
// if (mode.get(1)) {
// for (Entity entity : mc.world.loadedEntityList) {
// if (entity instanceof EntityEnderCrystal && mc.player.getDistanceToEntity(entity) <= radiusExplosion.get()) {
// return true;
// }
// if (entity instanceof EntityTNTPrimed && mc.player.getDistanceToEntity(entity) <= radiusExplosion.get()) {
// return true;
// }
// if (entity instanceof EntityMinecartTNT && mc.player.getDistanceToEntity(entity) <= radiusExplosion.get()) {
// return true;
// }
// }
// }
//
// return false;
// }
@Override
public void onDisable() {
if (mc.player == null) return;
mc.player.setSprinting(false);
super.onDisable();
}
}