Skip to content
This repository was archived by the owner on Feb 4, 2018. It is now read-only.

Commit e9ca966

Browse files
committed
💄 Refactoring Mixins
1 parent 9e00108 commit e9ca966

File tree

4 files changed

+9
-37
lines changed

4 files changed

+9
-37
lines changed

‎src/main/java/uk/co/hexeption/darkforge/MC.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
package uk.co.hexeption.darkforge;
1919

2020
import net.minecraft.client.Minecraft;
21+
import uk.co.hexeption.darkforge.mixin.imp.IMixinMinecraft;
2122

2223
/**
2324
* Created by Keir on 21/04/2017.
2425
*/
2526
public interface MC {
2627

2728
Minecraft mc = Minecraft.getMinecraft();
29+
IMixinMinecraft mixMC = (IMixinMinecraft) mc;
2830
}

‎src/main/java/uk/co/hexeption/darkforge/mod/Mod.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import net.minecraft.client.settings.GameSettings;
2727
import org.lwjgl.input.Keyboard;
2828
import uk.co.hexeption.darkforge.DarkForge;
29+
import uk.co.hexeption.darkforge.MC;
2930
import uk.co.hexeption.darkforge.event.EventListener;
3031
import uk.co.hexeption.darkforge.font.MinecraftFontRenderer;
3132
import uk.co.hexeption.darkforge.managers.EventManager;
@@ -38,7 +39,7 @@
3839
/**
3940
* Created by Hexeption on 15/01/2017.
4041
*/
41-
public abstract class Mod implements EventListener {
42+
public abstract class Mod implements EventListener, MC {
4243

4344
protected Minecraft mc = Minecraft.getMinecraft();
4445

‎src/main/java/uk/co/hexeption/darkforge/mod/mods/movement/BHop.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void onEvent(Event event) {
4444

4545
if (getState() && event.getType() == Event.Type.PRE) {
4646
if (event instanceof EventMove) {
47-
((IMixinMinecraft) mc).getTimer().timerSpeed = 1.0888F;
47+
mixMC.getTimer().timerSpeed = 1.0888F;
4848

4949
if ((!mc.player.isCollidedHorizontally)) {
5050
if (MathUtils.round(mc.player.posY - (int) mc.player.posY, 3) == MathUtils.round(0.4D, 3)) {

‎src/main/java/uk/co/hexeption/darkforge/utils/LoginUtils.java‎

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -27,40 +27,15 @@
2727
import net.minecraft.util.Session;
2828
import org.apache.logging.log4j.LogManager;
2929
import org.apache.logging.log4j.Logger;
30+
import uk.co.hexeption.darkforge.MC;
3031

3132
import java.lang.reflect.Field;
3233
import java.net.Proxy;
3334

34-
public class LoginUtils {
35+
public class LoginUtils implements MC{
3536

3637
private static final Logger logger = LogManager.getLogger();
3738

38-
public static void setSession(Session s) throws IllegalAccessException {
39-
40-
Class<? extends Minecraft> mc = Minecraft.getMinecraft().getClass();
41-
try {
42-
Field session = null;
43-
44-
for (Field f : mc.getDeclaredFields()) {
45-
if (f.getType().isInstance(s)) {
46-
session = f;
47-
}
48-
}
49-
50-
if (session == null) {
51-
throw new IllegalStateException("no field of type " + Session.class.getCanonicalName() + " declared.");
52-
}
53-
54-
session.setAccessible(true);
55-
session.set(Minecraft.getMinecraft(), s);
56-
session.setAccessible(false);
57-
58-
} catch (Exception e) {
59-
e.printStackTrace();
60-
throw e;
61-
}
62-
}
63-
6439
public static String loginAlt(String email, String password) {
6540

6641
YggdrasilAuthenticationService authenticationService = new YggdrasilAuthenticationService(Proxy.NO_PROXY, "");
@@ -71,7 +46,7 @@ public static String loginAlt(String email, String password) {
7146

7247
try {
7348
authentication.logIn();
74-
setSession(new Session(authentication.getSelectedProfile().getName(), authentication.getSelectedProfile().getId().toString(), authentication.getAuthenticatedToken(), "mojang"));
49+
mixMC.setSession(new Session(authentication.getSelectedProfile().getName(), authentication.getSelectedProfile().getId().toString(), authentication.getAuthenticatedToken(), "mojang"));
7550
displayText = "";
7651
} catch (AuthenticationUnavailableException e) {
7752
displayText = "§4§lCannot contact authentication server!";
@@ -86,8 +61,6 @@ public static String loginAlt(String email, String password) {
8661
logger.error(e.getMessage());
8762
} catch (NullPointerException e) {
8863
displayText = "§4§lWrong password!";
89-
} catch (IllegalAccessException e) {
90-
e.printStackTrace();
9164
}
9265

9366
return displayText;
@@ -110,11 +83,7 @@ public static String getName(String email, String password) {
11083

11184
public static void changeCrackedName(String name) {
11285

113-
try {
114-
setSession(new Session(name, "", "", "mojang"));
115-
} catch (IllegalAccessException e) {
116-
e.printStackTrace();
117-
}
86+
mixMC.setSession(new Session(name, "", "", "mojang"));
11887
}
11988

12089

0 commit comments

Comments
 (0)