/* * 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 entries; public S2CSoundManifestPacket(int version, List 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 list = new ArrayList(); for (int i = 0; i < size; ++i) { list.add(SoundManifestEntry.read(buf)); } return new S2CSoundManifestPacket(version, list); } public static void handle(S2CSoundManifestPacket msg, Supplier 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 local = new HashSet(cache.localHashes()); ArrayList missing = new ArrayList(); 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(local), missing)); }); ctx.get().setPacketHandled(true); } }