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:
@@ -13,7 +13,6 @@ import net.minecraft.client.util.math.MatrixStack;
|
||||
|
||||
import static com.replaymod.core.ReplayMod.TEXTURE;
|
||||
import static com.replaymod.core.ReplayMod.TEXTURE_SIZE;
|
||||
import static com.replaymod.core.versions.MCVer.*;
|
||||
import static com.mojang.blaze3d.platform.GlStateManager.*;
|
||||
|
||||
/**
|
||||
@@ -44,7 +43,7 @@ public class GuiRecordingOverlay extends EventRegistrations {
|
||||
stack,
|
||||
//#endif
|
||||
text.toUpperCase(), 30, 18 - (fontRenderer.fontHeight / 2), 0xffffffff);
|
||||
bindTexture(TEXTURE);
|
||||
mc.getTextureManager().bindTexture(TEXTURE);
|
||||
enableAlphaTest();
|
||||
GuiRenderer renderer = new MinecraftGuiRenderer(stack);
|
||||
renderer.drawTexturedRect(10, 10, 58, 20, 16, 16, 16, 16, TEXTURE_SIZE, TEXTURE_SIZE);
|
||||
|
||||
@@ -138,7 +138,7 @@ public class ConnectionEventHandler {
|
||||
metaData.setCustomServerName(serverName);
|
||||
metaData.setGenerator("ReplayMod v" + ReplayMod.instance.getVersion());
|
||||
metaData.setDate(System.currentTimeMillis());
|
||||
metaData.setMcVersion(MCVer.getMinecraftVersion());
|
||||
metaData.setMcVersion(ReplayMod.instance.getMinecraftVersion());
|
||||
packetListener = new PacketListener(core, outputPath, replayFile, metaData);
|
||||
Channel channel = ((NetworkManagerAccessor) networkManager).getChannel();
|
||||
channel.pipeline().addBefore(packetHandlerKey, "replay_recorder", packetListener);
|
||||
|
||||
@@ -7,6 +7,7 @@ import de.johni0702.minecraft.gui.utils.EventRegistrations;
|
||||
import de.johni0702.minecraft.gui.versions.callbacks.PreTickCallback;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.network.packet.s2c.play.BlockBreakingProgressS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.EntityAnimationS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.EntityAttachS2CPacket;
|
||||
@@ -146,9 +147,9 @@ public class RecordingEventHandler extends EventRegistrations {
|
||||
boolean force = false;
|
||||
if(lastX == null || lastY == null || lastZ == null) {
|
||||
force = true;
|
||||
lastX = Entity_getX(player);
|
||||
lastY = Entity_getY(player);
|
||||
lastZ = Entity_getZ(player);
|
||||
lastX = player.getX();
|
||||
lastY = player.getY();
|
||||
lastZ = player.getZ();
|
||||
}
|
||||
|
||||
ticksSinceLastCorrection++;
|
||||
@@ -157,13 +158,13 @@ public class RecordingEventHandler extends EventRegistrations {
|
||||
force = true;
|
||||
}
|
||||
|
||||
double dx = Entity_getX(player) - lastX;
|
||||
double dy = Entity_getY(player) - lastY;
|
||||
double dz = Entity_getZ(player) - lastZ;
|
||||
double dx = player.getX() - lastX;
|
||||
double dy = player.getY() - lastY;
|
||||
double dz = player.getZ() - lastZ;
|
||||
|
||||
lastX = Entity_getX(player);
|
||||
lastY = Entity_getY(player);
|
||||
lastZ = Entity_getZ(player);
|
||||
lastX = player.getX();
|
||||
lastY = player.getY();
|
||||
lastZ = player.getZ();
|
||||
|
||||
Packet packet;
|
||||
if (force || Math.abs(dx) > 8.0 || Math.abs(dy) > 8.0 || Math.abs(dz) > 8.0) {
|
||||
@@ -309,18 +310,16 @@ public class RecordingEventHandler extends EventRegistrations {
|
||||
|
||||
//Leaving Ride
|
||||
|
||||
if((!player.isRiding() && lastRiding != -1) ||
|
||||
(player.isRiding() && lastRiding != getRiddenEntity(player).getEntityId())) {
|
||||
if(!player.isRiding()) {
|
||||
lastRiding = -1;
|
||||
} else {
|
||||
lastRiding = getRiddenEntity(player).getEntityId();
|
||||
}
|
||||
Entity vehicle = player.getVehicle();
|
||||
int vehicleId = vehicle == null ? -1 : vehicle.getEntityId();
|
||||
if (lastRiding != vehicleId) {
|
||||
lastRiding = vehicleId;
|
||||
packetListener.save(new EntityAttachS2CPacket(
|
||||
//#if MC<10904
|
||||
//$$ 0,
|
||||
//#endif
|
||||
player, getRiddenEntity(player)
|
||||
player,
|
||||
vehicle
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public abstract class MixinNetHandlerPlayClient {
|
||||
//$$ @Inject(method = "handlePlayerListItem", at=@At("HEAD"))
|
||||
//#endif
|
||||
public void recordOwnJoin(PlayerListS2CPacket packet, CallbackInfo ci) {
|
||||
if (!MCVer.isOnMainThread()) return;
|
||||
if (!mcStatic.isOnThread()) return;
|
||||
if (mcStatic.player == null) return;
|
||||
|
||||
RecordingEventHandler handler = getRecordingEventHandler();
|
||||
|
||||
@@ -163,8 +163,8 @@ public class PacketListener extends ChannelInboundHandlerAdapter {
|
||||
// to happen on the main thread so we can guarantee correct ordering of inbound and inject packets.
|
||||
// Otherwise, injected packets may end up further down the packet stream than they were supposed to and other
|
||||
// inbound packets which may rely on the injected packet would behave incorrectly when played back.
|
||||
if (!MCVer.isOnMainThread()) {
|
||||
MCVer.scheduleOnMainThread(() -> save(packet));
|
||||
if (!mc.isOnThread()) {
|
||||
mc.send(() -> save(packet));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@@ -488,15 +488,15 @@ public class PacketListener extends ChannelInboundHandlerAdapter {
|
||||
}
|
||||
|
||||
public void addMarker(String name, int timestamp) {
|
||||
Entity view = getRenderViewEntity(mc);
|
||||
Entity view = mc.getCameraEntity();
|
||||
|
||||
Marker marker = new Marker();
|
||||
marker.setName(name);
|
||||
marker.setTime(timestamp);
|
||||
if (view != null) {
|
||||
marker.setX(Entity_getX(view));
|
||||
marker.setY(Entity_getY(view));
|
||||
marker.setZ(Entity_getZ(view));
|
||||
marker.setX(view.getX());
|
||||
marker.setY(view.getY());
|
||||
marker.setZ(view.getZ());
|
||||
marker.setYaw(view.yaw);
|
||||
marker.setPitch(view.pitch);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user