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:
@@ -28,20 +28,20 @@ import static com.replaymod.core.utils.Utils.SSL_SOCKET_FACTORY;
|
||||
import static com.replaymod.extras.ReplayModExtras.LOGGER;
|
||||
|
||||
public class OpenEyeExtra implements Extra {
|
||||
private static final String DOWNLOAD_URL = "https://www.replaymod.com/dl/openeye/" + MCVer.getMinecraftVersion();
|
||||
|
||||
private URL url;
|
||||
private ReplayMod mod;
|
||||
|
||||
@Override
|
||||
public void register(ReplayMod mod) throws Exception {
|
||||
this.mod = mod;
|
||||
this.url = new URL("https://www.replaymod.com/dl/openeye/" + mod.getMinecraftVersion());
|
||||
|
||||
boolean isOpenEyeLoaded = MCVer.isModLoaded("OpenEye");
|
||||
boolean isOpenEyeLoaded = mod.isModLoaded("OpenEye");
|
||||
if (!isOpenEyeLoaded && mod.getSettingsRegistry().get(Setting.ASK_FOR_OPEN_EYE)) {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
LOGGER.trace("Checking for OpenEye availability");
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(DOWNLOAD_URL).openConnection();
|
||||
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
||||
connection.setSSLSocketFactory(SSL_SOCKET_FACTORY);
|
||||
connection.setRequestMethod("HEAD");
|
||||
connection.connect();
|
||||
@@ -86,10 +86,10 @@ public class OpenEyeExtra implements Extra {
|
||||
GuiPopup popup = new GuiPopup(OfferGui.this);
|
||||
new Thread(() -> {
|
||||
try {
|
||||
File targetFile = new File(mod.getMinecraft().runDirectory, "mods/" + MCVer.getMinecraftVersion() + "/OpenEye.jar");
|
||||
File targetFile = new File(mod.getMinecraft().runDirectory, "mods/" + mod.getMinecraftVersion() + "/OpenEye.jar");
|
||||
FileUtils.forceMkdir(targetFile.getParentFile());
|
||||
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(DOWNLOAD_URL).openConnection();
|
||||
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
||||
connection.setSSLSocketFactory(SSL_SOCKET_FACTORY);
|
||||
ReadableByteChannel in = Channels.newChannel(connection.getInputStream());
|
||||
FileChannel out = new FileOutputStream(targetFile).getChannel();
|
||||
|
||||
@@ -9,10 +9,9 @@ import com.replaymod.render.rendering.Pipelines;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.Dimension;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.util.Window;
|
||||
import net.minecraft.util.crash.CrashReport;
|
||||
|
||||
import static com.replaymod.core.versions.MCVer.getMainWindowSize;
|
||||
import static com.replaymod.core.versions.MCVer.getRenderPartialTicks;
|
||||
import static com.replaymod.core.versions.MCVer.resizeMainWindow;
|
||||
|
||||
public class ScreenshotRenderer implements RenderInfo {
|
||||
@@ -29,7 +28,9 @@ public class ScreenshotRenderer implements RenderInfo {
|
||||
|
||||
public boolean renderScreenshot() throws Throwable {
|
||||
try {
|
||||
Dimension sizeBefore = getMainWindowSize(mc);
|
||||
Window window = mc.getWindow();
|
||||
int widthBefore = window.getFramebufferWidth();
|
||||
int heightBefore = window.getFramebufferHeight();
|
||||
boolean hideGUIBefore = mc.options.hudHidden;
|
||||
mc.options.hudHidden = true;
|
||||
|
||||
@@ -46,7 +47,7 @@ public class ScreenshotRenderer implements RenderInfo {
|
||||
clrg.uninstall();
|
||||
|
||||
mc.options.hudHidden = hideGUIBefore;
|
||||
resizeMainWindow(mc, sizeBefore.getWidth(), sizeBefore.getHeight());
|
||||
resizeMainWindow(mc, widthBefore, heightBefore);
|
||||
return true;
|
||||
} catch (OutOfMemoryError e) {
|
||||
e.printStackTrace();
|
||||
@@ -75,7 +76,7 @@ public class ScreenshotRenderer implements RenderInfo {
|
||||
@Override
|
||||
public float updateForNextFrame() {
|
||||
framesDone++;
|
||||
return getRenderPartialTicks();
|
||||
return mc.getTickDelta();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -117,7 +117,7 @@ public class PlayerOverview extends EventRegistrations implements Extra {
|
||||
|
||||
{ on(PreRenderHandCallback.EVENT, this::shouldHideHand); }
|
||||
private boolean shouldHideHand() {
|
||||
Entity view = getRenderViewEntity(module.getCore().getMinecraft());
|
||||
Entity view = module.getCore().getMinecraft().getCameraEntity();
|
||||
return view != null && isHidden(view.getUuid());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user