Last active
February 17, 2020 17:01
-
-
Save TheGlitch76/256b45f336784ddcc5879a63ed9b0051 to your computer and use it in GitHub Desktop.
:tiny_potato:
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
@Mixin(StatusEffectInstance.class) | |
public abstract class MixinStatusEffectInstance implements UpdateDurationSuperShim { | |
@Unique | |
private static final Object BLANK = new Object(); | |
@Shadow | |
protected abstract int updateDuration(); | |
@Unique | |
private ThreadLocal<Object> updateDurationLocal = new ThreadLocal<>(); | |
@Inject(method = "updateDuration", at = @At("HEAD"), cancellable = true) | |
private void hookUpdateDuration(CallbackInfoReturnable<Integer> cir) { | |
// If this is *not* a super call | |
if(updateDurationLocal.get() == null) { | |
if(this instanceof OverridesUpdateDuration) { | |
// cancel + return whatever it spits out | |
cir.setReturnValue(((OverridesUpdateDuration) this).patchwork$override$updateDuration()); | |
} | |
} else { | |
updateDurationLocal.remove(); | |
// continue with execution | |
} | |
} | |
@Override | |
public int patchwork$superShim$updateDuration() { | |
updateDurationLocal.set(BLANK); | |
return updateDuration(); | |
} |
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 interface OverridesUpdateDuration { | |
public int patchwork$override$updateDuration(); | |
} |
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 PatchworkStatusEffectInstance extends StatusEffectInstance implements OverridesUpdateDuration { | |
public PatchworkStatusEffectInstance(StatusEffectInstance statusEffectInstance) { | |
super(statusEffectInstance); | |
} | |
@Override | |
public int patchwork$override$updateDuration() { | |
throw new RuntimeException("duration: " + ((UpdateDurationSuperShim) this).patchwork$superShim$updateDuration()); | |
} | |
@Override | |
public int compareTo(StatusEffectInstance statusEffectInstance) { | |
throw new AssertionError("unimplemented"); | |
} | |
} |
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 interface UpdateDurationSuperShim { | |
public int patchwork$superShim$updateDuration(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment