2019-10-27 15:45:44 +00:00
package me.rigamortis.seppuku.impl.module.combat ;
2021-10-12 03:01:11 +00:00
import me.rigamortis.seppuku.Seppuku ;
2019-10-27 15:45:44 +00:00
import me.rigamortis.seppuku.api.event.EventStageable ;
import me.rigamortis.seppuku.api.event.player.EventPlayerUpdate ;
2021-10-12 03:01:11 +00:00
import me.rigamortis.seppuku.api.event.world.EventLoadWorld ;
2019-10-27 15:45:44 +00:00
import me.rigamortis.seppuku.api.module.Module ;
2019-11-30 00:54:21 +00:00
import me.rigamortis.seppuku.api.value.Value ;
2021-10-12 03:01:11 +00:00
import me.rigamortis.seppuku.impl.module.player.AutoGappleModule ;
2019-10-27 15:45:44 +00:00
import net.minecraft.client.Minecraft ;
import net.minecraft.init.Items ;
import net.minecraft.inventory.ClickType ;
import net.minecraft.item.Item ;
import net.minecraft.item.ItemStack ;
import team.stiff.pomelo.impl.annotated.handler.annotation.Listener ;
/ * *
* Author Seth
* 4 / 30 / 2019 @ 3 : 37 AM .
* /
public final class AutoTotemModule extends Module {
2021-01-15 19:17:10 +00:00
public final Value < Float > health = new Value < > ( " Health " , new String [ ] { " Hp " , " h " } , " The amount of health needed to acquire a totem. " , 7 . 0f , 0 . 0f , 20 . 0f , 0 . 5f ) ;
public final Value < Boolean > crystals = new Value < > ( " Crystals " , new String [ ] { " cry " , " c " } , " Go back to crystals in offhand after health is replenished. " , false ) ;
2021-10-12 03:01:11 +00:00
//public final Value<Boolean> force = new Value<>("Force", new String[]{"f"}, "Prioritize AutoTotem over AutoGapple, etc.", true);
2021-01-15 19:38:30 +00:00
public final Value < Boolean > checkScreen = new Value < > ( " CheckScreen " , new String [ ] { " screen " , " check " , " cs " } , " Checks if a screen is not opened to begin (usually disabled). " , false ) ;
2019-10-27 15:45:44 +00:00
2021-10-12 03:01:11 +00:00
private AutoGappleModule autoGappleModule ;
2019-10-27 15:45:44 +00:00
public AutoTotemModule ( ) {
2020-11-25 20:00:59 +00:00
super ( " AutoTotem " , new String [ ] { " Totem " } , " Automatically places a totem of undying in your offhand " , " NONE " , - 1 , ModuleType . COMBAT ) ;
2019-10-27 15:45:44 +00:00
}
2021-10-12 03:01:11 +00:00
@Listener
public void onLoadWorld ( EventLoadWorld event ) {
if ( event . getWorld ( ) ! = null ) {
this . autoGappleModule = ( AutoGappleModule ) Seppuku . INSTANCE . getModuleManager ( ) . find ( AutoGappleModule . class ) ;
}
}
2019-10-27 15:45:44 +00:00
@Override
public String getMetaData ( ) {
2020-12-08 18:51:53 +00:00
return " " + this . getTotemCount ( ) ;
2019-10-27 15:45:44 +00:00
}
@Listener
public void onUpdate ( EventPlayerUpdate event ) {
2021-01-26 00:52:06 +00:00
final Minecraft mc = Minecraft . getMinecraft ( ) ;
if ( this . checkScreen . getValue ( ) ) {
if ( mc . currentScreen ! = null )
return ;
}
2021-01-15 19:38:30 +00:00
2021-01-26 00:52:06 +00:00
final ItemStack offHand = mc . player . getHeldItemOffhand ( ) ;
2019-10-27 15:45:44 +00:00
2021-01-26 00:52:06 +00:00
if ( event . getStage ( ) = = EventStageable . EventStage . PRE ) {
2021-01-15 19:38:30 +00:00
if ( mc . player . getHealth ( ) < = this . health . getValue ( ) ) {
if ( offHand . getItem ( ) = = Items . TOTEM_OF_UNDYING ) {
return ;
}
2019-10-27 15:45:44 +00:00
2021-01-15 19:38:30 +00:00
final int totemSlot = this . getTotemSlot ( ) ;
2021-01-15 19:17:10 +00:00
2021-01-15 19:38:30 +00:00
if ( totemSlot ! = - 1 ) {
mc . playerController . windowClick ( mc . player . inventoryContainer . windowId , totemSlot , 0 , ClickType . PICKUP , mc . player ) ;
mc . playerController . windowClick ( mc . player . inventoryContainer . windowId , 45 , 0 , ClickType . PICKUP , mc . player ) ;
mc . playerController . windowClick ( mc . player . inventoryContainer . windowId , totemSlot , 0 , ClickType . PICKUP , mc . player ) ;
mc . playerController . updateController ( ) ;
}
2021-01-26 00:52:06 +00:00
}
} else {
if ( mc . player . getHealth ( ) > this . health . getValue ( ) & & this . crystals . getValue ( ) ) {
2021-10-12 03:01:11 +00:00
if ( this . autoGappleModule ! = null ) {
if ( this . autoGappleModule . isEnabled ( ) ) {
if ( this . autoGappleModule . isActiveOffHand ( ) ) {
return ;
}
}
}
2021-01-15 19:38:30 +00:00
if ( offHand . getItem ( ) = = Items . END_CRYSTAL ) {
return ;
}
2021-01-15 19:17:10 +00:00
2021-01-15 19:38:30 +00:00
final int crystalSlot = this . getCrystalSlot ( ) ;
2019-10-27 15:45:44 +00:00
2021-01-15 19:38:30 +00:00
if ( crystalSlot ! = - 1 ) {
mc . playerController . windowClick ( mc . player . inventoryContainer . windowId , crystalSlot , 0 , ClickType . PICKUP , mc . player ) ;
mc . playerController . windowClick ( mc . player . inventoryContainer . windowId , 45 , 0 , ClickType . PICKUP , mc . player ) ;
mc . playerController . windowClick ( mc . player . inventoryContainer . windowId , crystalSlot , 0 , ClickType . PICKUP , mc . player ) ;
mc . playerController . updateController ( ) ;
2019-10-27 15:45:44 +00:00
}
}
}
}
2021-01-15 19:17:10 +00:00
private int getCrystalSlot ( ) {
for ( int i = 0 ; i < 36 ; i + + ) {
final Item item = Minecraft . getMinecraft ( ) . player . inventory . getStackInSlot ( i ) . getItem ( ) ;
if ( item = = Items . END_CRYSTAL ) {
if ( i < 9 ) {
i + = 36 ;
}
return i ;
}
}
return - 1 ;
}
2020-12-08 18:51:53 +00:00
private int getTotemSlot ( ) {
2020-11-25 20:00:59 +00:00
for ( int i = 0 ; i < 36 ; i + + ) {
2019-10-27 15:45:44 +00:00
final Item item = Minecraft . getMinecraft ( ) . player . inventory . getStackInSlot ( i ) . getItem ( ) ;
2020-12-08 18:51:53 +00:00
if ( item = = Items . TOTEM_OF_UNDYING ) {
2019-10-27 15:45:44 +00:00
if ( i < 9 ) {
i + = 36 ;
}
return i ;
}
}
return - 1 ;
}
2021-01-15 19:17:10 +00:00
public int getTotemCount ( ) {
2020-12-08 18:51:53 +00:00
int totems = 0 ;
if ( Minecraft . getMinecraft ( ) . player = = null )
return totems ;
2019-10-27 15:45:44 +00:00
2020-11-25 20:00:59 +00:00
for ( int i = 0 ; i < 45 ; i + + ) {
2019-10-27 15:45:44 +00:00
final ItemStack stack = Minecraft . getMinecraft ( ) . player . inventory . getStackInSlot ( i ) ;
2020-12-08 18:51:53 +00:00
if ( stack . getItem ( ) = = Items . TOTEM_OF_UNDYING ) {
totems + = stack . getCount ( ) ;
2019-10-27 15:45:44 +00:00
}
}
2020-12-08 18:51:53 +00:00
return totems ;
2019-10-27 15:45:44 +00:00
}
}