Created
December 2, 2018 22:32
-
-
Save killjoy1221/c109342668d44111166c7cb289ef9c15 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyObfHelper<Owner, Type> extends ObfHelper<Owner, Type> { | |
public static final ObfHelper<Entity, Double> LAST_PORTAL_POS = new ObfHelper<>(Entity.class, "field_181016_an"); | |
public static final ObfHelper<Entity, Double> LAST_PORTAL_VEC = new ObfHelper<>(Entity.class, "field_181017_ao"); | |
public static final ObfHelper<Entity, Double> TELEPORT_DIRECTION = new ObfHelper<>(Entity.class, "field_181018_ap"); | |
protected ObfHelper(Class<Owner> owner, String srgname) { | |
super(owner, srgname); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class ObfHelper<Owner, Type> { | |
private Class<Owner> owner; | |
private String name; | |
private Field field; | |
private Method method; | |
protected ObfHelper(Class<Owner> owner, String srgname) { | |
this.owner = owner; | |
this.name = remap(owner, srgname); | |
} | |
public Class<Owner> getOwner() { | |
return owner; | |
} | |
public String getName() { | |
return name; | |
} | |
public Field getField() { | |
if (field == null) { | |
field = owner.getField(name); | |
field.setAccessible(true); | |
} | |
return field; | |
} | |
public Method getMethod(Class<?>... args) { | |
if (method == null) { | |
method = owner.getMethod(name, args); | |
method.setAccessible(true); | |
} | |
return method; | |
} | |
public Type getFieldValue(Owner instance) { | |
return (Type) getField().getValue(instance); | |
} | |
public void setFieldValue(Owner instance, Type value) { | |
getField().setValue(instance, value); | |
} | |
public Type invoke(Owner instance, Object... args) { | |
return getMethod().invoke(instance, args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment