Adding ModFile Request

This commit is contained in:
Frank 2021-08-18 10:02:44 +02:00
parent e9fc77ab0d
commit 8588191556
2 changed files with 15 additions and 5 deletions

View file

@ -3,6 +3,7 @@ package ru.bclib.api.dataexchange.handler.autosync;
import net.minecraft.network.FriendlyByteBuf;
import org.jetbrains.annotations.NotNull;
import ru.bclib.api.dataexchange.DataHandler;
import ru.bclib.api.datafixer.DataFixerAPI;
import java.io.File;
import java.util.Objects;
@ -42,18 +43,21 @@ public class AutoSyncID {
static class ForModFileRequest extends AutoSyncID {
public final static String UNIQUE_ID = "bclib::MOD";
ForModFileRequest(String modID) {
private final String version;
ForModFileRequest(String modID, String version) {
super(modID, ForModFileRequest.UNIQUE_ID);
this.version = version;
}
@Override
void serializeData(FriendlyByteBuf buf) {
super.serializeData(buf);
buf.writeInt(DataFixerAPI.getModVersion(version));
}
static ForModFileRequest finishDeserialize(String modID, String uniqueID, FriendlyByteBuf buf){
return new ForModFileRequest(modID);
final String version = DataFixerAPI.getModVersion(buf.readInt());
return new ForModFileRequest(modID, version);
}
}

View file

@ -263,8 +263,14 @@ public class HelloClient extends DataHandler.FromServer {
@Environment(EnvType.CLIENT)
private void processModFileSync(final List<AutoSyncID> filesToRequest) {
for (Entry<String, String> e : modVersion.entrySet()) {
String ver = PathUtil.getModVersion(e.getKey());
BCLib.LOGGER.info(" - " + e.getKey() + " (client=" + ver + ", server=" + ver + ")");
final String localVersion = PathUtil.getModVersion(e.getKey());
final String serverVersion = e.getValue();
final boolean requestMod = !serverVersion.equals(localVersion);
BCLib.LOGGER.info(" - " + e.getKey() + " (client=" + localVersion + ", server=" + serverVersion + (requestMod?", requesting":"") +")");
if (requestMod){
filesToRequest.add(new AutoSyncID.ForModFileRequest(e.getKey(), serverVersion));
}
}
}