-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
237 additions
and
107 deletions.
There are no files selected for viewing
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
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
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
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
7 changes: 7 additions & 0 deletions
7
src/main/java/github/io/lucunji/explayerenderer/config/OptionPatch.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package github.io.lucunji.explayerenderer.config; | ||
|
||
public interface OptionPatch<T> { | ||
T extraPlayerRenderer$getSavedValue(); | ||
boolean extraPlayerRenderer$savePendingValue(); | ||
void extraPlayerRenderer$restoreSavedValue(); | ||
} |
20 changes: 0 additions & 20 deletions
20
src/main/java/github/io/lucunji/explayerenderer/config/PoseOffsetMethod.java
This file was deleted.
Oops, something went wrong.
70 changes: 0 additions & 70 deletions
70
src/main/java/github/io/lucunji/explayerenderer/mixin/yacl/YACLScreenMixin.java
This file was deleted.
Oops, something went wrong.
87 changes: 87 additions & 0 deletions
87
src/main/java/github/io/lucunji/explayerenderer/mixin/yacl/patch/OptionImplMixin.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package github.io.lucunji.explayerenderer.mixin.yacl.patch; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import dev.isxander.yacl3.api.*; | ||
import dev.isxander.yacl3.impl.OptionImpl; | ||
import github.io.lucunji.explayerenderer.config.Configs; | ||
import github.io.lucunji.explayerenderer.config.OptionPatch; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.text.Text; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import java.util.Collection; | ||
import java.util.Objects; | ||
import java.util.function.BiConsumer; | ||
import java.util.function.Function; | ||
|
||
@SuppressWarnings("UnstableApiUsage") | ||
@Mixin(value = OptionImpl.class, priority = Integer.MIN_VALUE) | ||
public abstract class OptionImplMixin<T> implements Option<T>, OptionPatch<T> { | ||
@Shadow | ||
@Final | ||
private Binding<T> binding; | ||
@Shadow private T pendingValue; | ||
@Shadow public abstract boolean applyValue(); | ||
|
||
@Shadow public abstract void requestSet(@NotNull T value); | ||
|
||
/** | ||
* We should rename it to isDirty | ||
*/ | ||
@Shadow public abstract boolean changed(); | ||
|
||
@Shadow public abstract boolean isPendingValueDefault(); | ||
|
||
@Unique private T savedValue; | ||
|
||
@Inject(method = "<init>", at = @At("RETURN"), remap = false) | ||
public void onInit( | ||
@NotNull Text name, | ||
@NotNull Function<T, OptionDescription> descriptionFunction, | ||
@NotNull Function<Option<T>, Controller<T>> controlGetter, | ||
@NotNull Binding<T> binding, | ||
boolean available, | ||
ImmutableSet<OptionFlag> flags, | ||
@NotNull Collection<BiConsumer<Option<T>, T>> listeners, | ||
CallbackInfo ci) { | ||
this.savedValue = binding.getValue(); | ||
} | ||
|
||
@Inject(method = "changed", at = @At("HEAD"), cancellable = true, remap = false) | ||
public void onChanged(CallbackInfoReturnable<Boolean> cir) { | ||
if (!Configs.isConfigScreen(MinecraftClient.getInstance().currentScreen)) return; | ||
// the second case is needed to allow applyValue to work when running Undo/Cancel | ||
cir.setReturnValue(!Objects.equals(pendingValue, savedValue) || !Objects.equals(pendingValue, binding.getValue())); | ||
} | ||
|
||
|
||
@Unique | ||
@Override | ||
public T extraPlayerRenderer$getSavedValue() { | ||
return savedValue; | ||
} | ||
|
||
@Unique | ||
@Override | ||
public boolean extraPlayerRenderer$savePendingValue() { | ||
if (changed()) { | ||
binding().setValue(savedValue = pendingValue); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
@Unique | ||
@Override | ||
public void extraPlayerRenderer$restoreSavedValue() { | ||
requestSet(savedValue); | ||
} | ||
} |
Oops, something went wrong.