Skip to content

Instantly share code, notes, and snippets.

@killjoy1221
Created December 2, 2018 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save killjoy1221/c109342668d44111166c7cb289ef9c15 to your computer and use it in GitHub Desktop.
Save killjoy1221/c109342668d44111166c7cb289ef9c15 to your computer and use it in GitHub Desktop.
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);
}
}
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