11package xyz .templecheats .templeclient .features .module .modules .combat ;
22
3+ import net .minecraft .client .gui .inventory .GuiInventory ;
4+ import net .minecraft .init .Blocks ;
35import net .minecraft .init .Items ;
46import net .minecraft .inventory .ClickType ;
5- import net .minecraft .item . Item ;
6- import net .minecraft . item . ItemStack ;
7- import net .minecraft . network . play . client . CPacketPlayer ;
7+ import net .minecraft .util . math . BlockPos ;
8+ import net .minecraftforge . fml . common . eventhandler . SubscribeEvent ;
9+ import net .minecraftforge . fml . common . gameevent . TickEvent ;
810import org .lwjgl .input .Keyboard ;
911import xyz .templecheats .templeclient .features .module .Module ;
10- import xyz .templecheats .templeclient .manager .ModuleManager ;
11- import xyz .templecheats .templeclient .util .setting .impl .DoubleSetting ;
12+ import xyz .templecheats .templeclient .util .setting .impl .BooleanSetting ;
13+ import xyz .templecheats .templeclient .util .setting .impl .EnumSetting ;
14+ import xyz .templecheats .templeclient .util .setting .impl .IntSetting ;
1215
1316import java .util .Arrays ;
17+ import java .util .Map ;
1418
15- public class Offhand extends Module {
19+ public class Offhand extends Module {
1620 /*
1721 * Settings
1822 */
19- private final DoubleSetting health = new DoubleSetting ("Health" , this , 0.0d , 36.0d , 14.0d );
20- private final DoubleSetting defaultHealthVal = new DoubleSetting ("DHV" , this , 0.0f , 36.0f , 14.0f );
23+ private final EnumSetting < Item > item = new EnumSetting < > ("Item" , this , Item .Crystal );
24+ private final IntSetting totemHp = new IntSetting ("Totem HP" , this , 0 , 36 , 16 );
25+ private final BooleanSetting gappleInHole = new BooleanSetting ("Gap In Hole" , this , false );
26+ private final IntSetting gappleInHoleHP = new IntSetting ("Gap Hole HP" , this , 0 , 36 , 16 );
27+ private final BooleanSetting delay = new BooleanSetting ("Delay" , this , false );
28+
29+ /*
30+ * Variables
31+ */
32+ private boolean switching = false ;
33+ private int last_slot ;
34+ private Map < String , Item > itemMap ;
2135
2236 public Offhand () {
2337 super ("Offhand" , "Puts items in you're offhand" , Keyboard .KEY_NONE , Category .Combat );
24- registerSettings (health , defaultHealthVal );
38+ registerSettings (gappleInHole , delay , gappleInHoleHP , totemHp , item );
2539 }
2640
27- @ Override
28- public void onUpdate () {
29- final int slot = slot ();
30- if (slot != -1 ) {
31- swapItem (slot );
32- }
33- if (mc .player .getHeldItemOffhand ().isEmpty ()) {
34- inventorySlot (Items .END_CRYSTAL );
41+ @ SubscribeEvent
42+ public void onTick (TickEvent .ClientTickEvent event ) {
43+
44+ if (mc .player == null )
45+ return ;
46+
47+ if (mc .currentScreen == null || mc .currentScreen instanceof GuiInventory ) {
48+
49+ if (switching ) {
50+ swap_items (last_slot , 2 );
51+ return ;
52+ }
53+
54+ float hp = mc .player .getHealth () + mc .player .getAbsorptionAmount ();
55+
56+ if (hp > totemHp .intValue ()) {
57+ if (gappleInHole .booleanValue () && hp > gappleInHoleHP .intValue () && is_in_hole ()) {
58+ swap_items (get_item_slot (Items .GOLDEN_APPLE ), delay .booleanValue () ? 1 : 0 );
59+ return ;
60+ }
61+ switch (item .value ()) {
62+ case Crystal :
63+ swap_items (get_item_slot (Items .END_CRYSTAL ), 0 );
64+ break ;
65+ case Gapple :
66+ swap_items (get_item_slot (Items .GOLDEN_APPLE ), delay .booleanValue () ? 1 : 0 );
67+ break ;
68+ case Totem :
69+ swap_items (get_item_slot (Items .TOTEM_OF_UNDYING ), delay .booleanValue () ? 1 : 0 );
70+ break ;
71+ }
72+ } else {
73+ swap_items (get_item_slot (Items .TOTEM_OF_UNDYING ), delay .booleanValue () ? 1 : 0 );
74+ return ;
75+ }
76+
77+ if (mc .player .getHeldItemOffhand ().getItem () == Items .AIR ) {
78+ swap_items (get_item_slot (Items .TOTEM_OF_UNDYING ), delay .booleanValue () ? 1 : 0 );
79+ }
80+
3581 }
82+
3683 }
37- private int slot () {
38- if (mc .currentScreen != null ) {
39- return -1 ;
84+
85+ public void swap_items (int slot , int step ) {
86+ if (slot == -1 )
87+ return ;
88+ if (step == 0 ) {
89+ mc .playerController .windowClick (0 , slot , 0 , ClickType .PICKUP , mc .player );
90+ mc .playerController .windowClick (0 , 45 , 0 , ClickType .PICKUP , mc .player );
91+ mc .playerController .windowClick (0 , slot , 0 , ClickType .PICKUP , mc .player );
4092 }
41- final int totem = inventorySlot (Items .TOTEM_OF_UNDYING );
42- if (totem == -1 ) {
43- health .setDoubleValue (0.1f );
44- } else {
45- health .setDoubleValue (defaultHealthVal .doubleValue ());
93+ if (step == 1 ) {
94+ mc .playerController .windowClick (0 , slot , 0 , ClickType .PICKUP , mc .player );
95+ switching = true ;
96+ last_slot = slot ;
4697 }
47- if (mc .player .getHealth () + mc .player .getAbsorptionAmount () <= health .doubleValue ()) {
48- return totem ;
98+ if (step == 2 ) {
99+ mc .playerController .windowClick (0 , 45 , 0 , ClickType .PICKUP , mc .player );
100+ mc .playerController .windowClick (0 , slot , 0 , ClickType .PICKUP , mc .player );
101+ switching = false ;
49102 }
50- if (mc .player .getHeldItemMainhand ().getItem ().equals (Items .DIAMOND_SWORD )) {
51- if (mc .gameSettings .keyBindUseItem .isKeyDown ()) {
52- return inventorySlot (Items .GOLDEN_APPLE );
53- }
54103
55- }
56- final int crystal = inventorySlot (Items .END_CRYSTAL );
57- if (crystal != -1 ) {
58- return inventorySlot (Items .END_CRYSTAL );
59- }
60- return totem ;
104+ mc .playerController .updateController ();
61105 }
62106
63- private void swapItem (final int i ) {
64- final Item item = mc .player .inventory .getStackInSlot (i ).getItem ();
65- if (!mc .player .getHeldItemOffhand ().getItem ().equals (item )) {
66- int slot = i < 9 ? i + 36 : i ;
67- swap (new int []{slot , 45 , slot });
68- mc .playerController .updateController ();
69- }
70- }
107+ private boolean is_in_hole () {
71108
72- private void swap (final int [] slots ) {
73- if (mc .getConnection () != null ) {
74- Arrays .stream (slots ).forEach (i -> mc .playerController .windowClick (0 , i , 0 , ClickType .PICKUP , mc .player ));
75- mc .getConnection ().sendPacket (new CPacketPlayer ());
76- }
109+ BlockPos player_block = GetLocalPlayerPosFloored ();
110+
111+ return mc .world .getBlockState (player_block .east ()).getBlock () != Blocks .AIR &&
112+ mc .world .getBlockState (player_block .west ()).getBlock () != Blocks .AIR &&
113+ mc .world .getBlockState (player_block .north ()).getBlock () != Blocks .AIR &&
114+ mc .world .getBlockState (player_block .south ()).getBlock () != Blocks .AIR ;
77115 }
78116
79- public int inventorySlot (final Item item ) {
80- int itemSlot = -1 ;
81- for (int i = 45 ; i > 0 ; --i ) {
82- final ItemStack stack = mc .player .inventory .getStackInSlot (i );
83- if (stack .getItem ().equals (item )) {
84- itemSlot = i ;
85- break ;
117+ private int get_item_slot (net .minecraft .item .Item input ) {
118+ if (input == mc .player .getHeldItemOffhand ().getItem ())
119+ return -1 ;
120+ for (int i = 36 ; i >= 0 ; i --) {
121+ final net .minecraft .item .Item item = mc .player .inventory .getStackInSlot (i ).getItem ();
122+ if (item == input ) {
123+ if (i < 9 ) {
124+ if (input == Items .GOLDEN_APPLE ) {
125+ return -1 ;
126+ }
127+ i += 36 ;
128+ }
129+ return i ;
86130 }
87131 }
88- return itemSlot ;
132+ return - 1 ;
89133 }
90134
91- @ Override
92- public void onEnable () {
93- super .onEnable ();
94- AutoTotem autoTotem = (AutoTotem ) ModuleManager .getModuleByName ("AutoTotem" );
95- if (autoTotem .isEnabled ()) {
96- autoTotem .disable ();
97- }
135+ public BlockPos GetLocalPlayerPosFloored () {
136+ return new BlockPos (Math .floor (mc .player .posX ), Math .floor (mc .player .posY ), Math .floor (mc .player .posZ ));
98137 }
99- }
100138
139+ public enum Item {
140+ Crystal ,
141+ Gapple ,
142+ Totem
143+ }
144+ }
0 commit comments