forked from modmuss50/OptiFabric
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try recover more lambdas Optifine changes
Specifically aimed at the keyboard handling ones Fixes modmuss50#238 Fixes modmuss50#244
- Loading branch information
Showing
13 changed files
with
581 additions
and
51 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
47 changes: 47 additions & 0 deletions
47
src/main/java/me/modmuss50/optifabric/compat/architectury/mixin/GameRendererNewMixin.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,47 @@ | ||
package me.modmuss50.optifabric.compat.architectury.mixin; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.At.Shift; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; | ||
|
||
import net.minecraft.client.render.GameRenderer; | ||
import net.minecraft.client.util.Window; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.util.math.Matrix4f; | ||
|
||
import me.modmuss50.optifabric.compat.InterceptingMixin; | ||
import me.modmuss50.optifabric.compat.PlacatingSurrogate; | ||
import me.modmuss50.optifabric.compat.Shim; | ||
|
||
@Mixin(GameRenderer.class) | ||
@InterceptingMixin("dev/architectury/mixin/fabric/client/MixinGameRenderer") | ||
abstract class GameRendererNewMixin { | ||
@Shim | ||
private native void renderScreenPre(float tickDelta, long startTime, boolean tick, CallbackInfo call, int mouseX, int mouseY, MatrixStack matrices); | ||
|
||
@PlacatingSurrogate | ||
private void renderScreenPre(float tickDelta, long startTime, boolean tick, CallbackInfo call, int mouseX, int mouseY, Window window) { | ||
} | ||
|
||
@Inject(method = "render(FJZ)V", locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true, | ||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;render(Lnet/minecraft/client/util/math/MatrixStack;IIF)V", ordinal = 0)) | ||
private void renderScreenPre(float tickDelta, long startTime, boolean tick, CallbackInfo call, int mouseX, int mouseY, Window window, Matrix4f projection, MatrixStack matrices) { | ||
renderScreenPre(tickDelta, startTime, tick, call, mouseX, mouseY, matrices); | ||
} | ||
|
||
@Shim | ||
private native void renderScreenPost(float tickDelta, long startTime, boolean tick, CallbackInfo call, int mouseX, int mouseY, MatrixStack matrices); | ||
|
||
@PlacatingSurrogate | ||
private void renderScreenPost(float tickDelta, long startTime, boolean tick, CallbackInfo call, int mouseX, int mouseY, Window window) { | ||
} | ||
|
||
@Inject(method = "render(FJZ)V", locals = LocalCapture.CAPTURE_FAILHARD, | ||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;render(Lnet/minecraft/client/util/math/MatrixStack;IIF)V", shift = Shift.AFTER, ordinal = 0)) | ||
private void renderScreenPost(float tickDelta, long startTime, boolean tick, CallbackInfo call, int mouseX, int mouseY, Window window, Matrix4f projection, MatrixStack matrices) { | ||
renderScreenPost(tickDelta, startTime, tick, call, mouseX, mouseY, matrices); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...in/java/me/modmuss50/optifabric/compat/architectury/mixin/SpriteAtlasTextureNewMixin.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,37 @@ | ||
package me.modmuss50.optifabric.compat.architectury.mixin; | ||
|
||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; | ||
|
||
import net.minecraft.client.texture.SpriteAtlasTexture; | ||
import net.minecraft.client.texture.SpriteAtlasTexture.Data; | ||
import net.minecraft.resource.ResourceManager; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.profiler.Profiler; | ||
|
||
import me.modmuss50.optifabric.compat.InterceptingMixin; | ||
import me.modmuss50.optifabric.compat.PlacatingSurrogate; | ||
import me.modmuss50.optifabric.compat.Shim; | ||
|
||
@Mixin(SpriteAtlasTexture.class) | ||
@InterceptingMixin("dev/architectury/mixin/fabric/client/MixinTextureAtlas") | ||
abstract class SpriteAtlasTextureNewMixin { | ||
@PlacatingSurrogate | ||
private void preStitch(ResourceManager resourceManager, Stream<Identifier> idStream, Profiler profiler, int mipmapLevel, CallbackInfoReturnable<Data> call, int mipmapLevels) { | ||
} | ||
|
||
@Inject(method = "stitch", locals = LocalCapture.CAPTURE_FAILHARD, | ||
at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/util/profiler/Profiler;swap(Ljava/lang/String;)V", args = "ldc=extracting_frames")) | ||
private void preStitch(ResourceManager resourceManager, Stream<Identifier> idStream, Profiler profiler, int mipmapLevel, CallbackInfoReturnable<Data> call, int mipmapLevels, Set<Identifier> set) { | ||
preStitch(resourceManager, idStream, profiler, mipmapLevels, call, set); | ||
} | ||
|
||
@Shim | ||
private native void preStitch(ResourceManager resourceManager, Stream<Identifier> idStream, Profiler profiler, int mipmapLevel, CallbackInfoReturnable<Data> call, Set<Identifier> set); | ||
} |
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
83 changes: 83 additions & 0 deletions
83
src/main/java/me/modmuss50/optifabric/mod/RetainingMappingsProvider.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,83 @@ | ||
package me.modmuss50.optifabric.mod; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.BiConsumer; | ||
|
||
import org.apache.commons.lang3.tuple.Pair; | ||
import org.apache.commons.lang3.tuple.Triple; | ||
|
||
import net.fabricmc.tinyremapper.IMappingProvider; | ||
import net.fabricmc.tinyremapper.IMappingProvider.MappingAcceptor; | ||
|
||
public class RetainingMappingsProvider implements MappingAcceptor, IMappingProvider { | ||
private static class LocalMapping { | ||
final Member method; | ||
final int lvtIndex; | ||
final int start; | ||
final int asmIndex; | ||
final String name; | ||
|
||
public LocalMapping(Member method, int lvtIndex, int start, int asmIndex, String name) { | ||
this.method = method; | ||
this.lvtIndex = lvtIndex; | ||
this.start = start; | ||
this.asmIndex = asmIndex; | ||
this.name = name; | ||
} | ||
} | ||
private final List<Pair<String, String>> classes = new ArrayList<>(); | ||
private final List<Pair<Member, String>> methods = new ArrayList<>(); | ||
private final List<Triple<Member, Integer, String>> parameters = new ArrayList<>(); | ||
private final List<LocalMapping> locals = new ArrayList<>(); | ||
private final List<Pair<Member, String>> fields = new ArrayList<>(); | ||
|
||
@Override | ||
public void acceptClass(String srcName, String dstName) { | ||
classes.add(Pair.of(srcName, dstName)); | ||
} | ||
|
||
@Override | ||
public void acceptMethod(Member method, String name) { | ||
methods.add(Pair.of(method, name)); | ||
} | ||
|
||
@Override | ||
public void acceptMethodArg(Member method, int lvtIndex, String name) { | ||
parameters.add(Triple.of(method, lvtIndex, name)); | ||
} | ||
|
||
@Override | ||
public void acceptMethodVar(Member method, int lvtIndex, int start, int asmIndex, String name) { | ||
locals.add(new LocalMapping(method, lvtIndex, start, asmIndex, name)); | ||
} | ||
|
||
@Override | ||
public void acceptField(Member field, String name) { | ||
fields.add(Pair.of(field, name)); | ||
} | ||
|
||
@Override | ||
public void load(MappingAcceptor out) { | ||
take(classes, out::acceptClass); | ||
take(methods, out::acceptMethod); | ||
take(fields, out::acceptField); | ||
|
||
for (Triple<Member, Integer, String> triple : parameters) { | ||
out.acceptMethodArg(triple.getLeft(), triple.getMiddle(), triple.getRight()); | ||
} | ||
parameters.clear(); | ||
|
||
for (LocalMapping mapping : locals) { | ||
out.acceptMethodVar(mapping.method, mapping.lvtIndex, mapping.start, mapping.asmIndex, mapping.name); | ||
} | ||
locals.clear(); | ||
} | ||
|
||
private <T, U> void take(List<Pair<T, U>> things, BiConsumer<T, U> acceptor) { | ||
for (Pair<T, U> pair : things) { | ||
acceptor.accept(pair.getLeft(), pair.getRight()); | ||
} | ||
things.clear(); | ||
} | ||
} |
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
Oops, something went wrong.