67 lines
2.6 KiB
Java
67 lines
2.6 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*
|
|
* Could not load the following classes:
|
|
* net.minecraft.network.PacketBuffer
|
|
* net.minecraftforge.fml.network.NetworkEvent$Context
|
|
*/
|
|
package com.example.soundmod.net.packet;
|
|
|
|
import com.example.soundmod.common.SoundManifestEntry;
|
|
import com.example.soundmod.core.SoundDebug;
|
|
import com.example.soundmod.net.NetworkHandler;
|
|
import com.example.soundmod.net.packet.C2SCacheReportPacket;
|
|
import com.example.soundmod.sounddata.client.ClientSoundCache;
|
|
import java.util.ArrayList;
|
|
import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.function.Supplier;
|
|
import net.minecraft.network.PacketBuffer;
|
|
import net.minecraftforge.fml.network.NetworkEvent;
|
|
|
|
public class S2CSoundManifestPacket {
|
|
private final int version;
|
|
private final List<SoundManifestEntry> entries;
|
|
|
|
public S2CSoundManifestPacket(int version, List<SoundManifestEntry> entries) {
|
|
this.version = version;
|
|
this.entries = entries;
|
|
}
|
|
|
|
public static void encode(S2CSoundManifestPacket msg, PacketBuffer buf) {
|
|
buf.writeVarInt(msg.version);
|
|
buf.writeVarInt(msg.entries.size());
|
|
for (SoundManifestEntry entry : msg.entries) {
|
|
SoundManifestEntry.write(buf, entry);
|
|
}
|
|
}
|
|
|
|
public static S2CSoundManifestPacket decode(PacketBuffer buf) {
|
|
int version = buf.readVarInt();
|
|
int size = buf.readVarInt();
|
|
ArrayList<SoundManifestEntry> list = new ArrayList<SoundManifestEntry>();
|
|
for (int i = 0; i < size; ++i) {
|
|
list.add(SoundManifestEntry.read(buf));
|
|
}
|
|
return new S2CSoundManifestPacket(version, list);
|
|
}
|
|
|
|
public static void handle(S2CSoundManifestPacket msg, Supplier<NetworkEvent.Context> ctx) {
|
|
ctx.get().enqueueWork(() -> {
|
|
ClientSoundCache cache = ClientSoundCache.get();
|
|
cache.applyManifest(msg.entries);
|
|
SoundDebug.log(SoundDebug.Level.L1, "MANIFEST", "CLIENT", "received version={} entries={}", msg.version, msg.entries.size());
|
|
HashSet<String> local = new HashSet<String>(cache.localHashes());
|
|
ArrayList<String> missing = new ArrayList<String>();
|
|
for (SoundManifestEntry entry : msg.entries) {
|
|
if (entry.flags != 0 || local.contains(entry.sha256)) continue;
|
|
missing.add(entry.soundId);
|
|
}
|
|
SoundDebug.log(SoundDebug.Level.L2, "MANIFEST", "CLIENT", "cache report localHashes={} missing={}", local.size(), missing.size());
|
|
NetworkHandler.CHANNEL.sendToServer((Object)new C2SCacheReportPacket(new ArrayList<String>(local), missing));
|
|
});
|
|
ctx.get().setPacketHandled(true);
|
|
}
|
|
}
|
|
|