Port to 1.20.3-rc1
This commit is contained in:
@@ -9,7 +9,9 @@ public class WrappedTimer extends RenderTickCounter {
|
||||
protected final RenderTickCounter wrapped;
|
||||
|
||||
public WrappedTimer(RenderTickCounter wrapped) {
|
||||
//#if MC>=11400
|
||||
//#if MC>=12003
|
||||
//$$ super(0, 0, f -> f);
|
||||
//#elseif MC>=11400
|
||||
super(0, 0);
|
||||
//#else
|
||||
//$$ super(0);
|
||||
|
||||
@@ -168,6 +168,7 @@ public class MCVer {
|
||||
//$$ }
|
||||
//#endif
|
||||
|
||||
//#if MC<12003
|
||||
public static
|
||||
//#if MC>=11400
|
||||
CompletableFuture<?>
|
||||
@@ -195,6 +196,7 @@ public class MCVer {
|
||||
//#endif
|
||||
//#endif
|
||||
}
|
||||
//#endif
|
||||
|
||||
public static <T> void addCallback(
|
||||
//#if MC>=11400
|
||||
|
||||
@@ -8,7 +8,9 @@ import net.minecraft.client.render.RenderTickCounter;
|
||||
* Wrapper around the current timer that prevents the timer from advancing by itself.
|
||||
*/
|
||||
public class ReplayTimer extends WrappedTimer {
|
||||
//#if MC>=11400
|
||||
//#if MC>=12003
|
||||
//$$ private final RenderTickCounter state = new RenderTickCounter(0, 0, f -> f);
|
||||
//#elseif MC>=11400
|
||||
private final RenderTickCounter state = new RenderTickCounter(0, 0);
|
||||
//#else
|
||||
//$$ private final Timer state = new Timer(0);
|
||||
|
||||
@@ -92,16 +92,24 @@ public class PacketListener extends ChannelInboundHandlerAdapter {
|
||||
private static final MinecraftClient mc = getMinecraft();
|
||||
private static final Logger logger = LogManager.getLogger();
|
||||
|
||||
private static final ResourcePackSendS2CPacket RESOURCE_PACK_SEND_PACKET =
|
||||
//#if MC>=12003
|
||||
//$$ new ResourcePackSendS2CPacket(null, "", "", false, null)
|
||||
//#elseif MC>=11700
|
||||
//$$ new ResourcePackSendS2CPacket("", "", false, null)
|
||||
//#else
|
||||
new ResourcePackSendS2CPacket()
|
||||
//#endif
|
||||
;
|
||||
private static final int PACKET_ID_RESOURCE_PACK_SEND = getPacketId(NetworkState.PLAY, RESOURCE_PACK_SEND_PACKET);
|
||||
//#if MC>=12002
|
||||
//$$ private static final int PACKET_ID_CONFIG_RESOURCE_PACK_SEND = getPacketId(NetworkState.CONFIGURATION, RESOURCE_PACK_SEND_PACKET);
|
||||
//#endif
|
||||
//#if MC>=11700
|
||||
//$$ private static final int PACKET_ID_RESOURCE_PACK_SEND = getPacketId(NetworkState.PLAY, new ResourcePackSendS2CPacket("", "", false, null));
|
||||
//$$ private static final int PACKET_ID_LOGIN_COMPRESSION = getPacketId(NetworkState.LOGIN, new LoginCompressionS2CPacket(0));
|
||||
//#else
|
||||
private static final int PACKET_ID_RESOURCE_PACK_SEND = getPacketId(NetworkState.PLAY, new ResourcePackSendS2CPacket());
|
||||
private static final int PACKET_ID_LOGIN_COMPRESSION = getPacketId(NetworkState.LOGIN, new LoginCompressionS2CPacket());
|
||||
//#endif
|
||||
//#if MC>=12002
|
||||
//$$ private static final int PACKET_ID_CONFIG_RESOURCE_PACK_SEND = getPacketId(NetworkState.CONFIGURATION, new ResourcePackSendS2CPacket("", "", false, null));
|
||||
//#endif
|
||||
//#if MC<10904
|
||||
//$$ private static final int PACKET_ID_PLAY_COMPRESSION = getPacketId(EnumConnectionState.PLAY, new S46PacketSetCompressionLevel());
|
||||
//#endif
|
||||
@@ -388,6 +396,9 @@ public class PacketListener extends ChannelInboundHandlerAdapter {
|
||||
) {
|
||||
ClientConnection connection = ctx.pipeline().get(ClientConnection.class);
|
||||
save(resourcePackRecorder.handleResourcePack(connection, (ResourcePackSendS2CPacket) decodeMcPacket(packet)));
|
||||
//#if MC>=12003
|
||||
//$$ super.channelRead(ctx, msg);
|
||||
//#endif
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -516,6 +527,10 @@ public class PacketListener extends ChannelInboundHandlerAdapter {
|
||||
this.serverWasPaused = true;
|
||||
}
|
||||
|
||||
public ResourcePackRecorder getResourcePackRecorder() {
|
||||
return resourcePackRecorder;
|
||||
}
|
||||
|
||||
private class DecodedPacketListener extends ChannelInboundHandlerAdapter {
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.replaymod.recording.packet;
|
||||
|
||||
import com.google.common.hash.Hashing;
|
||||
import com.google.common.io.Files;
|
||||
import com.replaymod.replaystudio.replay.ReplayFile;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.ConfirmScreen;
|
||||
@@ -11,6 +10,10 @@ import net.minecraft.client.resource.ClientBuiltinResourcePackProvider;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
//#if MC>=12003
|
||||
//$$ import java.util.UUID;
|
||||
//#endif
|
||||
|
||||
//#if MC>=11900
|
||||
//$$ import java.net.MalformedURLException;
|
||||
//$$ import java.net.URL;
|
||||
@@ -55,6 +58,8 @@ import net.minecraft.network.ClientConnection;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -75,10 +80,10 @@ public class ResourcePackRecorder {
|
||||
this.replayFile = replayFile;
|
||||
}
|
||||
|
||||
public void recordResourcePack(File file, int requestId) {
|
||||
public void recordResourcePack(Path file, int requestId) {
|
||||
try {
|
||||
// Read in resource pack file
|
||||
byte[] bytes = Files.toByteArray(file);
|
||||
byte[] bytes = Files.readAllBytes(file);
|
||||
// Check whether it is already known
|
||||
String hash = Hashing.sha1().hashBytes(bytes).toString();
|
||||
boolean doWrite = false; // Whether we are the first and have to write it
|
||||
@@ -105,7 +110,24 @@ public class ResourcePackRecorder {
|
||||
}
|
||||
}
|
||||
|
||||
//#if MC>=10800
|
||||
//#if MC>=12003
|
||||
//$$ private final Map<UUID, Integer> mcIdToReplayId = new HashMap<>();
|
||||
//$$
|
||||
//$$ public synchronized ResourcePackSendS2CPacket handleResourcePack(ClientConnection netManager, ResourcePackSendS2CPacket packet) {
|
||||
//$$ final int requestId = nextRequestId++;
|
||||
//$$ mcIdToReplayId.put(packet.id(), requestId);
|
||||
//$$ return new ResourcePackSendS2CPacket(packet.id(), "replay://" + requestId, "", packet.required(), packet.prompt());
|
||||
//$$ }
|
||||
//$$
|
||||
//$$ public void recordResourcePack(Path file, UUID uuid) {
|
||||
//$$ Integer id = mcIdToReplayId.get(uuid);
|
||||
//$$ if (id == null) {
|
||||
//$$ logger.warn("Got resource pack download for unexpected uuid " + uuid + " at " + file);
|
||||
//$$ return;
|
||||
//$$ }
|
||||
//$$ recordResourcePack(file, id);
|
||||
//$$ }
|
||||
//#elseif MC>=10800
|
||||
public ResourcePackStatusC2SPacket makeStatusPacket(String hash, Status action) {
|
||||
//#if MC>=11002
|
||||
return new ResourcePackStatusC2SPacket(action);
|
||||
@@ -128,7 +150,7 @@ public class ResourcePackRecorder {
|
||||
if (levelDir.isFile()) {
|
||||
netManager.send(makeStatusPacket(hash, Status.ACCEPTED));
|
||||
addCallback(setServerResourcePack(levelDir), result -> {
|
||||
recordResourcePack(levelDir, requestId);
|
||||
recordResourcePack(levelDir.toPath(), requestId);
|
||||
netManager.send(makeStatusPacket(hash, Status.SUCCESSFULLY_LOADED));
|
||||
}, throwable -> {
|
||||
netManager.send(makeStatusPacket(hash, Status.FAILED_DOWNLOAD));
|
||||
@@ -196,7 +218,7 @@ public class ResourcePackRecorder {
|
||||
//#endif
|
||||
downloadResourcePack(final int requestId, String url, String hash) {
|
||||
ClientBuiltinResourcePackProvider packFinder = mc.getResourcePackDownloader();
|
||||
((IDownloadingPackFinder) packFinder).setRequestCallback(file -> recordResourcePack(file, requestId));
|
||||
((IDownloadingPackFinder) packFinder).setRequestCallback(file -> recordResourcePack(file.toPath(), requestId));
|
||||
//#if MC>=11900
|
||||
//$$ try {
|
||||
//$$ URL theUrl = new URL(url);
|
||||
@@ -286,7 +308,7 @@ public class ResourcePackRecorder {
|
||||
//$$ acc.setActive(false);
|
||||
//$$ acc.setPack(new FileResourcePack(file));
|
||||
//$$ Minecraft.getMinecraft().scheduleResourcesRefresh();
|
||||
//$$ recordResourcePack(file, requestId);
|
||||
//$$ recordResourcePack(file.toPath(), requestId);
|
||||
//$$ }
|
||||
//$$ }
|
||||
//$$ }, hashmap, 50*1024*1024, guiScreen, Minecraft.getMinecraft().getProxy());
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.minecraft.util.thread.TaskExecutor;
|
||||
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;
|
||||
@@ -20,12 +21,28 @@ import java.util.concurrent.locks.Condition;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
//#if MC>=12003
|
||||
//$$ import net.minecraft.client.render.chunk.BlockBufferBuilderPool;
|
||||
//#endif
|
||||
|
||||
@Mixin(ChunkBuilder.class)
|
||||
public abstract class Mixin_BlockOnChunkRebuilds implements ForceChunkLoadingHook.IBlockOnChunkRebuilds {
|
||||
//#if MC>=12003
|
||||
//$$ @Shadow @Final private BlockBufferBuilderPool buffersPool;
|
||||
//$$ @Unique
|
||||
//$$ private int getAvailableBufferCount() {
|
||||
//$$ return this.buffersPool.getAvailableBuilderCount();
|
||||
//$$ }
|
||||
//#else
|
||||
@Shadow @Final private Queue<BlockBufferBuilderStorage> threadBuffers;
|
||||
@Unique
|
||||
private int getAvailableBufferCount() {
|
||||
return threadBuffers.size();
|
||||
}
|
||||
//#endif
|
||||
|
||||
//#if MC>=11800
|
||||
//$$ @org.spongepowered.asm.mixin.Unique
|
||||
//$$ @Unique
|
||||
//$$ private boolean upload() {
|
||||
//$$ boolean anything = false;
|
||||
//$$ Runnable runnable;
|
||||
@@ -52,12 +69,12 @@ public abstract class Mixin_BlockOnChunkRebuilds implements ForceChunkLoadingHoo
|
||||
|
||||
@Inject(method = "<init>", at = @At("RETURN"))
|
||||
private void rememberTotalThreads(CallbackInfo ci) {
|
||||
this.totalBufferCount = this.threadBuffers.size();
|
||||
this.totalBufferCount = getAvailableBufferCount();
|
||||
}
|
||||
|
||||
@Inject(method = "scheduleRunTasks", at = @At("RETURN"))
|
||||
private void notifyMainThreadIfEverythingIsDone(CallbackInfo ci) {
|
||||
if (this.threadBuffers.size() == this.totalBufferCount) {
|
||||
if (getAvailableBufferCount() == this.totalBufferCount) {
|
||||
// Looks like we're done, better notify the main thread in case the previous task didn't generate an upload
|
||||
this.waitingForWorkLock.lock();
|
||||
try {
|
||||
@@ -84,7 +101,7 @@ public abstract class Mixin_BlockOnChunkRebuilds implements ForceChunkLoadingHoo
|
||||
private boolean waitForMainThreadWork() {
|
||||
boolean allDone = this.mailbox.<Boolean>ask(reply -> () -> {
|
||||
scheduleRunTasks();
|
||||
reply.send(this.threadBuffers.size() == this.totalBufferCount);
|
||||
reply.send(getAvailableBufferCount() == this.totalBufferCount);
|
||||
}).join();
|
||||
|
||||
if (allDone) {
|
||||
|
||||
@@ -655,7 +655,11 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend
|
||||
|
||||
if(p instanceof ResourcePackSendS2CPacket) {
|
||||
ResourcePackSendS2CPacket packet = (ResourcePackSendS2CPacket) p;
|
||||
//#if MC>=12003
|
||||
//$$ String url = packet.url();
|
||||
//#else
|
||||
String url = packet.getURL();
|
||||
//#endif
|
||||
if (url.startsWith("replay://")) {
|
||||
//#else
|
||||
//$$ String url;
|
||||
@@ -671,7 +675,11 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend
|
||||
if (!file.exists()) {
|
||||
IOUtils.copy(replayFile.getResourcePack(hash).get(), new FileOutputStream(file));
|
||||
}
|
||||
//#if MC>=12003
|
||||
//$$ mc.getServerResourcePackProvider().addResourcePack(packet.id(), file.toPath());
|
||||
//#else
|
||||
setServerResourcePack(file);
|
||||
//#endif
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -42,6 +42,10 @@ import net.minecraft.network.ClientConnection;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
//#if MC>=12003
|
||||
//$$ import net.minecraft.client.resource.server.ServerResourcePackManager;
|
||||
//#endif
|
||||
|
||||
//#if MC>=12002
|
||||
//$$ import io.netty.channel.ChannelDuplexHandler;
|
||||
//$$ import io.netty.channel.ChannelPromise;
|
||||
@@ -355,6 +359,10 @@ public class ReplayHandler {
|
||||
//#if MC>=11400
|
||||
((MinecraftAccessor) mc).setConnection(networkManager);
|
||||
//#endif
|
||||
|
||||
//#if MC>=12003
|
||||
//$$ mc.getServerResourcePackProvider().init(networkManager, ServerResourcePackManager.AcceptanceStatus.ALLOWED);
|
||||
//#endif
|
||||
}
|
||||
|
||||
public ReplayFile getReplayFile() {
|
||||
|
||||
Reference in New Issue
Block a user