11package pro .mikey .autoclicker ;
22
33import com .google .gson .Gson ;
4- import net .minecraft .client . MinecraftClient ;
5- import net .minecraft .client .gui . DrawContext ;
6- import net .minecraft .client .network . ClientPlayerEntity ;
7- import net .minecraft .client .option . KeyBinding ;
8- import net .minecraft .client .render . RenderTickCounter ;
9- import net .minecraft .client .resource . language . I18n ;
10- import net .minecraft .entity . LivingEntity ;
11- import net .minecraft .item . ShieldItem ;
12- import net .minecraft .text . Text ;
13- import net .minecraft .util . Formatting ;
14- import net .minecraft .util . Hand ;
15- import net .minecraft .util . hit .EntityHitResult ;
16- import net .minecraft .util . hit .HitResult ;
4+ import net .minecraft .ChatFormatting ;
5+ import net .minecraft .client .DeltaTracker ;
6+ import net .minecraft .client .KeyMapping ;
7+ import net .minecraft .client .Minecraft ;
8+ import net .minecraft .client .gui . GuiGraphics ;
9+ import net .minecraft .client .player . LocalPlayer ;
10+ import net .minecraft .client . resources . language . I18n ;
11+ import net .minecraft .network . chat . Component ;
12+ import net .minecraft .world . InteractionHand ;
13+ import net .minecraft .world . entity . LivingEntity ;
14+ import net .minecraft .world . item . ShieldItem ;
15+ import net .minecraft .world . phys .EntityHitResult ;
16+ import net .minecraft .world . phys .HitResult ;
1717import org .apache .logging .log4j .LogManager ;
1818import org .apache .logging .log4j .Logger ;
1919import org .lwjgl .glfw .GLFW ;
2828public class AutoClicker {
2929 public static final String MOD_ID = "autoclicker" ;
3030 public static final Logger LOGGER = LogManager .getLogger (MOD_ID );
31- public static final KeyBinding openConfig =
32- new KeyBinding ("keybinding.open-gui" , GLFW .GLFW_KEY_O , "category.autoclicker-fabric" );
33- public static final KeyBinding toggleHolding =
34- new KeyBinding ("keybinding.toggle-hold" , GLFW .GLFW_KEY_I , "category.autoclicker-fabric" );
35- private static final Path CONFIG_DIR = Paths .get (MinecraftClient .getInstance ().runDirectory .getPath () + "/config" );
31+ public static final KeyMapping openConfig =
32+ new KeyMapping ("keybinding.open-gui" , GLFW .GLFW_KEY_O , "category.autoclicker-fabric" );
33+ public static final KeyMapping toggleHolding =
34+ new KeyMapping ("keybinding.toggle-hold" , GLFW .GLFW_KEY_I , "category.autoclicker-fabric" );
35+ private static final Path CONFIG_DIR = Paths .get (Minecraft .getInstance ().gameDirectory .getPath () + "/config" );
3636 private static final Path CONFIG_FILE = Paths .get (CONFIG_DIR + "/auto-clicker-fabric.json" );
3737 public static Holding .AttackHolding leftHolding ;
3838 public static Holding rightHolding ;
@@ -59,7 +59,7 @@ public void onInitialize() {
5959 LOGGER .info ("Auto Clicker Initialised" );
6060 }
6161
62- public void clientReady (MinecraftClient client ) {
62+ public void clientReady (Minecraft client ) {
6363 if (!Files .exists (CONFIG_FILE )) {
6464 try {
6565 Files .createDirectories (CONFIG_DIR );
@@ -83,9 +83,9 @@ public void clientReady(MinecraftClient client) {
8383 }
8484 }
8585
86- leftHolding = new Holding .AttackHolding (client .options .attackKey , this .config .getLeftClick ());
87- rightHolding = new Holding (client .options .useKey , this .config .getRightClick ());
88- jumpHolding = new Holding (client .options .jumpKey , this .config .getJump ());
86+ leftHolding = new Holding .AttackHolding (client .options .keyAttack , this .config .getLeftClick ());
87+ rightHolding = new Holding (client .options .keyUse , this .config .getRightClick ());
88+ jumpHolding = new Holding (client .options .keyJump , this .config .getJump ());
8989 hudConfig = this .config .getHudConfig ();
9090 }
9191
@@ -101,57 +101,57 @@ public void saveConfig() {
101101 }
102102 }
103103
104- public void RenderGameOverlayEvent ( DrawContext context , RenderTickCounter delta ) {
104+ public void renderGameOverlayEvent ( GuiGraphics context , DeltaTracker delta ) {
105105
106106 if ((!leftHolding .isActive () && !rightHolding .isActive () && !jumpHolding .isActive ()) || !this .isActive || !config .getHudConfig ().isEnabled ()) {
107107 return ;
108108 }
109109
110- MinecraftClient client = MinecraftClient .getInstance ();
110+ Minecraft client = Minecraft .getInstance ();
111111
112112 if (leftHolding .isActive ()) {
113- Text text = Language .HUD_HOLDING .getText (I18n .translate (leftHolding .getKey ().getTranslationKey ()));
113+ Component text = Language .HUD_HOLDING .getText (I18n .get (leftHolding .getKey ().getName ()));
114114 int y = getHudY () + (15 * 0 );
115115 int x = getHudX (text );
116- context .drawTextWithShadow (client .textRenderer , text .asOrderedText (), x , y , 0xffffff );
116+ context .drawString (client .font , text .getVisualOrderText (), x , y , 0xffffff );
117117 }
118118
119119 if (rightHolding .isActive ()) {
120- Text text = Language .HUD_HOLDING .getText (I18n .translate (rightHolding .getKey ().getTranslationKey ()));
120+ Component text = Language .HUD_HOLDING .getText (I18n .get (rightHolding .getKey ().getName ()));
121121 int y = getHudY () + (15 * 1 );
122122 int x = getHudX (text );
123- context .drawTextWithShadow (client .textRenderer , text .asOrderedText (), x , y , 0xffffff );
123+ context .drawString (client .font , text .getVisualOrderText (), x , y , 0xffffff );
124124 }
125125
126126 if (jumpHolding .isActive ()) {
127- Text text = Language .HUD_HOLDING .getText (I18n .translate (jumpHolding .getKey ().getTranslationKey ()));
127+ Component text = Language .HUD_HOLDING .getText (I18n .get (jumpHolding .getKey ().getName ()));
128128 int y = getHudY () + (15 * 2 );
129129 int x = getHudX (text );
130- context .drawTextWithShadow (client .textRenderer , text .asOrderedText (), x , y , 0xffffff );
130+ context .drawString (client .font , text .getVisualOrderText (), x , y , 0xffffff );
131131 }
132132 }
133133
134- public int getHudX (Text text ){
135- MinecraftClient client = MinecraftClient .getInstance ();
134+ public int getHudX (Component text ){
135+ Minecraft client = Minecraft .getInstance ();
136136
137137 String location = this .config .getHudConfig ().getLocation ();
138138 return switch (location ) {
139139 case "top-left" , "bottom-left" -> 10 ;
140- case "top-right" , "bottom-right" -> (MinecraftClient .getInstance ().getWindow ().getScaledWidth ()) - 10 - client .textRenderer . getWidth (text );
140+ case "top-right" , "bottom-right" -> (Minecraft .getInstance ().getWindow ().getGuiScaledWidth ()) - 10 - client .font . width (text );
141141 default -> 10 ;
142142 };
143143 }
144144 public int getHudY (){
145145 String location = this .config .getHudConfig ().getLocation ();
146146 return switch (location ) {
147147 case "top-left" , "top-right" -> 10 ;
148- case "bottom-left" , "bottom-right" -> (MinecraftClient .getInstance ().getWindow ().getScaledHeight ()) - 50 ;
148+ case "bottom-left" , "bottom-right" -> (Minecraft .getInstance ().getWindow ().getGuiScaledHeight ()) - 50 ;
149149 default -> 10 ;
150150 };
151151 }
152152
153- public void clientTickEvent (MinecraftClient mc ) {
154- if (mc .player == null || mc .world == null ) {
153+ public void clientTickEvent (Minecraft mc ) {
154+ if (mc .player == null || mc .level == null ) {
155155 return ;
156156 }
157157 if (!mc .player .isAlive ()) this .isActive = false ;
@@ -173,7 +173,7 @@ public void clientTickEvent(MinecraftClient mc) {
173173 this .keyInputEvent (mc );
174174 }
175175
176- private void handleActiveHolding (MinecraftClient mc , Holding key ) {
176+ private void handleActiveHolding (Minecraft mc , Holding key ) {
177177 assert mc .player != null ;
178178 if (!key .isActive ()) {
179179 return ;
@@ -188,17 +188,17 @@ private void handleActiveHolding(MinecraftClient mc, Holding key) {
188188 }
189189
190190 // Press the button twice by toggling 1 and 0
191- key .getKey ().setPressed (key .getTimeout () == 1 );
191+ key .getKey ().setDown (key .getTimeout () == 1 );
192192
193- if (key .getKey ().isPressed ()) {
193+ if (key .getKey ().isDown ()) {
194194 this .attemptMobAttack (mc , key );
195195 }
196196 }
197197 key .decreaseTimeout ();
198198 } else {
199199 // Handle the click if it's done normally
200- key .getKey ().setPressed (!key .getKey ().isPressed ());
201- if (key .getKey ().isPressed ()) {
200+ key .getKey ().setDown (!key .getKey ().isDown ());
201+ if (key .getKey ().isDown ()) {
202202 this .attemptMobAttack (mc , key );
203203 }
204204 }
@@ -211,72 +211,72 @@ private void handleActiveHolding(MinecraftClient mc, Holding key) {
211211 if (key .isRespectCooldown ()) {
212212 // Don't do anything if they're not looking at something
213213 if (key instanceof Holding .AttackHolding && ((Holding .AttackHolding ) key ).isMobMode () && !this .isPlayerLookingAtMob (mc )) {
214- if (key .getKey ().isPressed ()) {
215- key .getKey ().setPressed (false );
214+ if (key .getKey ().isDown ()) {
215+ key .getKey ().setDown (false );
216216 }
217217 return ;
218218 }
219219
220- if (mc .player .getAttackCooldownProgress (0 ) == 1.0F ) {
221- key .getKey ().setPressed (true );
220+ if (mc .player .getAttackStrengthScale (0 ) == 1.0F ) {
221+ key .getKey ().setDown (true );
222222 this .attemptMobAttack (mc , key );
223223 } else {
224- key .getKey ().setPressed (false );
224+ key .getKey ().setDown (false );
225225 }
226226 } else {
227227 // Hold the click
228- key .getKey ().setPressed (true );
228+ key .getKey ().setDown (true );
229229 }
230230 }
231231
232- private void attemptMobAttack (MinecraftClient mc , Holding key ) {
232+ private void attemptMobAttack (Minecraft mc , Holding key ) {
233233 // Don't attack on a right click
234234 if (key .getKey () != leftHolding .getKey ()) {
235235 return ;
236236 }
237237
238- HitResult rayTrace = mc .crosshairTarget ;
239- if (rayTrace instanceof EntityHitResult && mc .interactionManager != null ) {
238+ HitResult rayTrace = mc .hitResult ;
239+ if (rayTrace instanceof EntityHitResult && mc .gameMode != null ) {
240240 if (!(config .getLeftClick ().isRespectShield () && isShielding (mc .player ))) {
241- mc .interactionManager . attackEntity (mc .player , ((EntityHitResult ) rayTrace ).getEntity ());
241+ mc .gameMode . attack (mc .player , ((EntityHitResult ) rayTrace ).getEntity ());
242242 if (mc .player != null ) {
243- mc .player .swingHand ( Hand .MAIN_HAND );
243+ mc .player .swing ( InteractionHand .MAIN_HAND );
244244 }
245245 }
246246 }
247247 }
248248
249- private boolean isShielding (ClientPlayerEntity player ) {
249+ private boolean isShielding (LocalPlayer player ) {
250250 if (player .isUsingItem ()) {
251- return player .getActiveItem ().getItem () instanceof ShieldItem ;
251+ return player .getUseItem ().getItem () instanceof ShieldItem ;
252252 }
253253 return false ;
254254 }
255255
256- private boolean isPlayerLookingAtMob (MinecraftClient mc ) {
257- HitResult rayTrace = mc .crosshairTarget ;
256+ private boolean isPlayerLookingAtMob (Minecraft mc ) {
257+ HitResult rayTrace = mc .hitResult ;
258258 return rayTrace instanceof EntityHitResult && ((EntityHitResult ) rayTrace ).getEntity () instanceof LivingEntity livingEntity && livingEntity .isAlive () && livingEntity .isAttackable ();
259259 }
260260
261- private void keyInputEvent (MinecraftClient mc ) {
261+ private void keyInputEvent (Minecraft mc ) {
262262 assert mc .player != null ;
263- while (toggleHolding .wasPressed ()) {
263+ while (toggleHolding .consumeClick ()) {
264264 this .isActive = !this .isActive ;
265- mc .player .sendMessage (
265+ mc .player .displayClientMessage (
266266 (this .isActive ? Language .MSG_HOLDING_KEYS : Language .MSG_RELEASED_KEYS )
267267 .getText ()
268- . formatted (this .isActive ? Formatting .GREEN : Formatting .RED ),
268+ . withStyle (this .isActive ? ChatFormatting .GREEN : ChatFormatting .RED ),
269269 true
270270 );
271271
272272 if (!this .isActive ) {
273- if (leftHolding .isActive ()) leftHolding .getKey ().setPressed (false );
274- if (rightHolding .isActive ()) rightHolding .getKey ().setPressed (false );
275- if (jumpHolding .isActive ()) jumpHolding .getKey ().setPressed (false );
273+ if (leftHolding .isActive ()) leftHolding .getKey ().setDown (false );
274+ if (rightHolding .isActive ()) rightHolding .getKey ().setDown (false );
275+ if (jumpHolding .isActive ()) jumpHolding .getKey ().setDown (false );
276276 }
277277 }
278278
279- while (openConfig .wasPressed ()) {
279+ while (openConfig .consumeClick ()) {
280280 mc .setScreen (getConfigScreen ());
281281 }
282282 }
0 commit comments