Make use of new @Pattern feature to centralize version-aware code
That is, most of the business code should not be aware that it is being compiled to multiple versions even when it heavily interacts with MC, preprocessor statements should be an escape hatch, not the norm. Similarly, code should not be forced to do `MCVer.getWindow(mc)` instead of the much more intuitive `mc.getWindow()`, and a new preprocessor (technically remap) feature makes this possible by defining "search and replace"-like patterns (but smarter in that they are type-aware) in one or more central places (the "Patterns.java" files) which then are applied all over the code base. In a way, this is another step in the automatic back-porting process where preprocessor statements are used when we cannot yet do something automatically. Previously we "merely" automatically converted between different mapping, this new feature now also allows us to automatically perform simple refactoring tasks like changing field access to a getter+setter (e.g. `mc.getWindow()`), or changing how a method is called (e.g. `BufferBuilder.begin`), or changing a method call chain (e.g. `dispatcher.camera.getYaw()`), or most other search-and-replace-like changes and any combination of those. The only major limitation is that the replacement itself is not smart, so arguments must be kept in same order (or be temporarily assigned to local variables which then can be used in any order).
This commit is contained in:
@@ -31,6 +31,7 @@ import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.DownloadingTerrainScreen;
|
||||
import net.minecraft.client.network.ClientLoginNetworkHandler;
|
||||
import net.minecraft.client.util.Window;
|
||||
import net.minecraft.util.crash.CrashReport;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
@@ -50,12 +51,10 @@ import org.lwjgl.opengl.GL11;
|
||||
|
||||
//#if MC>=11400
|
||||
import com.replaymod.replay.mixin.EntityLivingBaseAccessor;
|
||||
import net.minecraft.client.util.Window;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
//#else
|
||||
//$$ import com.replaymod.replay.mixin.EntityOtherPlayerMPAccessor;
|
||||
//$$ import net.minecraft.client.entity.EntityOtherPlayerMP;
|
||||
//$$ import net.minecraft.client.gui.ScaledResolution;
|
||||
//$$ import org.lwjgl.opengl.Display;
|
||||
//#endif
|
||||
|
||||
@@ -148,7 +147,7 @@ public class ReplayHandler {
|
||||
private UUID spectating;
|
||||
|
||||
public ReplayHandler(ReplayFile replayFile, boolean asyncMode) throws IOException {
|
||||
Preconditions.checkState(isOnMainThread(), "Must be called from Minecraft thread.");
|
||||
Preconditions.checkState(mc.isOnThread(), "Must be called from Minecraft thread.");
|
||||
this.replayFile = replayFile;
|
||||
|
||||
replayDuration = replayFile.getMetaData().getDuration();
|
||||
@@ -171,7 +170,7 @@ public class ReplayHandler {
|
||||
}
|
||||
|
||||
void restartedReplay() {
|
||||
Preconditions.checkState(isOnMainThread(), "Must be called from Minecraft thread.");
|
||||
Preconditions.checkState(mc.isOnThread(), "Must be called from Minecraft thread.");
|
||||
|
||||
channel.close();
|
||||
|
||||
@@ -197,7 +196,7 @@ public class ReplayHandler {
|
||||
}
|
||||
|
||||
public void endReplay() throws IOException {
|
||||
Preconditions.checkState(isOnMainThread(), "Must be called from Minecraft thread.");
|
||||
Preconditions.checkState(mc.isOnThread(), "Must be called from Minecraft thread.");
|
||||
|
||||
ReplayClosingCallback.EVENT.invoker().replayClosing(this);
|
||||
|
||||
@@ -246,7 +245,7 @@ public class ReplayHandler {
|
||||
}
|
||||
|
||||
private void setup() {
|
||||
Preconditions.checkState(isOnMainThread(), "Must be called from Minecraft thread.");
|
||||
Preconditions.checkState(mc.isOnThread(), "Must be called from Minecraft thread.");
|
||||
|
||||
//#if MC>=11100
|
||||
mc.inGameHud.getChatHud().clear(false);
|
||||
@@ -403,7 +402,7 @@ public class ReplayHandler {
|
||||
|
||||
CameraEntity cam = getCameraEntity();
|
||||
if (cam != null) {
|
||||
targetCameraPosition = new Location(Entity_getX(cam), Entity_getY(cam), Entity_getZ(cam), cam.yaw, cam.pitch);
|
||||
targetCameraPosition = new Location(cam.getX(), cam.getY(), cam.getZ(), cam.yaw, cam.pitch);
|
||||
} else {
|
||||
targetCameraPosition = null;
|
||||
}
|
||||
@@ -486,8 +485,8 @@ public class ReplayHandler {
|
||||
cameraEntity.setCameraController(new SpectatorCameraController(cameraEntity));
|
||||
}
|
||||
|
||||
if (getRenderViewEntity(mc) != e) {
|
||||
setRenderViewEntity(mc, e);
|
||||
if (mc.getCameraEntity() != e) {
|
||||
mc.setCameraEntity(e);
|
||||
cameraEntity.setCameraPosRot(e);
|
||||
}
|
||||
}
|
||||
@@ -505,7 +504,7 @@ public class ReplayHandler {
|
||||
* @return {@code true} if the camera is the view entity, {@code false} otherwise
|
||||
*/
|
||||
public boolean isCameraView() {
|
||||
return mc.player instanceof CameraEntity && mc.player == getRenderViewEntity(mc);
|
||||
return mc.player instanceof CameraEntity && mc.player == mc.getCameraEntity();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -539,11 +538,11 @@ public class ReplayHandler {
|
||||
}
|
||||
|
||||
// Update all entity positions (especially prev/lastTick values)
|
||||
for (Entity entity : loadedEntityList(mc.world)) {
|
||||
for (Entity entity : mc.world.getEntities()) {
|
||||
skipTeleportInterpolation(entity);
|
||||
entity.lastRenderX = entity.prevX = Entity_getX(entity);
|
||||
entity.lastRenderY = entity.prevY = Entity_getY(entity);
|
||||
entity.lastRenderZ = entity.prevZ = Entity_getZ(entity);
|
||||
entity.lastRenderX = entity.prevX = entity.getX();
|
||||
entity.lastRenderY = entity.prevY = entity.getY();
|
||||
entity.lastRenderZ = entity.prevZ = entity.getZ();
|
||||
entity.prevYaw = entity.yaw;
|
||||
entity.prevPitch = entity.pitch;
|
||||
}
|
||||
@@ -563,7 +562,7 @@ public class ReplayHandler {
|
||||
quickReplaySender.sendPacketsTill(targetTime);
|
||||
|
||||
// Immediately apply player teleport interpolation
|
||||
for (Entity entity : loadedEntityList(mc.world)) {
|
||||
for (Entity entity : mc.world.getEntities()) {
|
||||
skipTeleportInterpolation(entity);
|
||||
}
|
||||
return;
|
||||
@@ -582,7 +581,7 @@ public class ReplayHandler {
|
||||
if (retainCameraPosition) {
|
||||
CameraEntity cam = getCameraEntity();
|
||||
if (cam != null) {
|
||||
targetCameraPosition = new Location(Entity_getX(cam), Entity_getY(cam), Entity_getZ(cam),
|
||||
targetCameraPosition = new Location(cam.getX(), cam.getY(), cam.getZ(),
|
||||
cam.yaw, cam.pitch);
|
||||
} else {
|
||||
targetCameraPosition = null;
|
||||
@@ -612,8 +611,8 @@ public class ReplayHandler {
|
||||
);
|
||||
enableTexture();
|
||||
mc.getFramebuffer().beginWrite(true);
|
||||
Window window = mc.getWindow();
|
||||
//#if MC>=11500
|
||||
Window window = getWindow(mc);
|
||||
RenderSystem.clear(256, MinecraftClient.IS_SYSTEM_MAC);
|
||||
RenderSystem.matrixMode(GL11.GL_PROJECTION);
|
||||
RenderSystem.loadIdentity();
|
||||
@@ -623,23 +622,13 @@ public class ReplayHandler {
|
||||
RenderSystem.translatef(0, 0, -2000);
|
||||
//#else
|
||||
//#if MC>=11400
|
||||
//$$ getWindow(mc).method_4493(true);
|
||||
//#else
|
||||
//#if MC>=11400
|
||||
//$$ mc.mainWindow.setupOverlayRendering();
|
||||
//$$ window.method_4493(true);
|
||||
//#else
|
||||
//$$ mc.entityRenderer.setupOverlayRendering();
|
||||
//#endif
|
||||
//#endif
|
||||
//#endif
|
||||
|
||||
//#if MC>=11400
|
||||
Window
|
||||
//#else
|
||||
//$$ ScaledResolution
|
||||
//#endif
|
||||
resolution = newScaledResolution(mc);
|
||||
guiScreen.toMinecraft().init(mc, resolution.getScaledWidth(), resolution.getScaledHeight());
|
||||
guiScreen.toMinecraft().init(mc, window.getScaledWidth(), window.getScaledHeight());
|
||||
//#if MC>=11600
|
||||
guiScreen.toMinecraft().render(new MatrixStack(), 0, 0, 0);
|
||||
//#else
|
||||
@@ -654,18 +643,14 @@ public class ReplayHandler {
|
||||
mc.getFramebuffer().endWrite();
|
||||
popMatrix();
|
||||
pushMatrix();
|
||||
//#if MC>=11400
|
||||
mc.getFramebuffer().draw(getWindow(mc).getFramebufferWidth(), getWindow(mc).getFramebufferHeight());
|
||||
//#else
|
||||
//$$ mc.getFramebuffer().framebufferRender(mc.displayWidth, mc.displayHeight);
|
||||
//#endif
|
||||
mc.getFramebuffer().draw(mc.getWindow().getFramebufferWidth(), mc.getWindow().getFramebufferHeight());
|
||||
popMatrix();
|
||||
|
||||
//#if MC>=11500
|
||||
getWindow(mc).swapBuffers();
|
||||
mc.getWindow().swapBuffers();
|
||||
//#else
|
||||
//#if MC>=11400
|
||||
//$$ getWindow(mc).setFullscreen(true);
|
||||
//$$ mc.window.setFullscreen(true);
|
||||
//#else
|
||||
//$$ Display.update();
|
||||
//#endif
|
||||
@@ -691,11 +676,11 @@ public class ReplayHandler {
|
||||
//#else
|
||||
//$$ .processReceivedPackets();
|
||||
//#endif
|
||||
for (Entity entity : loadedEntityList(mc.world)) {
|
||||
for (Entity entity : mc.world.getEntities()) {
|
||||
skipTeleportInterpolation(entity);
|
||||
entity.lastRenderX = entity.prevX = Entity_getX(entity);
|
||||
entity.lastRenderY = entity.prevY = Entity_getY(entity);
|
||||
entity.lastRenderZ = entity.prevZ = Entity_getZ(entity);
|
||||
entity.lastRenderX = entity.prevX = entity.getX();
|
||||
entity.lastRenderY = entity.prevY = entity.getY();
|
||||
entity.lastRenderZ = entity.prevZ = entity.getZ();
|
||||
entity.prevYaw = entity.yaw;
|
||||
entity.prevPitch = entity.pitch;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user