package electroblob.wizardry.packet;
import electroblob.wizardry.spell.Spell;
import electroblob.wizardry.util.SpellProperties;
import io.netty.buffer.ByteBuf;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import java.util.ArrayList;
import java.util.List;
/** [Server -> Client] This packet is sent to sync server-side spell properties with clients on login. */
public class PacketSpellProperties implements IMessageHandler {
@Override
public IMessage onMessage(Message message, MessageContext ctx){
// Just to make sure that the side is correct
if(ctx.side.isClient()){
net.minecraft.client.Minecraft.getMinecraft().addScheduledTask(() -> {
for(int i=0; i propertiesList = new ArrayList<>();
int i = 0;
while(buf.isReadable()){
propertiesList.add(new SpellProperties(Spell.byNetworkID(i++), buf));
}
propertiesArray = propertiesList.toArray(new SpellProperties[0]);
}
@Override
public void toBytes(ByteBuf buf){
for(SpellProperties properties : propertiesArray) properties.write(buf);
}
}
}