package fun.rich.features.impl.misc;
import fun.rich.events.player.TickEvent;
import fun.rich.features.module.Module;
import fun.rich.features.module.ModuleCategory;
import fun.rich.utils.client.Instance;
import fun.rich.utils.client.managers.event.EventHandler;
import fun.rich.utils.interactions.inv.InventoryResult;
import fun.rich.utils.interactions.inv.InventoryToolkit;
import net.minecraft.item.Items;
import net.minecraft.screen.slot.SlotActionType;
public class SphereSwap extends Module {
private static final float TARGET_PITCH = 80.7f;
private int savedSlot = -1;
private int headOriginSlot = -1;
private boolean headPlaced = false;
private boolean headFromInventory = false;
private float savedPitch = 0f;
public SphereSwap() {
super("SphereSwap", ModuleCategory.MISC);
}
public static SphereSwap getInstance() {
return Instance.get(SphereSwap.class);
}
@Override
public void activate() {
super.activate();
savedSlot = -1;
headOriginSlot = -1;
headPlaced = false;
headFromInventory = false;
if (mc.player != null) {
savedPitch = mc.player.getPitch();
mc.player.setPitch(TARGET_PITCH);
}
}
@Override
public void deactivate() {
if (mc.player != null) {
mc.player.setPitch(savedPitch);
}
if (headPlaced && mc.player != null) {
if (headFromInventory) {
InventoryToolkit.clickSlot(headOriginSlot, savedSlot, SlotActionType.SWAP);
}
InventoryToolkit.switchTo(savedSlot);
}
savedSlot = -1;
headOriginSlot = -1;
headPlaced = false;
headFromInventory = false;
savedPitch = 0f;
super.deactivate();
}
@EventHandler
public void onTick(TickEvent e) {
if (mc.player == null || mc.world == null) return;
mc.player.setPitch(TARGET_PITCH);
if (headPlaced) return;
savedSlot = mc.player.getInventory().selectedSlot;
InventoryResult hotbar = InventoryToolkit.findItemInHotBar(Items.PLAYER_HEAD);
if (hotbar.found()) {
headFromInventory = false;
InventoryToolkit.switchTo(hotbar.slot());
headPlaced = true;
return;
}
InventoryResult inv = InventoryToolkit.findItemInInventory(Items.PLAYER_HEAD);
if (inv.found()) {
headOriginSlot = inv.slot();
headFromInventory = true;
InventoryToolkit.clickSlot(headOriginSlot, savedSlot, SlotActionType.SWAP);
headPlaced = true;
}
}
}